Skip to content

Commit e4fd725

Browse files
committed
[ModelicaSystem*] omc_process => session
1 parent d0b6fe2 commit e4fd725

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

OMPython/ModelicaSystem.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def __init__(
333333
command_line_options: Optional[list[str]] = None,
334334
work_directory: Optional[str | os.PathLike] = None,
335335
omhome: Optional[str] = None,
336-
omc_process: Optional[OMCSession] = None,
336+
session: Optional[OMCSession] = None,
337337
) -> None:
338338
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
339339
@@ -345,7 +345,7 @@ def __init__(
345345
files like the model executable. If left unspecified, a tmp
346346
directory will be created.
347347
omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ).
348-
omc_process: definition of a (local) OMC process to be used. If
348+
session: definition of a (local) OMC session to be used. If
349349
unspecified, a new local session will be created.
350350
"""
351351

@@ -373,8 +373,8 @@ def __init__(
373373
self._linearized_outputs: list[str] = [] # linearization output list
374374
self._linearized_states: list[str] = [] # linearization states list
375375

376-
if omc_process is not None:
377-
self._session = OMCSessionZMQ(omc_process=omc_process)
376+
if session is not None:
377+
self._session = OMCSessionZMQ(omc_process=session)
378378
else:
379379
self._session = OMCSessionZMQ(omhome=omhome)
380380

@@ -482,7 +482,7 @@ def model(
482482
if build:
483483
self.buildModel(variable_filter)
484484

485-
def session(self) -> OMCSessionZMQ:
485+
def get_session(self) -> OMCSessionZMQ:
486486
"""
487487
Return the OMC session used for this class.
488488
"""
@@ -1954,7 +1954,7 @@ def __init__(
19541954
variable_filter: Optional[str] = None,
19551955
work_directory: Optional[str | os.PathLike] = None,
19561956
omhome: Optional[str] = None,
1957-
omc_process: Optional[OMCSession] = None,
1957+
session: Optional[OMCSession] = None,
19581958
# simulation specific input
19591959
# TODO: add more settings (simulation options, input options, ...)
19601960
simargs: Optional[dict[str, Optional[str | dict[str, str] | numbers.Number]]] = None,
@@ -1974,7 +1974,7 @@ def __init__(
19741974
command_line_options=command_line_options,
19751975
work_directory=work_directory,
19761976
omhome=omhome,
1977-
omc_process=omc_process,
1977+
session=session,
19781978
)
19791979
self._mod.model(
19801980
model_file=model_file,
@@ -1988,9 +1988,9 @@ def __init__(
19881988
self._simargs = simargs
19891989

19901990
if resultpath is None:
1991-
self._resultpath = self.session().omcpath_tempdir()
1991+
self._resultpath = self.get_session().omcpath_tempdir()
19921992
else:
1993-
self._resultpath = self.session().omcpath(resultpath)
1993+
self._resultpath = self.get_session().omcpath(resultpath)
19941994
if not self._resultpath.is_dir():
19951995
raise ModelicaSystemError("Argument resultpath must be set to a valid path within the environment used "
19961996
f"for the OpenModelica session: {resultpath}!")
@@ -2003,11 +2003,11 @@ def __init__(
20032003
self._doe_def: Optional[dict[str, dict[str, Any]]] = None
20042004
self._doe_cmd: Optional[dict[str, OMCSessionRunData]] = None
20052005

2006-
def session(self) -> OMCSessionZMQ:
2006+
def get_session(self) -> OMCSessionZMQ:
20072007
"""
20082008
Return the OMC session used for this class.
20092009
"""
2010-
return self._mod.session()
2010+
return self._mod.get_session()
20112011

20122012
def prepare(self) -> int:
20132013
"""
@@ -2046,7 +2046,7 @@ def prepare(self) -> int:
20462046

20472047
pk_value = pc_structure[idx_structure]
20482048
if isinstance(pk_value, str):
2049-
pk_value_str = self.session().escape_str(pk_value)
2049+
pk_value_str = self.get_session().escape_str(pk_value)
20502050
expression = f"setParameterValue({self._model_name}, {pk_structure}, \"{pk_value_str}\")"
20512051
elif isinstance(pk_value, bool):
20522052
pk_value_bool_str = "true" if pk_value else "false"
@@ -2167,12 +2167,12 @@ def worker(worker_id, task_queue):
21672167
raise ModelicaSystemError("Missing simulation definition!")
21682168

21692169
resultfile = cmd_definition.cmd_result_path
2170-
resultpath = self.session().omcpath(resultfile)
2170+
resultpath = self.get_session().omcpath(resultfile)
21712171

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

21742174
try:
2175-
returncode = self.session().run_model_executable(cmd_run_data=cmd_definition)
2175+
returncode = self.get_session().run_model_executable(cmd_run_data=cmd_definition)
21762176
logger.info(f"[Worker {worker_id}] Simulation {resultpath.name} "
21772177
f"finished with return code: {returncode}")
21782178
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)