From b795209aa53b4f3555334e57d256ed1a9921685f Mon Sep 17 00:00:00 2001 From: Winkler Date: Wed, 11 Mar 2026 20:44:34 +0100 Subject: [PATCH] Use simflags string for simulation options instead of setSimulationOptions With the recent OpenModelica update to v1.26.2, setSimulationOptions doesn't recognice timing parameters any more. Introduced fix: Replace calls to setSimulationOptions with a constructed simflags string that includes timing parameters (-startTime, -stopTime, -stepSize, -tolerance) and appends any existing flags. Applied to run_simulation_in_order and simulate_model_worker so model.simulate is invoked with simflags=sim_options (and resultfile where applicable). This centralizes simulation options into the simflags parameter and removes the previous setSimulationOptions usage. --- .../open_modelica_simulator.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/moo_sim_interface/simulation_environment_apis/open_modelica_simulator.py b/moo_sim_interface/simulation_environment_apis/open_modelica_simulator.py index e8e37ab..ae7c4e6 100644 --- a/moo_sim_interface/simulation_environment_apis/open_modelica_simulator.py +++ b/moo_sim_interface/simulation_environment_apis/open_modelica_simulator.py @@ -89,15 +89,18 @@ def run_simulation(return_results: bool = False, **args) -> Union[None, list]: def run_simulation_in_order(final_names, indices, initial_names, input_values, method, model, start_time, step_size, stop_time, tolerance, flags, result_transformation) -> list[list]: combined_results = [] + for i in indices: initial_values = [values[i] for values in input_values] # set the start values model.setParameters([f'{name}={value}' for name, value in zip(initial_names, initial_values)]) - model.setSimulationOptions( - [f'startTime={start_time}', f'stopTime={stop_time}', f'stepSize={step_size}', f'solver={method}', - f'tolerance={tolerance}']) - model.simulate(simflags=flags) # simflags='-noEventEmit' - # model.simulate(simflags='-lv=-assert,-stdout') # simflags='-noEventEmit' + + # Build simulation flags with timing parameters + sim_options = f'-startTime={start_time} -stopTime={stop_time} -stepSize={step_size} -tolerance={tolerance}' + if flags: + sim_options = f'{sim_options} {flags}' + + model.simulate(simflags=sim_options) results = model.getSolutions(final_names) combined_results.append([(i, result_transformation(results))]) @@ -143,15 +146,16 @@ def simulate_model_worker(indices, final_names, initial_names, input_values, met for index in indices: initial_values = dict(zip(initial_names, [values[index] for values in input_values])) model.setParameters([f'{name}={value}' for name, value in initial_values.items()]) - model.setSimulationOptions( - [f'startTime={start_time}', f'stopTime={stop_time}', f'stepSize={step_size}', f'solver={method}', - f'tolerance={tolerance}'] - ) + + # Build simulation flags with timing parameters + sim_options = f'-startTime={start_time} -stopTime={stop_time} -stepSize={step_size} -tolerance={tolerance}' + if flags: + sim_options = f'{sim_options} {flags}' result_file = construct_resultfile_name(model_name, index) # Simulate the model - model.simulate(resultfile=result_file, simflags=flags) + model.simulate(resultfile=result_file, simflags=sim_options) # Retrieve results result = model.getSolutions(final_names)