Skip to content

Commit b2b7817

Browse files
committed
[ModelicaSystem] session => omc_process
1 parent 2e34e03 commit b2b7817

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ def __init__(
377377
self._linearized_states: list[str] = [] # linearization states list
378378

379379
if omc_process is not None:
380-
self._session = OMCSessionZMQ(omc_process=omc_process)
380+
self._omc_process = OMCSessionZMQ(omc_process=omc_process)
381381
else:
382-
self._session = OMCSessionZMQ(omhome=omhome)
382+
self._omc_process = OMCSessionZMQ(omhome=omhome)
383383

384384
# set commandLineOptions using default values or the user defined list
385385
if command_line_options is None:
@@ -464,13 +464,13 @@ def model(
464464
if model_file is not None:
465465
file_path = pathlib.Path(model_file)
466466
# special handling for OMCProcessLocal - consider a relative path
467-
if isinstance(self._session.omc_process, OMCProcessLocal) and not file_path.is_absolute():
467+
if isinstance(self._omc_process.omc_process, OMCProcessLocal) and not file_path.is_absolute():
468468
file_path = pathlib.Path.cwd() / file_path
469469
if not file_path.is_file():
470470
raise IOError(f"Model file {file_path} does not exist!")
471471

472472
self._file_name = self.getWorkDirectory() / file_path.name
473-
if (isinstance(self._session.omc_process, OMCProcessLocal)
473+
if (isinstance(self._omc_process.omc_process, OMCProcessLocal)
474474
and file_path.as_posix() == self._file_name.as_posix()):
475475
pass
476476
elif self._file_name.is_file():
@@ -485,11 +485,11 @@ def model(
485485
if build:
486486
self.buildModel(variable_filter)
487487

488-
def session(self) -> OMCSessionZMQ:
488+
def get_omc_process(self) -> OMCSessionZMQ:
489489
"""
490490
Return the OMC session used for this class.
491491
"""
492-
return self._session
492+
return self._omc_process
493493

494494
def set_command_line_options(self, command_line_option: str):
495495
"""
@@ -532,11 +532,11 @@ def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -
532532
directory. If no directory is defined a unique temporary directory is created.
533533
"""
534534
if work_directory is not None:
535-
workdir = self._session.omcpath(work_directory).absolute()
535+
workdir = self._omc_process.omcpath(work_directory).absolute()
536536
if not workdir.is_dir():
537537
raise IOError(f"Provided work directory does not exists: {work_directory}!")
538538
else:
539-
workdir = self._session.omcpath_tempdir().absolute()
539+
workdir = self._omc_process.omcpath_tempdir().absolute()
540540
if not workdir.is_dir():
541541
raise IOError(f"{workdir} could not be created")
542542

@@ -572,24 +572,24 @@ def buildModel(self, variableFilter: Optional[str] = None):
572572

573573
# check if the executable exists ...
574574
om_cmd = ModelicaSystemCmd(
575-
omc_process=self._session,
575+
omc_process=self._omc_process,
576576
runpath=self.getWorkDirectory(),
577577
modelname=self._model_name,
578578
timeout=5.0,
579579
)
580580
# ... by running it - output help for command help
581581
om_cmd.arg_set(key="help", val="help")
582582
cmd_definition = om_cmd.definition()
583-
returncode = self._session.run_model_executable(cmd_run_data=cmd_definition)
583+
returncode = self._omc_process.run_model_executable(cmd_run_data=cmd_definition)
584584
if returncode != 0:
585585
raise ModelicaSystemError("Model executable not working!")
586586

587-
xml_file = self._session.omcpath(build_model_result[0]).parent / build_model_result[1]
587+
xml_file = self._omc_process.omcpath(build_model_result[0]).parent / build_model_result[1]
588588
self._xmlparse(xml_file=xml_file)
589589

590590
def sendExpression(self, expr: str, parsed: bool = True) -> Any:
591591
try:
592-
retval = self._session.sendExpression(expr, parsed)
592+
retval = self._omc_process.sendExpression(expr, parsed)
593593
except OMCProcessException as ex:
594594
raise ModelicaSystemError(f"Error executing {repr(expr)}: {ex}") from ex
595595

@@ -1083,7 +1083,7 @@ def simulate_cmd(
10831083
"""
10841084

10851085
om_cmd = ModelicaSystemCmd(
1086-
omc_process=self._session,
1086+
omc_process=self._omc_process,
10871087
runpath=self.getWorkDirectory(),
10881088
modelname=self._model_name,
10891089
timeout=timeout,
@@ -1164,7 +1164,7 @@ def simulate(
11641164
elif isinstance(resultfile, OMCPath):
11651165
self._result_file = resultfile
11661166
else:
1167-
self._result_file = self._session.omcpath(resultfile)
1167+
self._result_file = self._omc_process.omcpath(resultfile)
11681168
if not self._result_file.is_absolute():
11691169
self._result_file = self.getWorkDirectory() / resultfile
11701170

@@ -1183,7 +1183,7 @@ def simulate(
11831183
self._result_file.unlink()
11841184
# ... run simulation ...
11851185
cmd_definition = om_cmd.definition()
1186-
returncode = self._session.run_model_executable(cmd_run_data=cmd_definition)
1186+
returncode = self._omc_process.run_model_executable(cmd_run_data=cmd_definition)
11871187
# and check returncode *AND* resultfile
11881188
if returncode != 0 and self._result_file.is_file():
11891189
# check for an empty (=> 0B) result file which indicates a crash of the model executable
@@ -1207,12 +1207,12 @@ def plot(
12071207
plot is created by OMC which needs access to the local display. This is not the case for docker and WSL.
12081208
"""
12091209

1210-
if not isinstance(self._session.omc_process, OMCProcessLocal):
1210+
if not isinstance(self._omc_process.omc_process, OMCProcessLocal):
12111211
raise ModelicaSystemError("Plot is using the OMC plot functionality; "
12121212
"thus, it is only working if OMC is running locally!")
12131213

12141214
if resultfile is not None:
1215-
plot_result_file = self._session.omcpath(resultfile)
1215+
plot_result_file = self._omc_process.omcpath(resultfile)
12161216
elif self._result_file is not None:
12171217
plot_result_file = self._result_file
12181218
else:
@@ -1266,7 +1266,7 @@ def getSolutions(
12661266
raise ModelicaSystemError("No result file found. Run simulate() first.")
12671267
result_file = self._result_file
12681268
else:
1269-
result_file = self._session.omcpath(resultfile)
1269+
result_file = self._omc_process.omcpath(resultfile)
12701270

12711271
# check if the result file exits
12721272
if not result_file.is_file():
@@ -1683,7 +1683,7 @@ def convertMo2Fmu(
16831683
properties = (f'version="{version}", fmuType="{fmuType}", '
16841684
f'fileNamePrefix="{fileNamePrefix}", includeResources={include_resources_str}')
16851685
fmu = self._requestApi(apiName='buildModelFMU', entity=self._model_name, properties=properties)
1686-
fmu_path = self._session.omcpath(fmu)
1686+
fmu_path = self._omc_process.omcpath(fmu)
16871687

16881688
# report proper error message
16891689
if not fmu_path.is_file():
@@ -1704,7 +1704,7 @@ def convertFmu2Mo(
17041704
>>> convertFmu2Mo("c:/BouncingBall.Fmu")
17051705
"""
17061706

1707-
fmu_path = self._session.omcpath(fmu)
1707+
fmu_path = self._omc_process.omcpath(fmu)
17081708

17091709
if not fmu_path.is_file():
17101710
raise ModelicaSystemError(f"Missing FMU file: {fmu_path.as_posix()}")
@@ -1789,7 +1789,7 @@ def linearize(
17891789
)
17901790

17911791
om_cmd = ModelicaSystemCmd(
1792-
omc_process=self._session,
1792+
omc_process=self._omc_process,
17931793
runpath=self.getWorkDirectory(),
17941794
modelname=self._model_name,
17951795
timeout=timeout,
@@ -1828,7 +1828,7 @@ def linearize(
18281828
linear_file.unlink(missing_ok=True)
18291829

18301830
cmd_definition = om_cmd.definition()
1831-
returncode = self._session.run_model_executable(cmd_run_data=cmd_definition)
1831+
returncode = self._omc_process.run_model_executable(cmd_run_data=cmd_definition)
18321832
if returncode != 0:
18331833
raise ModelicaSystemError(f"Linearize failed with return code: {returncode}")
18341834
if not linear_file.is_file():
@@ -2022,7 +2022,7 @@ def session(self) -> OMCSessionZMQ:
20222022
"""
20232023
Return the OMC session used for this class.
20242024
"""
2025-
return self._mod.session()
2025+
return self._mod.get_omc_process()
20262026

20272027
def prepare(self) -> int:
20282028
"""

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-
omc_process=mod.session(),
27+
omc_process=mod.get_omc_process(),
2828
runpath=mod.getWorkDirectory(),
2929
modelname=mod._model_name,
3030
)

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.OMCCmd(session=mod.session())
16+
omccmd = OMPython.OMCCmd(session=mod.get_omc_process())
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_omc_process().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)