Skip to content

Commit da13bc7

Browse files
committed
[ModelicaSystem*] omc_process => session
1 parent 6a44b1b commit da13bc7

6 files changed

Lines changed: 19 additions & 19 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def __init__(
336336
command_line_options: Optional[list[str]] = None,
337337
work_directory: Optional[str | os.PathLike] = None,
338338
omhome: Optional[str] = None,
339-
omc_process: Optional[OMCSession] = None,
339+
session: Optional[OMCSession] = None,
340340
timeout: float = 10.0,
341341
) -> None:
342342
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
@@ -349,7 +349,7 @@ def __init__(
349349
files like the model executable. If left unspecified, a tmp
350350
directory will be created.
351351
omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ).
352-
omc_process: definition of a (local) OMC process to be used. If
352+
session: definition of a (local) OMC session to be used. If
353353
unspecified, a new local session will be created.
354354
timeout: float value to define the timeout; if nothing is defined, a default value of 10s is used
355355
"""
@@ -378,8 +378,8 @@ def __init__(
378378
self._linearized_outputs: list[str] = [] # linearization output list
379379
self._linearized_states: list[str] = [] # linearization states list
380380

381-
if omc_process is not None:
382-
self._session = OMCSessionZMQ(omc_process=omc_process)
381+
if session is not None:
382+
self._session = OMCSessionZMQ(omc_process=session)
383383
else:
384384
self._session = OMCSessionZMQ(omhome=omhome, timeout=timeout)
385385

@@ -487,7 +487,7 @@ def model(
487487
if build:
488488
self.buildModel(variable_filter)
489489

490-
def session(self) -> OMCSessionZMQ:
490+
def get_session(self) -> OMCSessionZMQ:
491491
"""
492492
Return the OMC session used for this class.
493493
"""
@@ -1969,7 +1969,7 @@ def __init__(
19691969
variable_filter: Optional[str] = None,
19701970
work_directory: Optional[str | os.PathLike] = None,
19711971
omhome: Optional[str] = None,
1972-
omc_process: Optional[OMCSession] = None,
1972+
session: Optional[OMCSession] = None,
19731973
timeout: float = 10.0,
19741974
# simulation specific input
19751975
# TODO: add more settings (simulation options, input options, ...)
@@ -1990,7 +1990,7 @@ def __init__(
19901990
command_line_options=command_line_options,
19911991
work_directory=work_directory,
19921992
omhome=omhome,
1993-
omc_process=omc_process,
1993+
session=session,
19941994
timeout=timeout,
19951995
)
19961996
self._mod.model(
@@ -2006,9 +2006,9 @@ def __init__(
20062006
self._timeout = timeout
20072007

20082008
if resultpath is None:
2009-
self._resultpath = self.session().omcpath_tempdir()
2009+
self._resultpath = self.get_session().omcpath_tempdir()
20102010
else:
2011-
self._resultpath = self.session().omcpath(resultpath)
2011+
self._resultpath = self.get_session().omcpath(resultpath)
20122012
if not self._resultpath.is_dir():
20132013
raise ModelicaSystemError("Argument resultpath must be set to a valid path within the environment used "
20142014
f"for the OpenModelica session: {resultpath}!")
@@ -2021,11 +2021,11 @@ def __init__(
20212021
self._doe_def: Optional[dict[str, dict[str, Any]]] = None
20222022
self._doe_cmd: Optional[dict[str, OMCSessionRunData]] = None
20232023

2024-
def session(self) -> OMCSessionZMQ:
2024+
def get_session(self) -> OMCSessionZMQ:
20252025
"""
20262026
Return the OMC session used for this class.
20272027
"""
2028-
return self._mod.session()
2028+
return self._mod.get_session()
20292029

20302030
def prepare(self) -> int:
20312031
"""
@@ -2064,7 +2064,7 @@ def prepare(self) -> int:
20642064

20652065
pk_value = pc_structure[idx_structure]
20662066
if isinstance(pk_value, str):
2067-
pk_value_str = self.session().escape_str(pk_value)
2067+
pk_value_str = self.get_session().escape_str(pk_value)
20682068
expression = f"setParameterValue({self._model_name}, {pk_structure}, \"{pk_value_str}\")"
20692069
elif isinstance(pk_value, bool):
20702070
pk_value_bool_str = "true" if pk_value else "false"
@@ -2186,12 +2186,12 @@ def worker(worker_id, task_queue):
21862186
raise ModelicaSystemError("Missing simulation definition!")
21872187

21882188
resultfile = cmd_definition.cmd_result_path
2189-
resultpath = self.session().omcpath(resultfile)
2189+
resultpath = self.get_session().omcpath(resultfile)
21902190

21912191
logger.info(f"[Worker {worker_id}] Performing task: {resultpath.name}")
21922192

21932193
try:
2194-
returncode = self.session().run_model_executable(cmd_run_data=cmd_definition)
2194+
returncode = self.get_session().run_model_executable(cmd_run_data=cmd_definition)
21952195
logger.info(f"[Worker {worker_id}] Simulation {resultpath.name} "
21962196
f"finished with return code: {returncode}")
21972197
except ModelicaSystemError as ex:

tests/test_ModelicaSystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_getSolutions_docker(model_firstorder):
161161
omc = OMPython.OMCSessionZMQ(omc_process=omcp)
162162

163163
mod = OMPython.ModelicaSystem(
164-
omc_process=omc.omc_process,
164+
session=omc.omc_process,
165165
)
166166
mod.model(
167167
model_file=model_firstorder,

tests/test_ModelicaSystemCmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def mscmd_firstorder(model_firstorder):
2424
model_name="M",
2525
)
2626
mscmd = OMPython.ModelicaSystemCmd(
27-
session=mod.session(),
27+
session=mod.get_session(),
2828
runpath=mod.getWorkDirectory(),
2929
modelname=mod._model_name,
3030
)

tests/test_ModelicaSystemDoE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_ModelicaSystemDoE_docker(tmp_path, model_doe, param_doe):
7777
model_file=model_doe.as_posix(),
7878
model_name="M",
7979
parameters=param_doe,
80-
omc_process=omcp,
80+
session=omcp,
8181
simargs={"override": {'stopTime': 1.0}},
8282
)
8383

tests/test_OMSessionCmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_isPackage2():
1313
model_name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
1414
libraries=["Modelica"],
1515
)
16-
omccmd = OMPython.OMCSessionCmd(session=mod.session())
16+
omccmd = OMPython.OMCSessionCmd(session=mod.get_session())
1717
assert omccmd.isPackage('Modelica')
1818

1919

tests/test_optimization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_optimization_example(tmp_path):
5656
r = mod.optimize()
5757
# it is necessary to specify resultfile, otherwise it wouldn't find it.
5858
resultfile_str = r["resultFile"]
59-
resultfile_omcpath = mod.session().omcpath(resultfile_str)
59+
resultfile_omcpath = mod.get_session().omcpath(resultfile_str)
6060
time, f, v = mod.getSolutions(["time", "f", "v"], resultfile=resultfile_omcpath.as_posix())
6161
assert np.isclose(f[0], 10)
6262
assert np.isclose(f[-1], -10)

0 commit comments

Comments
 (0)