Skip to content
Open
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
358 changes: 299 additions & 59 deletions OMPython/ModelicaSystem.py

Large diffs are not rendered by default.

66 changes: 46 additions & 20 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
OMSessionException,
)
from OMPython.om_session_omc import (
DockerPopen,
OMCSessionABC,
OMCSessionDocker,
OMCSessionDockerContainer,
Expand All @@ -26,30 +25,28 @@
OMCSessionWSL,
)

from OMPython.compatibility_v400 import (
depreciated_class,
)

# define logger using the current module name as ID
logger = logging.getLogger(__name__)


@depreciated_class(msg="Please use class OMSessionException instead!")
class OMCSessionException(OMSessionException):
"""
Just a compatibility layer ...
"""


@depreciated_class(msg="Please use OMCSession*.sendExpression(...) instead!")
class OMCSessionCmd:
"""
Implementation of Open Modelica Compiler API functions. Depreciated!
"""

def __init__(self, session: OMSessionABC, readonly: bool = False):
warnings.warn(
message="The class OMCSessionCMD is depreciated and will be removed in future versions; "
"please use OMCSession*.sendExpression(...) instead!",
category=DeprecationWarning,
stacklevel=2,
)

if not isinstance(session, OMSessionABC):
raise OMCSessionException("Invalid OMC process definition!")
self._session = session
Expand Down Expand Up @@ -228,6 +225,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
return self._ask(question='getClassNames', opt=opt)


@depreciated_class(msg="Please use OMCSession* classes instead!")
class OMCSessionZMQ(OMSessionABC):
"""
This class is a compatibility layer for the new schema using OMCSession* classes.
Expand All @@ -242,11 +240,6 @@ def __init__(
"""
Initialisation for OMCSessionZMQ
"""
warnings.warn(message="The class OMCSessionZMQ is depreciated and will be removed in future versions; "
"please use OMCProcess* classes instead!",
category=DeprecationWarning,
stacklevel=2)

if omc_process is None:
omc_process = OMCSessionLocal(omhome=omhome, timeout=timeout)
elif not isinstance(omc_process, OMCSessionABC):
Expand Down Expand Up @@ -280,7 +273,13 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMPathABC] = None) -> OMPathABC
return self.omc_process.omcpath_tempdir(tempdir_base=tempdir_base)

def execute(self, command: str):
return self.omc_process.execute(command=command)
warnings.warn(
message="This function is depreciated and will be removed in future versions; "
"please use sendExpression() instead",
category=DeprecationWarning,
stacklevel=2,
)
return self.omc_process.sendExpression(expr=command, parsed=False)

def sendExpression(
self,
Expand Down Expand Up @@ -308,9 +307,36 @@ def set_workdir(self, workdir: OMPathABC) -> None:
return self.omc_process.set_workdir(workdir=workdir)


DummyPopen = DockerPopen
OMCProcessLocal = OMCSessionLocal
OMCProcessPort = OMCSessionPort
OMCProcessDocker = OMCSessionDocker
OMCProcessDockerContainer = OMCSessionDockerContainer
OMCProcessWSL = OMCSessionWSL
@depreciated_class(msg="Please use class OMCSessionLocal instead!")
class OMCProcessLocal(OMCSessionLocal):
"""
Just a wrapper class; OMCProcessLocal => OMCSessionLocal
"""


@depreciated_class(msg="Please use class OMCSessionPort instead!")
class OMCProcessPort(OMCSessionPort):
"""
Just a wrapper class; OMCProcessPort => OMCSessionPort
"""


@depreciated_class(msg="Please use class OMCSessionDocker instead!")
class OMCProcessDocker(OMCSessionDocker):
"""
Just a wrapper class; OMCProcessDocker => OMCSessionDocker
"""


@depreciated_class(msg="Please use class OMCSessionDockerContainer instead!")
class OMCProcessDockerContainer(OMCSessionDockerContainer):
"""
Just a wrapper class; OMCProcessDockerContainer => OMCSessionDockerContainer
"""


@depreciated_class(msg="Please use class OMCSessionWSL instead!")
class OMCProcessWSL(OMCSessionWSL):
"""
Just a wrapper class; OMCProcessWSL => OMCSessionWSL
"""
7 changes: 3 additions & 4 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
# the imports below are compatibility functionality (OMPython v4.0.0)
from OMPython.ModelicaSystem import (
ModelicaSystem,
ModelicaSystemCmd,
ModelicaSystemDoE,
parse_simflags,
)
from OMPython.OMCSession import (
OMCSessionCmd,
Expand All @@ -89,7 +89,6 @@
'ModelicaDoEOMC',
'ModelicaDoERunner',
'ModelicaSystemABC',
'ModelicaSystemDoE',
'ModelicaSystemError',
'ModelicaSystemOMC',
'ModelicaSystemRunner',
Expand All @@ -110,10 +109,10 @@
'OMPathRunnerLocal',
'OMSessionRunner',

'ModelicaSystemCmd',
'ModelicaSystem',
'ModelicaSystemDoE',
'parse_simflags',

'OMCSessionABC',
'OMCSessionCmd',

'OMCSessionException',
Expand Down
39 changes: 39 additions & 0 deletions OMPython/compatibility_v400.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
"""
Helper functions for compatibility with OMPython v4.0.0
"""
import warnings
from typing import Optional


def depreciated_class(msg: Optional[str] = None):
"""
Decorator for depreciated / compatibility classes.
"""

def depreciated(cls):
"""
Helper functions to do the decoration part.
"""

class Wrapper(cls):
"""
Wrapper to define the depreciation message.
"""

def __init__(self, *args, **kwargs):
message = f"The class {cls.__name__} is depreciated and will be removed in future versions!"
if msg is not None:
message += f" {msg}"

warnings.warn(
message=message,
category=DeprecationWarning,
stacklevel=3,
)

super().__init__(*args, **kwargs)

return Wrapper

return depreciated
43 changes: 0 additions & 43 deletions OMPython/model_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import re
import subprocess
from typing import Any, Optional
import warnings

# define logger using the current module name as ID
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -314,45 +313,3 @@ def definition(self) -> ModelExecutionRun:
)

return omc_run_data

@staticmethod
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, Any] | numbers.Number]]:
"""
Parse a simflag definition; this is deprecated!

The return data can be used as input for self.args_set().
"""
warnings.warn(
message="The argument 'simflags' is depreciated and will be removed in future versions; "
"please use 'simargs' instead",
category=DeprecationWarning,
stacklevel=2,
)

simargs: dict[str, Optional[str | dict[str, Any] | numbers.Number]] = {}

args = [s for s in simflags.split(' ') if s]
for arg in args:
if arg[0] != '-':
raise ModelExecutionException(f"Invalid simulation flag: {arg}")
arg = arg[1:]
parts = arg.split('=')
if len(parts) == 1:
simargs[parts[0]] = None
elif parts[0] == 'override':
override = '='.join(parts[1:])

override_dict = {}
for item in override.split(','):
kv = item.split('=')
if not 0 < len(kv) < 3:
raise ModelExecutionException(f"Invalid value for '-override': {override}")
if kv[0]:
try:
override_dict[kv[0]] = kv[1]
except (KeyError, IndexError) as ex:
raise ModelExecutionException(f"Invalid value for '-override': {override}") from ex

simargs[parts[0]] = override_dict

return simargs
7 changes: 4 additions & 3 deletions OMPython/modelica_doe_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from OMPython.model_execution import (
ModelExecutionRun,
ModelExecutionException,
)
from OMPython.om_session_abc import (
OMPathABC,
Expand Down Expand Up @@ -209,7 +210,7 @@ def prepare(self) -> int:
}
)

self._mod.setParameters(sim_param_non_structural)
self._mod.setParameters(**sim_param_non_structural)
mscmd = self._mod.simulate_cmd(
result_file=resultfile,
)
Expand Down Expand Up @@ -310,8 +311,8 @@ def worker(worker_id, task_queue):
returncode = cmd_definition.run()
logger.info(f"[Worker {worker_id}] Simulation {resultpath.name} "
f"finished with return code: {returncode}")
except ModelicaSystemError as ex:
logger.warning(f"Simulation error for {resultpath.name}: {ex}")
except ModelExecutionException as exc:
logger.warning(f"Simulation error for {resultpath.name}: {exc}")

# Mark the task as done
task_queue.task_done()
Expand Down
Loading
Loading