Skip to content

Commit 5496bfa

Browse files
committed
[ModelicaSystem*] omc_process => session
1 parent 7fb3e7a commit 5496bfa

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
) -> None:
341341
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
342342
@@ -348,7 +348,7 @@ def __init__(
348348
files like the model executable. If left unspecified, a tmp
349349
directory will be created.
350350
omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ).
351-
omc_process: definition of a (local) OMC process to be used. If
351+
session: definition of a (local) OMC session to be used. If
352352
unspecified, a new local session will be created.
353353
"""
354354

@@ -376,8 +376,8 @@ def __init__(
376376
self._linearized_outputs: list[str] = [] # linearization output list
377377
self._linearized_states: list[str] = [] # linearization states list
378378

379-
if omc_process is not None:
380-
self._session = OMCSessionZMQ(omc_process=omc_process)
379+
if session is not None:
380+
self._session = OMCSessionZMQ(omc_process=session)
381381
else:
382382
self._session = OMCSessionZMQ(omhome=omhome)
383383

@@ -485,7 +485,7 @@ def model(
485485
if build:
486486
self.buildModel(variable_filter)
487487

488-
def session(self) -> OMCSessionZMQ:
488+
def get_session(self) -> OMCSessionZMQ:
489489
"""
490490
Return the OMC session used for this class.
491491
"""
@@ -1967,7 +1967,7 @@ def __init__(
19671967
variable_filter: Optional[str] = None,
19681968
work_directory: Optional[str | os.PathLike] = None,
19691969
omhome: Optional[str] = None,
1970-
omc_process: Optional[OMCSession] = None,
1970+
session: Optional[OMCSession] = None,
19711971
# simulation specific input
19721972
# TODO: add more settings (simulation options, input options, ...)
19731973
simargs: Optional[dict[str, Optional[str | dict[str, str] | numbers.Number]]] = None,
@@ -1988,7 +1988,7 @@ def __init__(
19881988
command_line_options=command_line_options,
19891989
work_directory=work_directory,
19901990
omhome=omhome,
1991-
omc_process=omc_process,
1991+
session=session,
19921992
)
19931993
self._mod.model(
19941994
model_file=model_file,
@@ -2003,9 +2003,9 @@ def __init__(
20032003
self._timeout = timeout
20042004

20052005
if resultpath is None:
2006-
self._resultpath = self.session().omcpath_tempdir()
2006+
self._resultpath = self.get_session().omcpath_tempdir()
20072007
else:
2008-
self._resultpath = self.session().omcpath(resultpath)
2008+
self._resultpath = self.get_session().omcpath(resultpath)
20092009
if not self._resultpath.is_dir():
20102010
raise ModelicaSystemError("Argument resultpath must be set to a valid path within the environment used "
20112011
f"for the OpenModelica session: {resultpath}!")
@@ -2018,11 +2018,11 @@ def __init__(
20182018
self._doe_def: Optional[dict[str, dict[str, Any]]] = None
20192019
self._doe_cmd: Optional[dict[str, OMCSessionRunData]] = None
20202020

2021-
def session(self) -> OMCSessionZMQ:
2021+
def get_session(self) -> OMCSessionZMQ:
20222022
"""
20232023
Return the OMC session used for this class.
20242024
"""
2025-
return self._mod.session()
2025+
return self._mod.get_session()
20262026

20272027
def prepare(self) -> int:
20282028
"""
@@ -2061,7 +2061,7 @@ def prepare(self) -> int:
20612061

20622062
pk_value = pc_structure[idx_structure]
20632063
if isinstance(pk_value, str):
2064-
pk_value_str = self.session().escape_str(pk_value)
2064+
pk_value_str = self.get_session().escape_str(pk_value)
20652065
expression = f"setParameterValue({self._model_name}, {pk_structure}, \"{pk_value_str}\")"
20662066
elif isinstance(pk_value, bool):
20672067
pk_value_bool_str = "true" if pk_value else "false"
@@ -2183,12 +2183,12 @@ def worker(worker_id, task_queue):
21832183
raise ModelicaSystemError("Missing simulation definition!")
21842184

21852185
resultfile = cmd_definition.cmd_result_path
2186-
resultpath = self.session().omcpath(resultfile)
2186+
resultpath = self.get_session().omcpath(resultfile)
21872187

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

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

tests/test_ModelicaSystem.py

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

161161
mod = OMPython.ModelicaSystem(
162-
omc_process=omc.omc_process,
162+
session=omc.omc_process,
163163
)
164164
mod.model(
165165
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,
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(
6161
varList=["time", "f", "v"],
6262
resultfile=resultfile_omcpath,

0 commit comments

Comments
 (0)