Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
25446a6
(A014) [ModelExecution] update code for execution of a compiled model
syntron Jan 18, 2026
6c794cb
[ModelicaSystem] define check_model_executable() - test if the model …
syntron Jan 20, 2026
59e6c9d
(B001) split ModelicaSystem
syntron Jan 24, 2026
6504341
(B002) split ModelicaSystemDoE
syntron Jan 24, 2026
ef8a3aa
(B003) update OMCSession:OMPathABC
syntron Jan 25, 2026
7626599
(B004) define OMCSession:OMSessionABC
syntron Jan 26, 2026
ae77187
(C001) Runner definition
syntron Jan 27, 2026
0067e1b
[OM(C)SessionABC] small fixes
syntron Feb 9, 2026
c8095c8
(D002) move OMCSessionZMQ
syntron Feb 9, 2026
7f52092
(D003) improve OMCPath
syntron Feb 9, 2026
7f2a02b
(D004) define OMSessionRunner
syntron Feb 9, 2026
8361414
(D005) update classes in OMCSession
syntron Feb 9, 2026
97c3e4b
(D006) small fixes in ModelicaSystem
syntron Feb 8, 2026
e3984e7
(D008) add v4.0.0 compatibility layer
syntron Feb 9, 2026
1fb3681
(D007) define unittest / workflow for v4.0.0
syntron Feb 8, 2026
a73e331
(E001) update tests (v4.x.x)
syntron Feb 8, 2026
5624b6c
(E002) prepare restructure
syntron Feb 13, 2026
4d93362
[ModelExecution*] move classes into model_execution.py
syntron Feb 13, 2026
b7e40af
[OMCSession] split file
syntron Feb 9, 2026
129d646
[ModelicaSystem] split file
syntron Feb 13, 2026
674bb36
(F001) cleanup after restructure
syntron Feb 14, 2026
27a49e5
G001-pylint
syntron Feb 15, 2026
c7b54c8
G002-bugfix
syntron Feb 15, 2026
6d738a4
G003-compatibility
syntron Feb 15, 2026
a9206d3
G004-remove_deprecated-ModelicaSystem_rewrite_set_functions2
syntron Feb 18, 2026
eedf250
G005-remove_depreciated_functionality2
syntron Feb 16, 2026
1b9af03
remove OMPathCompatibility - update needed Python version to 3.12
syntron Feb 15, 2026
a23279e
remove all compatibility code (v4.0.0)
syntron Feb 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
(E001) update tests (v4.x.x)
[test_*] reorder imports

[tests_ModelicaDoE*] fix pylint hint

* use .items()

[tests_*] use OMSessionABC.get_version()

[test_ModelicaSystemCmd] use get_model_name() instead of access to private variable _model_name

[test_ModelicaSystemOMC] read file using utf-8 encoding / linter fix

[test_ModelicaSystemRunner] update test case

* ModelicaSystemRunner & OMCPath
* ModelicaSystemRunner & OMPathRunnerLocal
* ModelicaSystemRunner & OMPathRunnerBash
* ModelicaSystemRunner & OMPathRunnerBash using docker
* ModelicaSystemRunner & OMPathRunnerBash using WSL (not tested!)

[test_OMCPath] update test case

* OMCPath & OMCSessionZMQ
* OMCPath & OMCSessionLocal
* OMCPath & OMCSessionDocker
* OMCPath & OMCSessionWSL (not tested!)
* OMPathLocal & OMCSessionRunner
* OMPathBash & OMCSessionRunner
* OMPathBash & OMCSessionRunner in docker
* OMPathBash & OMCSessionRunner in WSL (not tested!)

add workflow to run unittests in ./tests

[test_OMParser] use only the public interface => om_parser_basic()

[test_OMTypedParser] rename file / use om_parser_typed()

update tests - do NOT run test_FMIRegression.py

reason:
* it is only a test for OMC / not OMPython specific
* furthermore, it is run automatically via cron job (= FMITest)

[test_ModelExecutionCmd] rename from test_ModelicaSystemCmd
  • Loading branch information
syntron committed Mar 9, 2026
commit a73e331ae569bd6bc831d51029264b8095e13bee
2 changes: 2 additions & 0 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
OMPathABC,
OMCPath,

OMSessionABC,
OMSessionRunner,

OMCSessionABC,
Expand Down Expand Up @@ -77,6 +78,7 @@
'OMPathABC',
'OMCPath',

'OMSessionABC',
'OMSessionRunner',

'OMCSessionABC',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_FMIExport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import shutil
import os
import pathlib
import shutil

import OMPython

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def mscmd_firstorder(model_firstorder):
cmd_local=mod.get_session().model_execution_local,
cmd_windows=mod.get_session().model_execution_windows,
cmd_prefix=mod.get_session().model_execution_prefix(cwd=mod.getWorkDirectory()),
model_name=mod._model_name,
model_name=mod.get_model_name(),
)

return mscmd
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ModelicaDoEOMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ def _run_ModelicaDoEOMC(doe_mod):
f"y[{row['p']}]": float(row['b']),
}

for var in var_dict:
assert var in sol['data']
assert np.isclose(sol['data'][var][-1], var_dict[var])
for key, val in var_dict.items():
assert key in sol['data']
assert np.isclose(sol['data'][key][-1], val)
6 changes: 3 additions & 3 deletions tests/test_ModelicaDoERunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ def _check_runner_result(mod, doe_mod):
'b': float(row['b']),
}

for var in var_dict:
assert var in sol['data']
assert np.isclose(sol['data'][var][-1], var_dict[var])
for key, val in var_dict.items():
assert key in sol['data']
assert np.isclose(sol['data'][key][-1], val)
2 changes: 1 addition & 1 deletion tests/test_ModelicaSystemOMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def test_simulate_inputs(tmp_path):
}
mod.setInputs(**inputs)
csv_file = mod._createCSVData()
assert pathlib.Path(csv_file).read_text() == """time,u1,u2,end
assert pathlib.Path(csv_file).read_text(encoding='utf-8') == """time,u1,u2,end
0.0,0.0,0.0,0
0.25,0.25,0.5,0
0.5,0.5,1.0,0
Expand Down
176 changes: 175 additions & 1 deletion tests/test_ModelicaSystemRunner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import sys

import numpy as np
import pytest

import OMPython


skip_on_windows = pytest.mark.skipif(
sys.platform.startswith("win"),
reason="OpenModelica Docker image is Linux-only; skipping on Windows.",
)

skip_python_older_312 = pytest.mark.skipif(
sys.version_info < (3, 12),
reason="OMCPath(non-local) only working for Python >= 3.12.",
)


@pytest.fixture
def model_firstorder_content():
return """
Expand Down Expand Up @@ -37,7 +50,7 @@ def param():
}


def test_runner(model_firstorder, param):
def test_ModelicaSystemRunner_OMC(model_firstorder, param):
# create a model using ModelicaSystem
mod = OMPython.ModelicaSystemOMC()
mod.model(
Expand Down Expand Up @@ -71,6 +84,167 @@ def test_runner(model_firstorder, param):
_check_result(mod=mod, resultfile=resultfile_modr, param=param)


def test_ModelicaSystemRunner_local(model_firstorder, param):
# create a model using ModelicaSystem
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_firstorder,
model_name="M",
)

resultfile_mod = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_mod.mat"
_run_simulation(mod=mod, resultfile=resultfile_mod, param=param)

# run the model using only the runner class
omcs = OMPython.OMSessionRunner(
version=mod.get_session().get_version(),
ompath_runner=OMPython.OMPathRunnerLocal,
)
modr = OMPython.ModelicaSystemRunner(
session=omcs,
work_directory=mod.getWorkDirectory(),
)
modr.setup(
model_name="M",
)

resultfile_modr = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_modr.mat"
_run_simulation(mod=modr, resultfile=resultfile_modr, param=param)

# cannot check the content as runner does not have the capability to open a result file
assert resultfile_mod.size() == resultfile_modr.size()

# check results
_check_result(mod=mod, resultfile=resultfile_mod, param=param)
_check_result(mod=mod, resultfile=resultfile_modr, param=param)


@skip_on_windows
def test_ModelicaSystemRunner_bash(model_firstorder, param):
# create a model using ModelicaSystem
mod = OMPython.ModelicaSystemOMC()
mod.model(
model_file=model_firstorder,
model_name="M",
)

resultfile_mod = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_mod.mat"
_run_simulation(mod=mod, resultfile=resultfile_mod, param=param)

# run the model using only the runner class
omcsr = OMPython.OMSessionRunner(
version=mod.get_session().get_version(),
ompath_runner=OMPython.OMPathRunnerBash,
)
modr = OMPython.ModelicaSystemRunner(
session=omcsr,
work_directory=mod.getWorkDirectory(),
)
modr.setup(
model_name="M",
)

resultfile_modr = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_modr.mat"
_run_simulation(mod=modr, resultfile=resultfile_modr, param=param)

# cannot check the content as runner does not have the capability to open a result file
assert resultfile_mod.size() == resultfile_modr.size()

# check results
_check_result(mod=mod, resultfile=resultfile_mod, param=param)
_check_result(mod=mod, resultfile=resultfile_modr, param=param)


@skip_on_windows
@skip_python_older_312
def test_ModelicaSystemRunner_bash_docker(model_firstorder, param):
omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
omversion = omcs.sendExpression("getVersion()")
assert isinstance(omversion, str) and omversion.startswith("OpenModelica")

# create a model using ModelicaSystem
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
model_file=model_firstorder,
model_name="M",
)

resultfile_mod = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_mod.mat"
_run_simulation(mod=mod, resultfile=resultfile_mod, param=param)

# run the model using only the runner class
omcsr = OMPython.OMSessionRunner(
version=mod.get_session().get_version(),
cmd_prefix=omcs.model_execution_prefix(cwd=mod.getWorkDirectory()),
ompath_runner=OMPython.OMPathRunnerBash,
model_execution_local=False,
)
modr = OMPython.ModelicaSystemRunner(
session=omcsr,
work_directory=mod.getWorkDirectory(),
)
modr.setup(
model_name="M",
)

resultfile_modr = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_modr.mat"
_run_simulation(mod=modr, resultfile=resultfile_modr, param=param)

# cannot check the content as runner does not have the capability to open a result file
assert resultfile_mod.size() == resultfile_modr.size()

# check results
_check_result(mod=mod, resultfile=resultfile_mod, param=param)
_check_result(mod=mod, resultfile=resultfile_modr, param=param)


@pytest.mark.skip(reason="Not able to run WSL on github")
@skip_python_older_312
def test_ModelicaSystemDoE_WSL(tmp_path, model_doe, param_doe):
omcs = OMPython.OMCSessionWSL()
omversion = omcs.sendExpression("getVersion()")
assert isinstance(omversion, str) and omversion.startswith("OpenModelica")

# create a model using ModelicaSystem
mod = OMPython.ModelicaSystemOMC(
session=omcs,
)
mod.model(
model_file=model_firstorder,
model_name="M",
)

resultfile_mod = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_mod.mat"
_run_simulation(mod=mod, resultfile=resultfile_mod, param=param)

# run the model using only the runner class
omcsr = OMPython.OMSessionRunner(
version=mod.get_session().get_version(),
cmd_prefix=omcs.model_execution_prefix(cwd=mod.getWorkDirectory()),
ompath_runner=OMPython.OMPathRunnerBash,
model_execution_local=False,
)
modr = OMPython.ModelicaSystemRunner(
session=omcsr,
work_directory=mod.getWorkDirectory(),
)
modr.setup(
model_name="M",
)

resultfile_modr = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_modr.mat"
_run_simulation(mod=modr, resultfile=resultfile_modr, param=param)

# cannot check the content as runner does not have the capability to open a result file
assert resultfile_mod.size() == resultfile_modr.size()

# check results
_check_result(mod=mod, resultfile=resultfile_mod, param=param)
_check_result(mod=mod, resultfile=resultfile_modr, param=param)


def _run_simulation(mod, resultfile, param):
simOptions = {"stopTime": param['stopTime'], "stepSize": 0.1, "tolerance": 1e-8}
mod.setSimulationOptions(**simOptions)
Expand Down
Loading
Loading