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
183 changes: 152 additions & 31 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
ModelicaDoEOMC,
)

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 ModelicaSystemOMC instead!")
class ModelicaSystem(ModelicaSystemOMC):
"""
Compatibility class.
Expand Down Expand Up @@ -67,58 +72,167 @@ def __init__(
def setCommandLineOptions(self, commandLineOptions: str):
super().set_command_line_options(command_line_option=commandLineOptions)

def setContinuous( # type: ignore[override]
def _set_compatibility_helper(
self,
pkey: str,
args: Any,
kwargs: dict[str, Any],
) -> Any:
param = None
if len(args) == 1:
param = args[0]
if param is None and pkey in kwargs:
param = kwargs[pkey]

return param

def setContinuous(
self,
cvals: str | list[str] | dict[str, Any],
*args: Any,
**kwargs: dict[str, Any],
) -> bool:
if isinstance(cvals, dict):
return super().setContinuous(**cvals)
raise ModelicaSystemError("Only dict input supported for setContinuous()")
"""
Compatibility wrapper for setContinuous() from OMPython v4.0.0

Original definition:

def setParameters( # type: ignore[override]
```
def setContinuous(
self,
cvals: str | list[str] | dict[str, Any],
) -> bool:
```
"""
param = self._set_compatibility_helper(pkey='cvals', args=args, kwargs=kwargs)
if param is None:
raise ModelicaSystemError("Invalid input for setContinuous() (v4.0.0 compatibility mode).")

return super().setContinuous(param)

def setParameters(
self,
pvals: str | list[str] | dict[str, Any],
*args: Any,
**kwargs: dict[str, Any],
) -> bool:
if isinstance(pvals, dict):
return super().setParameters(**pvals)
raise ModelicaSystemError("Only dict input supported for setParameters()")
"""
Compatibility wrapper for setParameters() from OMPython v4.0.0

Original definition:

def setOptimizationOptions( # type: ignore[override]
```
def setParameters(
self,
pvals: str | list[str] | dict[str, Any],
) -> bool:
```
"""
param = self._set_compatibility_helper(pkey='pvals', args=args, kwargs=kwargs)
if param is None:
raise ModelicaSystemError("Invalid input for setParameters() (v4.0.0 compatibility mode).")

return super().setParameters(param)

def setOptimizationOptions(
self,
optimizationOptions: str | list[str] | dict[str, Any],
*args: Any,
**kwargs: dict[str, Any],
) -> bool:
if isinstance(optimizationOptions, dict):
return super().setOptimizationOptions(**optimizationOptions)
raise ModelicaSystemError("Only dict input supported for setOptimizationOptions()")
"""
Compatibility wrapper for setOptimizationOptions() from OMPython v4.0.0

Original definition:

def setInputs( # type: ignore[override]
```
def setOptimizationOptions(
self,
optimizationOptions: str | list[str] | dict[str, Any],
) -> bool:
```
"""
param = self._set_compatibility_helper(pkey='optimizationOptions', args=args, kwargs=kwargs)
if param is None:
raise ModelicaSystemError("Invalid input for setOptimizationOptions() (v4.0.0 compatibility mode).")

return super().setOptimizationOptions(param)

def setInputs(
self,
name: str | list[str] | dict[str, Any],
*args: Any,
**kwargs: dict[str, Any],
) -> bool:
if isinstance(name, dict):
return super().setInputs(**name)
raise ModelicaSystemError("Only dict input supported for setInputs()")
"""
Compatibility wrapper for setInputs() from OMPython v4.0.0

Original definition:

def setSimulationOptions( # type: ignore[override]
```
def setInputs(
self,
name: str | list[str] | dict[str, Any],
) -> bool:
```
"""
param = self._set_compatibility_helper(pkey='name', args=args, kwargs=kwargs)
if param is None:
raise ModelicaSystemError("Invalid input for setInputs() (v4.0.0 compatibility mode).")

return super().setInputs(param)

def setSimulationOptions(
self,
simOptions: str | list[str] | dict[str, Any],
*args: Any,
**kwargs: dict[str, Any],
) -> bool:
if isinstance(simOptions, dict):
return super().setSimulationOptions(**simOptions)
raise ModelicaSystemError("Only dict input supported for setSimulationOptions()")
"""
Compatibility wrapper for setSimulationOptions() from OMPython v4.0.0

Original definition:

def setLinearizationOptions( # type: ignore[override]
```
def setSimulationOptions(
self,
simOptions: str | list[str] | dict[str, Any],
) -> bool:
```
"""
param = self._set_compatibility_helper(pkey='simOptions', args=args, kwargs=kwargs)
if param is None:
raise ModelicaSystemError("Invalid input for setSimulationOptions() (v4.0.0 compatibility mode).")

return super().setSimulationOptions(param)

def setLinearizationOptions(
self,
linearizationOptions: str | list[str] | dict[str, Any],
*args: Any,
**kwargs: dict[str, Any],
) -> bool:
if isinstance(linearizationOptions, dict):
return super().setLinearizationOptions(**linearizationOptions)
raise ModelicaSystemError("Only dict input supported for setLinearizationOptions()")
"""
Compatibility wrapper for setLinearizationOptions() from OMPython v4.0.0

Original definition:

```
def setLinearizationOptions(
self,
linearizationOptions: str | list[str] | dict[str, Any],
) -> bool:
```
"""
param = self._set_compatibility_helper(pkey='linearizationOptions', args=args, kwargs=kwargs)
if param is None:
raise ModelicaSystemError("Invalid input for setLinearizationOptions() (v4.0.0 compatibility mode).")

return super().setLinearizationOptions(param)

def getContinuous(
self,
names: Optional[str | list[str]] = None,
):
"""
Compatibility wrapper for getContinuous() from OMPython v4.0.0

If no model simulation was run (self._simulated == False), the return value should be converted to str.
"""
retval = super().getContinuous(names=names)
if self._simulated:
return retval
Expand Down Expand Up @@ -146,6 +260,11 @@ def getOutputs(
self,
names: Optional[str | list[str]] = None,
):
"""
Compatibility wrapper for getOutputs() from OMPython v4.0.0

If no model simulation was run (self._simulated == False), the return value should be converted to str.
"""
retval = super().getOutputs(names=names)
if self._simulated:
return retval
Expand All @@ -170,15 +289,17 @@ def getOutputs(
raise ModelicaSystemError("Invalid data!")


@depreciated_class(msg="Please use class ModelicaDoEOMC instead!")
class ModelicaSystemDoE(ModelicaDoEOMC):
"""
Compatibility class.
"""


@depreciated_class(msg="Please use class ModelExecutionConfig instead!")
class ModelicaSystemCmd(ModelExecutionConfig):
"""
Compatibility class; in the new version it is renamed as ModelExecutionCmd.
Compatibility class; in the new version it is renamed as ModelExecutionConfig.
"""

def __init__(
Expand Down
59 changes: 39 additions & 20 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import logging
from typing import Any, Optional
import warnings

import pyparsing

Expand All @@ -17,7 +16,6 @@
OMSessionException,
)
from OMPython.om_session_omc import (
DockerPopen,
OMCSessionABC,
OMCSessionDocker,
OMCSessionDockerContainer,
Expand All @@ -26,30 +24,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 +224,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 +239,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 @@ -308,9 +300,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
"""
3 changes: 1 addition & 2 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
'ModelicaDoEOMC',
'ModelicaDoERunner',
'ModelicaSystemABC',
'ModelicaSystemDoE',
'ModelicaSystemError',
'ModelicaSystemOMC',
'ModelicaSystemRunner',
Expand All @@ -112,8 +111,8 @@

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

'OMCSessionABC',
'OMCSessionCmd',

'OMCSessionException',
Expand Down
Loading
Loading