Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
429fe87
[ModelicaSystem] move import re
syntron Dec 27, 2025
c1e597a
[ModelicaSystem] fix pylint message
syntron Dec 27, 2025
e588845
[ModelicaSystem] improve lintime checks
syntron Dec 27, 2025
d5ee232
[unittests] use new definitions / remove OMCSessionZMQ
syntron Nov 23, 2025
5cc2554
use keyword arguments if possible (FKA100 - flake8-force-keyword-argu…
syntron Nov 27, 2025
a32dac8
[OMCSession] improve log messages for model simulation using OM execu…
syntron Dec 15, 2025
7298ac9
[ModelicaSystem] improve handling of model simulation
syntron Dec 15, 2025
4f65db9
[ModelicaSystemDoE] fix exception handling
syntron Dec 16, 2025
9a3a3f0
add OMCPath to the public interface
syntron Nov 27, 2025
a46532d
[OMCSession] fix pylint: W0706: The except handler raises immediately…
syntron Dec 29, 2025
237e5cb
[ModelicaSystem] parse OM version in __init__()
syntron Dec 27, 2025
1f3ec87
[ModelicaSystem] simplify processing of override data
syntron Dec 27, 2025
cd3a9b9
[ModelicaSystem] define _linearization_options and _optimization_opti…
syntron Dec 27, 2025
843cb2c
[ModelicaSystem] simplify call to sendExpression()
syntron Dec 27, 2025
052f61e
[ModelicaSystem] check for dict content using len() == 0
syntron Dec 27, 2025
27d894b
[ModelicaSystem] fix overwrite file (write only if there is content)
syntron Dec 28, 2025
86af54f
[ModelicaSystem] add docstring for _process_override_data()
syntron Jan 5, 2026
319cf9d
update README.md - replace OMCSessionZMQ with OMCSessionLocal
syntron Nov 27, 2025
f08ea8b
[OMCSessionPort] add missing function / catch possible errors
syntron Nov 23, 2025
eae5e65
[OMCSessionPort] fix exception message
syntron Nov 26, 2025
1a3762b
reorder imports in __init__.py
syntron Nov 8, 2025
a2005ad
[OMCSession] improve logging
syntron Nov 23, 2025
12eef69
[OMCSession*] define set_timeout()
syntron Nov 26, 2025
fb568de
[OMCSession*] align all usages of timeout to the same structure
syntron Nov 25, 2025
702208d
[OMCSession*] simplify code for timeout loops
syntron Nov 26, 2025
cce234b
[OMCSession] fix definiton of _timeout variable - use set_timeout() c…
syntron Nov 27, 2025
ae4711a
[OMCSession*] some additional cleanup (mypy / flake8)
syntron Nov 27, 2025
252af40
[OMCSession] move call to set_timeout() to __post_init__
syntron Nov 27, 2025
7f32410
update test matrix
syntron Dec 28, 2025
4626128
[__init__] fix imports - include OMCSession
syntron Jan 24, 2026
78a1195
Merge branch 'update_override' into v4.1.0-status20260123
syntron Jan 24, 2026
10662da
Merge branch 'OMCSession_README' into v4.1.0-status20260123
syntron Jan 24, 2026
0288723
Merge branch 'OMCSessionPort' into v4.1.0-status20260123
syntron Jan 24, 2026
65425b8
Merge branch 'reorder_imports' into v4.1.0-status20260123
syntron Jan 24, 2026
064398b
Merge branch 'OMCSession_logging' into v4.1.0-status20260123
syntron Jan 24, 2026
a0b413e
Merge branch 'linter_fix' into v4.1.0-status20260123
syntron Jan 24, 2026
7f0ea59
Merge branch 'simulation' into v4.1.0-status20260123
syntron Jan 24, 2026
12f4455
Merge branch 'OMCPath_to_init' into v4.1.0-status20260123
syntron Jan 24, 2026
0e9ba15
Merge branch 'pylint_fix' into v4.1.0-status20260123
syntron Jan 24, 2026
c6e6f9d
Merge branch 'OMCSession_unittests' into v4.1.0-status20260123
syntron Jan 24, 2026
5d1c38d
[OMCSession] align definition of sendExpression() - use expr (was: co…
syntron Jan 24, 2026
4e81487
[OMCSession] fix log message
syntron Jan 24, 2026
a12c151
Merge branch 'ModelicaSystem_timeout' into v4.1.0-status20260123
syntron Jan 24, 2026
8dbf8a2
Merge branch 'OMCSession_sendExpression_rename_arg' into v4.1.0-statu…
syntron Jan 24, 2026
af2833e
Merge branch 'test_matrix' into v4.1.0-status20260123
syntron Jan 24, 2026
64e4265
[OMCSessionZMQ] remove depreciated function execute()
syntron Jun 17, 2025
aa1692c
[ModelicaSystemCmd] remove depreciated simflags
syntron Jun 17, 2025
d491caa
[test_ModelicaSystemCmd] update test_simflags
syntron Oct 31, 2025
cec873c
fix test_ZMQ
syntron Nov 29, 2025
035a549
keep 'import warnings'
syntron Nov 30, 2025
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
14 changes: 12 additions & 2 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.10', '3.12', '3.13']
# test for:
# * Python 3.10 - oldest supported version
# * Python 3.12 - changes in OMCSession / OMCPath
# * Python 3.14 - latest Python version
python-version: ['3.10', '3.12', '3.14']
# * Linux using ubuntu-latest
# * Windows using windows-latest
os: ['ubuntu-latest', 'windows-latest']
omc-version: ['stable', 'nightly']
# * OM 1.25.0 - before changing definition of simulation overrides
# * OM stable - latest stable version
# * OM nightly - latest nightly build
omc-version: ['1.25.0', 'stable', 'nightly']
# => total of 12 runs for each test

steps:
- uses: actions/checkout@v6
Expand Down
266 changes: 107 additions & 159 deletions OMPython/ModelicaSystem.py

Large diffs are not rendered by default.

251 changes: 134 additions & 117 deletions OMPython/OMCSession.py

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,38 @@
ModelicaSystemError,
)
from OMPython.OMCSession import (
OMCPath,
OMCSession,
OMCSessionCmd,
OMCSessionException,
OMCSessionRunData,
OMCSessionZMQ,
OMCSessionPort,
OMCSessionLocal,
OMCSessionDocker,
OMCSessionDockerContainer,
OMCSessionException,
OMCSessionLocal,
OMCSessionPort,
OMCSessionRunData,
OMCSessionWSL,
OMCSessionZMQ,
)

# global names imported if import 'from OMPython import *' is used
__all__ = [
'LinearizationResult',

'ModelicaSystem',
'ModelicaSystemCmd',
'ModelicaSystemDoE',
'ModelicaSystemError',

'OMCPath',

'OMCSession',
'OMCSessionCmd',
'OMCSessionDocker',
'OMCSessionDockerContainer',
'OMCSessionException',
'OMCSessionRunData',
'OMCSessionZMQ',
'OMCSessionPort',
'OMCSessionLocal',
'OMCSessionDocker',
'OMCSessionDockerContainer',
'OMCSessionRunData',
'OMCSessionWSL',
'OMCSessionZMQ',
]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ help(OMPython)
```

```python
from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
from OMPython import OMCSessionLocal
omc = OMCSessionLocal()
omc.sendExpression("getVersion()")
```

Expand Down
16 changes: 8 additions & 8 deletions tests/test_ArrayDimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@


def test_ArrayDimension(tmp_path):
omc = OMPython.OMCSessionZMQ()
omcs = OMPython.OMCSessionLocal()

omc.sendExpression(f'cd("{tmp_path.as_posix()}")')
omcs.sendExpression(f'cd("{tmp_path.as_posix()}")')

omc.sendExpression('loadString("model A Integer x[5+1,1+6]; end A;")')
omc.sendExpression("getErrorString()")
omcs.sendExpression('loadString("model A Integer x[5+1,1+6]; end A;")')
omcs.sendExpression("getErrorString()")

result = omc.sendExpression("getComponents(A)")
result = omcs.sendExpression("getComponents(A)")
assert result[0][-1] == (6, 7), "array dimension does not match"

omc.sendExpression('loadString("model A Integer y = 5; Integer x[y+1,1+9]; end A;")')
omc.sendExpression("getErrorString()")
omcs.sendExpression('loadString("model A Integer y = 5; Integer x[y+1,1+9]; end A;")')
omcs.sendExpression("getErrorString()")

result = omc.sendExpression("getComponents(A)")
result = omcs.sendExpression("getComponents(A)")
assert result[-1][-1] == ('y+1', 10), "array dimension does not match"
12 changes: 6 additions & 6 deletions tests/test_FMIRegression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@


def buildModelFMU(modelName):
omc = OMPython.OMCSessionZMQ()
omcs = OMPython.OMCSessionLocal()

tempdir = pathlib.Path(tempfile.mkdtemp())
try:
omc.sendExpression(f'cd("{tempdir.as_posix()}")')
omcs.sendExpression(f'cd("{tempdir.as_posix()}")')

omc.sendExpression("loadModel(Modelica)")
omc.sendExpression("getErrorString()")
omcs.sendExpression("loadModel(Modelica)")
omcs.sendExpression("getErrorString()")

fileNamePrefix = modelName.split(".")[-1]
exp = f'buildModelFMU({modelName}, fileNamePrefix="{fileNamePrefix}")'
fmu = omc.sendExpression(exp)
fmu = omcs.sendExpression(exp)
assert os.path.exists(fmu)
finally:
del omc
del omcs
shutil.rmtree(tempdir, ignore_errors=True)


Expand Down
19 changes: 9 additions & 10 deletions tests/test_ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ def worker():
)
mod.simulate()
mod.convertMo2Fmu(fmuType="me")

for _ in range(10):
worker()


def test_setParameters():
omc = OMPython.OMCSessionZMQ()
model_path_str = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels"
model_path = omc.omcpath(model_path_str)
omcs = OMPython.OMCSessionLocal()
model_path_str = omcs.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels"
model_path = omcs.omcpath(model_path_str)
mod = OMPython.ModelicaSystem()
mod.model(
model_file=model_path / "BouncingBall.mo",
Expand Down Expand Up @@ -87,9 +88,9 @@ def test_setParameters():


def test_setSimulationOptions():
omc = OMPython.OMCSessionZMQ()
model_path_str = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels"
model_path = omc.omcpath(model_path_str)
omcs = OMPython.OMCSessionLocal()
model_path_str = omcs.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels"
model_path = omcs.omcpath(model_path_str)
mod = OMPython.ModelicaSystem()
mod.model(
model_file=model_path / "BouncingBall.mo",
Expand Down Expand Up @@ -155,11 +156,9 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
@skip_on_windows
@skip_python_older_312
def test_getSolutions_docker(model_firstorder):
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
omc = OMPython.OMCSessionZMQ(omc_process=omcp)

omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
mod = OMPython.ModelicaSystem(
session=omc.omc_process,
session=omcs,
)
mod.model(
model_file=model_firstorder,
Expand Down
10 changes: 3 additions & 7 deletions tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ def test_simflags(mscmd_firstorder):

mscmd.args_set({
"noEventEmit": None,
"override": {'b': 2}
"override": {'b': 2, 'a': 4},
})
with pytest.deprecated_call():
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))

assert mscmd.get_cmd_args() == [
'-noEventEmit',
'-noRestart',
'-override=a=1,b=2,x=3',
'-override=a=4,b=2',
]

mscmd.args_set({
Expand All @@ -53,6 +50,5 @@ def test_simflags(mscmd_firstorder):

assert mscmd.get_cmd_args() == [
'-noEventEmit',
'-noRestart',
'-override=a=1,x=3',
'-override=a=4',
]
7 changes: 3 additions & 4 deletions tests/test_ModelicaSystemDoE.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ def test_ModelicaSystemDoE_local(tmp_path, model_doe, param_doe):
@skip_on_windows
@skip_python_older_312
def test_ModelicaSystemDoE_docker(tmp_path, model_doe, param_doe):
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
omc = OMPython.OMCSessionZMQ(omc_process=omcp)
assert omc.sendExpression("getVersion()") == "OpenModelica 1.25.0"
omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
assert omcs.sendExpression("getVersion()") == "OpenModelica 1.25.0"

doe_mod = OMPython.ModelicaSystemDoE(
model_file=model_doe,
model_name="M",
parameters=param_doe,
session=omcp,
session=omcs,
simargs={"override": {'stopTime': 1.0}},
)

Expand Down
43 changes: 15 additions & 28 deletions tests/test_OMCPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,41 @@
)


def test_OMCPath_OMCSessionZMQ():
om = OMPython.OMCSessionZMQ()

_run_OMCPath_checks(om)

del om


def test_OMCPath_OMCProcessLocal():
omp = OMPython.OMCSessionLocal()
om = OMPython.OMCSessionZMQ(omc_process=omp)
omcs = OMPython.OMCSessionLocal()

_run_OMCPath_checks(om)
_run_OMCPath_checks(omcs)

del om
del omcs


@skip_on_windows
@skip_python_older_312
def test_OMCPath_OMCProcessDocker():
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
om = OMPython.OMCSessionZMQ(omc_process=omcp)
assert om.sendExpression("getVersion()") == "OpenModelica 1.25.0"
omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
assert omcs.sendExpression("getVersion()") == "OpenModelica 1.25.0"

_run_OMCPath_checks(om)
_run_OMCPath_checks(omcs)

del omcp
del om
del omcs


@pytest.mark.skip(reason="Not able to run WSL on github")
@skip_python_older_312
def test_OMCPath_OMCProcessWSL():
omcp = OMPython.OMCSessionWSL(
omcs = OMPython.OMCSessionWSL(
wsl_omc='omc',
wsl_user='omc',
timeout=30.0,
)
om = OMPython.OMCSessionZMQ(omc_process=omcp)

_run_OMCPath_checks(om)
_run_OMCPath_checks(omcs)

del omcp
del om
del omcs


def _run_OMCPath_checks(om: OMPython.OMCSessionZMQ):
p1 = om.omcpath_tempdir()
def _run_OMCPath_checks(omcs: OMPython.OMCSession):
p1 = omcs.omcpath_tempdir()
p2 = p1 / 'test'
p2.mkdir()
assert p2.is_dir()
Expand All @@ -81,14 +68,14 @@ def _run_OMCPath_checks(om: OMPython.OMCSessionZMQ):


def test_OMCPath_write_file(tmpdir):
om = OMPython.OMCSessionZMQ()
omcs = OMPython.OMCSessionLocal()

data = "abc # \\t # \" # \\n # xyz"

p1 = om.omcpath_tempdir()
p1 = omcs.omcpath_tempdir()
p2 = p1 / 'test.txt'
p2.write_text(data=data)

assert data == p2.read_text()

del om
del omcs
4 changes: 2 additions & 2 deletions tests/test_OMSessionCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


def test_isPackage():
omczmq = OMPython.OMCSessionZMQ()
omccmd = OMPython.OMCSessionCmd(session=omczmq.omc_process)
omcs = OMPython.OMCSessionLocal()
omccmd = OMPython.OMCSessionCmd(session=omcs)
assert not omccmd.isPackage('Modelica')


Expand Down
Loading
Loading