Skip to content

Commit 8e60588

Browse files
committed
[ModelicaSystem*] do not use OMCSessionZMQ
1 parent a60a304 commit 8e60588

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from OMPython.OMCSession import (
5252
OMCProcessException,
5353
OMCProcessRunData,
54-
OMCSessionZMQ,
5554
OMCProcess,
5655
OMCProcessLocal,
5756
OMCPath,
@@ -127,7 +126,7 @@ class ModelicaSystemCmd:
127126

128127
def __init__(
129128
self,
130-
omc_process: OMCSessionZMQ,
129+
omc_process: OMCProcess,
131130
runpath: OMCPath,
132131
modelname: Optional[str] = None,
133132
timeout: Optional[float] = None,
@@ -337,6 +336,7 @@ def __init__(
337336
work_directory: Optional[str | os.PathLike] = None,
338337
omhome: Optional[str] = None,
339338
omc_process: Optional[OMCProcess] = None,
339+
timeout: float = 10.0,
340340
) -> None:
341341
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
342342
@@ -350,6 +350,7 @@ def __init__(
350350
omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ).
351351
omc_process: definition of a (local) OMC process to be used. If
352352
unspecified, a new local session will be created.
353+
timeout: float value define the timeout; if nothing is defined, a default value of 10s is used
353354
"""
354355

355356
self._quantities: list[dict[str, Any]] = []
@@ -377,9 +378,9 @@ def __init__(
377378
self._linearized_states: list[str] = [] # linearization states list
378379

379380
if omc_process is not None:
380-
self._omc_process = OMCSessionZMQ(omc_process=omc_process)
381+
self._omc_process = omc_process
381382
else:
382-
self._omc_process = OMCSessionZMQ(omhome=omhome)
383+
self._omc_process = OMCProcessLocal(omhome=omhome, timeout=timeout)
383384

384385
# set commandLineOptions using default values or the user defined list
385386
if command_line_options is None:
@@ -464,13 +465,13 @@ def model(
464465
if model_file is not None:
465466
file_path = pathlib.Path(model_file)
466467
# special handling for OMCProcessLocal - consider a relative path
467-
if isinstance(self._omc_process.omc_process, OMCProcessLocal) and not file_path.is_absolute():
468+
if isinstance(self._omc_process, OMCProcessLocal) and not file_path.is_absolute():
468469
file_path = pathlib.Path.cwd() / file_path
469470
if not file_path.is_file():
470471
raise IOError(f"Model file {file_path} does not exist!")
471472

472473
self._file_name = self.getWorkDirectory() / file_path.name
473-
if (isinstance(self._omc_process.omc_process, OMCProcessLocal)
474+
if (isinstance(self._omc_process, OMCProcessLocal)
474475
and file_path.as_posix() == self._file_name.as_posix()):
475476
pass
476477
elif self._file_name.is_file():
@@ -485,7 +486,7 @@ def model(
485486
if build:
486487
self.buildModel(variable_filter)
487488

488-
def get_omc_process(self) -> OMCSessionZMQ:
489+
def get_omc_process(self) -> OMCProcess:
489490
"""
490491
Return the OMC session used for this class.
491492
"""
@@ -1207,7 +1208,7 @@ def plot(
12071208
plot is created by OMC which needs access to the local display. This is not the case for docker and WSL.
12081209
"""
12091210

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

@@ -2018,7 +2019,7 @@ def __init__(
20182019
self._doe_def: Optional[dict[str, dict[str, Any]]] = None
20192020
self._doe_cmd: Optional[dict[str, OMCProcessRunData]] = None
20202021

2021-
def get_omc_process(self) -> OMCSessionZMQ:
2022+
def get_omc_process(self) -> OMCProcess:
20222023
"""
20232024
Return the OMC session used for this class.
20242025
"""

0 commit comments

Comments
 (0)