Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from OMPython.OMCSession import (
OMCSessionException,
OMCSessionRunData,
OMCSessionZMQ,
OMCSession,
OMCSessionLocal,
OMCPath,
Expand Down Expand Up @@ -98,7 +97,7 @@ class ModelicaSystemCmd:

def __init__(
self,
session: OMCSessionZMQ,
session: OMCSession,
runpath: OMCPath,
modelname: Optional[str] = None,
) -> None:
Expand Down Expand Up @@ -296,7 +295,7 @@ def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, Any] | n

class ModelicaSystem:
"""
Class to simulate a Modelica model using OpenModelica via OMCSessionZMQ.
Class to simulate a Modelica model using OpenModelica via OMCSession.
"""

def __init__(
Expand All @@ -315,7 +314,7 @@ def __init__(
work_directory: Path to a directory to be used for temporary
files like the model executable. If left unspecified, a tmp
directory will be created.
omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ).
omhome: path to OMC to be used when creating the OMC session (see OMCSession).
session: definition of a (local) OMC session to be used. If
unspecified, a new local session will be created.
"""
Expand Down Expand Up @@ -345,9 +344,9 @@ def __init__(
self._linearized_states: list[str] = [] # linearization states list

if session is not None:
self._session = OMCSessionZMQ(omc_process=session)
self._session = session
else:
self._session = OMCSessionZMQ(omhome=omhome)
self._session = OMCSessionLocal(omhome=omhome)

# set commandLineOptions using default values or the user defined list
if command_line_options is None:
Expand Down Expand Up @@ -432,13 +431,13 @@ def model(
if model_file is not None:
file_path = pathlib.Path(model_file)
# special handling for OMCProcessLocal - consider a relative path
if isinstance(self._session.omc_process, OMCSessionLocal) and not file_path.is_absolute():
if isinstance(self._session, OMCSessionLocal) and not file_path.is_absolute():
file_path = pathlib.Path.cwd() / file_path
if not file_path.is_file():
raise IOError(f"Model file {file_path} does not exist!")

self._file_name = self.getWorkDirectory() / file_path.name
if (isinstance(self._session.omc_process, OMCSessionLocal)
if (isinstance(self._session, OMCSessionLocal)
and file_path.as_posix() == self._file_name.as_posix()):
pass
elif self._file_name.is_file():
Expand All @@ -453,7 +452,7 @@ def model(
if build:
self.buildModel(variable_filter)

def get_session(self) -> OMCSessionZMQ:
def get_session(self) -> OMCSession:
"""
Return the OMC session used for this class.
"""
Expand Down Expand Up @@ -1168,7 +1167,7 @@ def plot(
plot is created by OMC which needs access to the local display. This is not the case for docker and WSL.
"""

if not isinstance(self._session.omc_process, OMCSessionLocal):
if not isinstance(self._session, OMCSessionLocal):
raise ModelicaSystemError("Plot is using the OMC plot functionality; "
"thus, it is only working if OMC is running locally!")

Expand Down Expand Up @@ -1974,7 +1973,7 @@ def __init__(
self._doe_def: Optional[dict[str, dict[str, Any]]] = None
self._doe_cmd: Optional[dict[str, OMCSessionRunData]] = None

def get_session(self) -> OMCSessionZMQ:
def get_session(self) -> OMCSession:
"""
Return the OMC session used for this class.
"""
Expand Down
6 changes: 3 additions & 3 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class OMCSessionCmd:
Implementation of Open Modelica Compiler API functions. Depreciated!
"""

def __init__(self, session: OMCSessionZMQ, readonly: bool = False):
if not isinstance(session, OMCSessionZMQ):
raise OMCSessionException("Invalid session definition!")
def __init__(self, session: OMCSession, readonly: bool = False):
if not isinstance(session, OMCSession):
raise OMCSessionException("Invalid OMC process definition!")
self._session = session
self._readonly = readonly
self._omc_cache: dict[tuple[str, bool], Any] = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_OMSessionCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def test_isPackage():
omczmq = OMPython.OMCSessionZMQ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test still using OMCSessionZMQ?
I understand that OMCSessionZMQ is still in code with depreciation warning but the test should use the latest code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I saw that #386 updates the tests.

omccmd = OMPython.OMCSessionCmd(session=omczmq)
omccmd = OMPython.OMCSessionCmd(session=omczmq.omc_process)
assert not omccmd.isPackage('Modelica')


Expand Down