From 47b6912414a24250b4ccaad0842e110d1abbf275 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Fri, 2 Oct 2026 16:08:34 +0200 Subject: [PATCH 1/6] Apply custom options alongside defaults options Added a flag to avoid adding default options --- OMPython/modelica_system_omc.py | 18 +++++++++++------- tests/test_ModelicaSystemOMC.py | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/OMPython/modelica_system_omc.py b/OMPython/modelica_system_omc.py index 8ee5c3b0..d7c4bf1a 100644 --- a/OMPython/modelica_system_omc.py +++ b/OMPython/modelica_system_omc.py @@ -39,13 +39,15 @@ def __init__( work_directory: Optional[str | os.PathLike] = None, omhome: Optional[str] = None, session: Optional[OMSessionABC] = None, + use_default_command_line_options: bool = True, ) -> None: """Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo(). Args: command_line_options: List with extra command line options as elements. The list elements are - provided to omc via setCommandLineOptions(). If set, the default values will be overridden. - To disable any command line options, use an empty list. + provided to omc via setCommandLineOptions() in addition to OMPython's default options. + use_default_command_line_options: Whether to set OMPython's default options for linearization. + Set to False to use only command_line_options, or no options if it is unspecified or empty. work_directory: Path to a directory to be used for temporary files like the model executable. If left unspecified, a tmp directory will be created. @@ -62,15 +64,17 @@ def __init__( work_directory=work_directory, ) - # set commandLineOptions using default values or the user defined list - if command_line_options is None: + options: list[str] = [] + if use_default_command_line_options: # set default command line options to improve the performance of linearization and to avoid recompilation if # the simulation executable is reused in linearize() via the runtime flag '-l' - command_line_options = [ + options.extend([ "--linearizationDumpLanguage=python", "--generateSymbolicLinearization", - ] - for opt in command_line_options: + ]) + if command_line_options is not None: + options.extend(command_line_options) + for opt in options: self.set_command_line_options(command_line_option=opt) def model( diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 171db6b9..4015af1f 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -38,6 +38,30 @@ def model_firstorder(tmp_path, model_firstorder_content): return mod +@pytest.mark.parametrize( + ("use_defaults", "custom_options", "expected_options"), + [ + (True, ["--showAnnotations"], [ + "--linearizationDumpLanguage=python", + "--generateSymbolicLinearization", + "--showAnnotations", + ]), + (False, ["--showAnnotations"], ["--showAnnotations"]), + (False, [], []), + ], +) +def test_command_line_options(use_defaults, custom_options, expected_options): + session = OMPython.OMCSessionLocal() + mod = OMPython.ModelicaSystemOMC( + session=session, + command_line_options=custom_options, + use_default_command_line_options=use_defaults, + ) + + current_options = mod.sendExpression("getCommandLineOptions()") + assert current_options == expected_options + + def test_ModelicaSystem_loop(model_firstorder): def worker(): mod = OMPython.ModelicaSystemOMC() From 048dd156f6f97caa8e69fa6296d1c0aa9b603bb3 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Fri, 2 Oct 2026 16:21:24 +0200 Subject: [PATCH 2/6] Remove test --- tests/test_ModelicaSystemOMC.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 4015af1f..171db6b9 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -38,30 +38,6 @@ def model_firstorder(tmp_path, model_firstorder_content): return mod -@pytest.mark.parametrize( - ("use_defaults", "custom_options", "expected_options"), - [ - (True, ["--showAnnotations"], [ - "--linearizationDumpLanguage=python", - "--generateSymbolicLinearization", - "--showAnnotations", - ]), - (False, ["--showAnnotations"], ["--showAnnotations"]), - (False, [], []), - ], -) -def test_command_line_options(use_defaults, custom_options, expected_options): - session = OMPython.OMCSessionLocal() - mod = OMPython.ModelicaSystemOMC( - session=session, - command_line_options=custom_options, - use_default_command_line_options=use_defaults, - ) - - current_options = mod.sendExpression("getCommandLineOptions()") - assert current_options == expected_options - - def test_ModelicaSystem_loop(model_firstorder): def worker(): mod = OMPython.ModelicaSystemOMC() From 7f85abd3334527e1b9c6448204d081b489acfd92 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Mon, 5 Oct 2026 11:16:50 +0200 Subject: [PATCH 3/6] Fix tests --- tests/test_FMIImport.py | 4 ++-- tests/test_ModelicaSystemOMC.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_FMIImport.py b/tests/test_FMIImport.py index bb3a1201..dab73e93 100644 --- a/tests/test_FMIImport.py +++ b/tests/test_FMIImport.py @@ -34,8 +34,8 @@ def test_FMIImport(model_firstorder): assert os.path.exists(fmu) # import FMU & check & simulate - # TODO: why is '--allowNonStandardModelica=reinitInAlgorithms' needed? any example without this possible? - mod2 = OMPython.ModelicaSystemOMC(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms']) + # --allowNonStandardModelica=reinitInAlgorithms' is needed since the generated code uses reinit inside algorithm section which is not standard Modelica. + mod2 = OMPython.ModelicaSystemOMC(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms'], use_default_command_line_options=False) mo = mod2.convertFmu2Mo(fmu=fmu) assert os.path.exists(mo) diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 171db6b9..5247dc61 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -38,6 +38,29 @@ def model_firstorder(tmp_path, model_firstorder_content): return mod +@pytest.mark.parametrize( + ("use_defaults", "custom_options", "expected_options"), + [ + (True, ["--showAnnotations"], [ + "--linearizationDumpLanguage=python", + "--generateSymbolicLinearization", + "--showAnnotations=true", + ]), + (False, ["--showAnnotations"], ["--showAnnotations"]), + ], +) +def test_command_line_options(use_defaults, custom_options, expected_options): + session = OMPython.OMCSessionLocal() + mod = OMPython.ModelicaSystemOMC( + session=session, + command_line_options=custom_options, + use_default_command_line_options=use_defaults, + ) + + current_options = mod.sendExpression("getCommandLineOptions()") + assert all(option in current_options for option in expected_options) + + def test_ModelicaSystem_loop(model_firstorder): def worker(): mod = OMPython.ModelicaSystemOMC() From 4e5581b1a7263b4beeebedd84b638c3d79a1a599 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Mon, 5 Oct 2026 11:21:50 +0200 Subject: [PATCH 4/6] Fix linter --- tests/test_FMIImport.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_FMIImport.py b/tests/test_FMIImport.py index dab73e93..fec9e60b 100644 --- a/tests/test_FMIImport.py +++ b/tests/test_FMIImport.py @@ -34,8 +34,10 @@ def test_FMIImport(model_firstorder): assert os.path.exists(fmu) # import FMU & check & simulate - # --allowNonStandardModelica=reinitInAlgorithms' is needed since the generated code uses reinit inside algorithm section which is not standard Modelica. - mod2 = OMPython.ModelicaSystemOMC(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms'], use_default_command_line_options=False) + # --allowNonStandardModelica=reinitInAlgorithms' is needed. + # Since the generated code uses reinit inside algorithm section which is not standard Modelica. + mod2 = OMPython.ModelicaSystemOMC(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms'], + use_default_command_line_options=False) mo = mod2.convertFmu2Mo(fmu=fmu) assert os.path.exists(mo) From c78b5014534c66cf886c6c611312de408dcfc9aa Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Mon, 5 Oct 2026 11:34:16 +0200 Subject: [PATCH 5/6] Fix test --- tests/test_ModelicaSystemOMC.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 5247dc61..92fa34f4 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -46,7 +46,7 @@ def model_firstorder(tmp_path, model_firstorder_content): "--generateSymbolicLinearization", "--showAnnotations=true", ]), - (False, ["--showAnnotations"], ["--showAnnotations"]), + (False, ["--showAnnotations"], ["--showAnnotations=true"]), ], ) def test_command_line_options(use_defaults, custom_options, expected_options): From 32977d6a7ae9de4699d6174d30bc762347b7569f Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Mon, 5 Oct 2026 11:51:35 +0200 Subject: [PATCH 6/6] Fix test again --- tests/test_ModelicaSystemOMC.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ModelicaSystemOMC.py b/tests/test_ModelicaSystemOMC.py index 92fa34f4..4a7f8cb6 100644 --- a/tests/test_ModelicaSystemOMC.py +++ b/tests/test_ModelicaSystemOMC.py @@ -43,7 +43,7 @@ def model_firstorder(tmp_path, model_firstorder_content): [ (True, ["--showAnnotations"], [ "--linearizationDumpLanguage=python", - "--generateSymbolicLinearization", + "--generateSymbolicLinearization=true", "--showAnnotations=true", ]), (False, ["--showAnnotations"], ["--showAnnotations=true"]),