Skip to content

Remove deprecated functionality #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
76 changes: 9 additions & 67 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
import subprocess
import tempfile
import textwrap
from typing import Optional, Any
import warnings
from typing import Any, Optional
import xml.etree.ElementTree as ET

from OMPython.OMCSession import OMCSessionException, OMCSessionZMQ, OMCProcessLocal
Expand Down Expand Up @@ -254,44 +253,6 @@ def run(self) -> int:

return returncode

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

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

simargs: dict[str, Optional[str | dict[str, str]]] = {}

args = [s for s in simflags.split(' ') if s]
for arg in args:
if arg[0] != '-':
raise ModelicaSystemError(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 ModelicaSystemError(f"Invalid value for '-override': {override}")
if kv[0]:
try:
override_dict[kv[0]] = kv[1]
except (KeyError, IndexError) as ex:
raise ModelicaSystemError(f"Invalid value for '-override': {override}") from ex

simargs[parts[0]] = override_dict

return simargs


class ModelicaSystem:
def __init__(
Expand Down Expand Up @@ -917,7 +878,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
def simulate_cmd(
self,
result_file: pathlib.Path,
simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
timeout: Optional[float] = None,
) -> ModelicaSystemCmd:
Expand All @@ -931,13 +891,6 @@ def simulate_cmd(
However, if only non-structural parameters are used, it is possible to reuse an existing instance of
ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.

Parameters
----------
result_file
simflags
simargs
timeout

Returns
-------
An instance if ModelicaSystemCmd to run the requested simulation.
Expand All @@ -948,11 +901,7 @@ def simulate_cmd(
# always define the result file to use
om_cmd.arg_set(key="r", val=result_file.as_posix())

# allow runtime simulation flags from user input
if simflags is not None:
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))

if simargs:
if simargs is not None:
om_cmd.args_set(args=simargs)

overrideFile = self._tempdir / f"{self._model_name}_override.txt"
Expand Down Expand Up @@ -992,7 +941,6 @@ def simulate_cmd(
def simulate(
self,
resultfile: Optional[str] = None,
simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
timeout: Optional[float] = None,
) -> None:
Expand All @@ -1002,8 +950,6 @@ def simulate(

Args:
resultfile: Path to a custom result file
simflags: String of extra command line flags for the model binary.
This argument is deprecated, use simargs instead.
simargs: Dict with simulation runtime flags.
timeout: Maximum execution time in seconds.

Expand All @@ -1024,7 +970,6 @@ def simulate(

om_cmd = self.simulate_cmd(
result_file=self._result_file,
simflags=simflags,
simargs=simargs,
timeout=timeout,
)
Expand Down Expand Up @@ -1414,17 +1359,18 @@ def optimize(self) -> dict[str, Any]:

return optimizeResult

def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
timeout: Optional[float] = None) -> LinearizationResult:
def linearize(
self,
lintime: Optional[float] = None,
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
timeout: Optional[int] = None,
) -> LinearizationResult:
"""Linearize the model according to linearization options.

See setLinearizationOptions.

Args:
lintime: Override "stopTime" value.
simflags: String of extra command line flags for the model binary.
This argument is deprecated, use simargs instead.
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
timeout: Maximum execution time in seconds.

Expand Down Expand Up @@ -1477,11 +1423,7 @@ def load_module_from_path(module_name, file_path):

om_cmd.arg_set(key="l", val=str(lintime or self._linearization_options["stopTime"]))

# allow runtime simulation flags from user input
if simflags is not None:
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))

if simargs:
if simargs is not None:
om_cmd.args_set(args=simargs)

returncode = om_cmd.run()
Expand Down
7 changes: 0 additions & 7 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import time
from typing import Any, Optional, Tuple
import uuid
import warnings
import zmq

# TODO: replace this with the new parser
Expand Down Expand Up @@ -322,12 +321,6 @@ def __del__(self):

self.omc_zmq = None

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

return self.sendExpression(command, parsed=False)

def sendExpression(self, command: str, parsed: bool = True) -> Any:
if self.omc_zmq is None:
raise OMCSessionException("No OMC running. Create a new instance of OMCSessionZMQ!")
Expand Down
5 changes: 1 addition & 4 deletions tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ def test_simflags(mscmd_firstorder):
"noEventEmit": None,
"override": {'b': 2}
})
with pytest.deprecated_call():
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))

assert mscmd.get_cmd() == [
mscmd.get_exe().as_posix(),
'-noEventEmit',
'-override=b=2,a=1,x=3',
'-noRestart',
'-override=b=2'
]
4 changes: 1 addition & 3 deletions tests/test_ZMQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def test_Simulate(om, model_time_str):
assert om.sendExpression('res.resultFile')


def test_execute(om):
with pytest.deprecated_call():
assert om.execute('"HelloWorld!"') == '"HelloWorld!"\n'
def test_sendExpression(om):
assert om.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert om.sendExpression('"HelloWorld!"', parsed=True) == 'HelloWorld!'

Expand Down
Loading