Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d0b6fe2
rename classes: *Process* => *Session*
syntron Nov 23, 2025
e4fd725
[ModelicaSystem*] omc_process => session
syntron Nov 23, 2025
fa448ea
[OMCSession*] fix docstrings
syntron Nov 23, 2025
fc04903
[ModelicaSystem*] remove dependency on depreciated OMCSessionZMQ
syntron Nov 23, 2025
6313dd6
[OMCSessionCmd] use OMCSession (old OMCProcess)
syntron Nov 23, 2025
3ccb5fd
[ModelicaSystem] fix initialisation of default OMCSession - use *Local
syntron Nov 26, 2025
fa97850
[unittests] use new definitions / remove OMCSessionZMQ
syntron Nov 23, 2025
8b19a46
[OMCSessionPort] add missing function / catch possible errors
syntron Nov 23, 2025
dd67406
[OMCSessionPort] fix exception message
syntron Nov 26, 2025
331e0a3
[OMCSession] improve logging
syntron Nov 23, 2025
73a38e5
[OMCSession*] define set_timeout()
syntron Nov 26, 2025
fe1775e
[OMCSession*] align all usages of timeout to the same structure
syntron Nov 25, 2025
938a124
[OMCSession*] simplify code for timeout loops
syntron Nov 26, 2025
9ad6f7c
add OMCPath to the public interface
syntron Nov 27, 2025
97e8333
[OMCSession] fix definiton of _timeout variable - use set_timeout() c…
syntron Nov 27, 2025
033e3a8
use keyword arguments if possible (FKA100 - flake8-force-keyword-argu…
syntron Nov 27, 2025
cbb6e56
[OMCSession*] some additional cleanup (mypy / flake8)
syntron Nov 27, 2025
223c895
[OMCSession] move call to set_timeout() to __post_init__
syntron Nov 27, 2025
fc43bdf
update README.md - replace OMCSessionZMQ with OMCSessionLocal
syntron Nov 27, 2025
589b17e
Merge branch 'OMCSessionPort' into v4.1.0-syntron
syntron Nov 28, 2025
b2499f1
Merge branch 'OMCSession_logging' into v4.1.0-syntron
syntron Nov 28, 2025
0ff9630
Merge branch 'linter_fix' into v4.1.0-syntron
syntron Nov 28, 2025
304e117
Merge branch 'OMCPath_to_init' into v4.1.0-syntron
syntron Nov 28, 2025
b1aba64
Merge branch 'ModelicaSystem_timeout' into v4.1.0-syntron
syntron Nov 28, 2025
8c838e8
[ModelicaSystem] remove old style input for set*() functions
syntron Aug 16, 2025
6acd4dd
fix pytest
syntron Aug 18, 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
160 changes: 45 additions & 115 deletions OMPython/ModelicaSystem.py

Large diffs are not rendered by default.

278 changes: 154 additions & 124 deletions OMPython/OMCSession.py

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@
ModelicaSystemError,
)
from OMPython.OMCSession import (
OMCPath,
OMCSessionCmd,
OMCSessionException,
OMCSessionRunData,
OMCSessionZMQ,
OMCProcessPort,
OMCProcessLocal,
OMCProcessDocker,
OMCProcessDockerContainer,
OMCProcessWSL,
OMCSessionPort,
OMCSessionLocal,
OMCSessionDocker,
OMCSessionDockerContainer,
OMCSessionWSL,
)

# global names imported if import 'from OMPython import *' is used
Expand All @@ -63,13 +64,15 @@
'ModelicaSystemDoE',
'ModelicaSystemError',

'OMCPath',

'OMCSessionCmd',
'OMCSessionException',
'OMCSessionRunData',
'OMCSessionZMQ',
'OMCProcessPort',
'OMCProcessLocal',
'OMCProcessDocker',
'OMCProcessDockerContainer',
'OMCProcessWSL',
'OMCSessionPort',
'OMCSessionLocal',
'OMCSessionDocker',
'OMCSessionDockerContainer',
'OMCSessionWSL',
]
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
27 changes: 13 additions & 14 deletions tests/test_ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,24 @@ 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",
model_name="BouncingBall",
)

# method 1 (test depreciated variants)
mod.setParameters("e=1.234")
mod.setParameters(["g=321.0"])
# method 1 (as kwarg)
mod.setParameters(e=1.234)
mod.setParameters(g=321.0)
assert mod.getParameters("e") == ["1.234"]
assert mod.getParameters("g") == ["321.0"]
assert mod.getParameters() == {
Expand All @@ -73,7 +74,7 @@ def test_setParameters():
with pytest.raises(KeyError):
mod.getParameters("thisParameterDoesNotExist")

# method 2 (new style)
# method 2 (as **kwarg)
pvals = {"e": 21.3, "g": 0.12}
mod.setParameters(**pvals)
assert mod.getParameters() == {
Expand All @@ -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.OMCProcessDocker(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(
omc_process=omc.omc_process,
session=omcs,
)
mod.model(
model_file=model_firstorder,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def mscmd_firstorder(model_firstorder):
model_name="M",
)
mscmd = OMPython.ModelicaSystemCmd(
session=mod.session(),
session=mod.get_session(),
runpath=mod.getWorkDirectory(),
modelname=mod._model_name,
)
Expand Down
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.OMCProcessDocker(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,
omc_process=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.OMCProcessLocal()
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.OMCProcessDocker(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.OMCProcessWSL(
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
6 changes: 3 additions & 3 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)
omcs = OMPython.OMCSessionLocal()
omccmd = OMPython.OMCSessionCmd(session=omcs)
assert not omccmd.isPackage('Modelica')


Expand All @@ -13,7 +13,7 @@ def test_isPackage2():
model_name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
libraries=["Modelica"],
)
omccmd = OMPython.OMCSessionCmd(session=mod.session())
omccmd = OMPython.OMCSessionCmd(session=mod.get_session())
assert omccmd.isPackage('Modelica')


Expand Down
63 changes: 30 additions & 33 deletions tests/test_ZMQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,55 @@ def model_time_str():


@pytest.fixture
def om(tmp_path):
def omcs(tmp_path):
origDir = pathlib.Path.cwd()
os.chdir(tmp_path)
om = OMPython.OMCSessionZMQ()
omcs = OMPython.OMCSessionLocal()
os.chdir(origDir)
return om
return omcs


def testHelloWorld(om):
assert om.sendExpression('"HelloWorld!"') == "HelloWorld!"
def testHelloWorld(omcs):
assert omcs.sendExpression('"HelloWorld!"') == "HelloWorld!"


def test_Translate(om, model_time_str):
assert om.sendExpression(model_time_str) == ("M",)
assert om.sendExpression('translateModel(M)') is True
def test_Translate(omcs, model_time_str):
assert omcs.sendExpression(model_time_str) == ("M",)
assert omcs.sendExpression('translateModel(M)') is True


def test_Simulate(om, model_time_str):
assert om.sendExpression(f'loadString("{model_time_str}")') is True
om.sendExpression('res:=simulate(M, stopTime=2.0)')
assert om.sendExpression('res.resultFile')
def test_Simulate(omcs, model_time_str):
assert omcs.sendExpression(f'loadString("{model_time_str}")') is True
omcs.sendExpression('res:=simulate(M, stopTime=2.0)')
assert omcs.sendExpression('res.resultFile')


def test_execute(om):
def test_execute(omcs):
with pytest.deprecated_call():
assert om.execute('"HelloWorld!"') == '"HelloWorld!"\n'
assert om.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert om.sendExpression('"HelloWorld!"', parsed=True) == 'HelloWorld!'
assert omcs.execute('"HelloWorld!"') == '"HelloWorld!"\n'
assert omcs.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert omcs.sendExpression('"HelloWorld!"', parsed=True) == 'HelloWorld!'


def test_omcprocessport_execute(om):
port = om.omc_process.get_port()
omcp = OMPython.OMCProcessPort(omc_port=port)
def test_omcprocessport_execute(omcs):
port = omcs.get_port()
omcs2 = OMPython.OMCSessionPort(omc_port=port)

# run 1
om1 = OMPython.OMCSessionZMQ(omc_process=omcp)
assert om1.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert omcs.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'

# run 2
om2 = OMPython.OMCSessionZMQ(omc_process=omcp)
assert om2.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert omcs2.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'

del om1
del om2
del omcs2


def test_omcprocessport_simulate(om, model_time_str):
port = om.omc_process.get_port()
omcp = OMPython.OMCProcessPort(omc_port=port)
def test_omcprocessport_simulate(omcs, model_time_str):
port = omcs.get_port()
omcs2 = OMPython.OMCSessionPort(omc_port=port)

om = OMPython.OMCSessionZMQ(omc_process=omcp)
assert om.sendExpression(f'loadString("{model_time_str}")') is True
om.sendExpression('res:=simulate(M, stopTime=2.0)')
assert om.sendExpression('res.resultFile') != ""
del om
assert omcs2.sendExpression(f'loadString("{model_time_str}")') is True
omcs2.sendExpression('res:=simulate(M, stopTime=2.0)')
assert omcs2.sendExpression('res.resultFile') != ""

del omcs2
Loading