Skip to content

Commit 4bc3a96

Browse files
committed
[ModelicaSystemCmd] remove depreciated simflags
1 parent 18566e5 commit 4bc3a96

2 files changed

Lines changed: 10 additions & 71 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
import subprocess
4646
import tempfile
4747
import textwrap
48-
from typing import Optional, Any
49-
import warnings
48+
from typing import Any, Optional
5049
import xml.etree.ElementTree as ET
5150

5251
from OMPython.OMCSession import OMCSessionException, OMCSessionZMQ, OMCProcessLocal
@@ -254,45 +253,6 @@ def run(self) -> int:
254253

255254
return returncode
256255

257-
@staticmethod
258-
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]:
259-
"""
260-
Parse a simflag definition; this is deprecated!
261-
262-
The return data can be used as input for self.args_set().
263-
"""
264-
warnings.warn("The argument 'simflags' is depreciated and will be removed in future versions; "
265-
"please use 'simargs' instead", DeprecationWarning, stacklevel=2)
266-
267-
simargs: dict[str, Optional[str | dict[str, str]]] = {}
268-
269-
args = [s for s in simflags.split(' ') if s]
270-
for arg in args:
271-
if arg[0] != '-':
272-
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
273-
arg = arg[1:]
274-
parts = arg.split('=')
275-
if len(parts) == 1:
276-
simargs[parts[0]] = None
277-
elif parts[0] == 'override':
278-
override = '='.join(parts[1:])
279-
280-
override_dict = {}
281-
for item in override.split(','):
282-
kv = item.split('=')
283-
if not 0 < len(kv) < 3:
284-
raise ModelicaSystemError(f"Invalid value for '-override': {override}")
285-
if kv[0]:
286-
try:
287-
override_dict[kv[0]] = kv[1]
288-
except (KeyError, IndexError) as ex:
289-
raise ModelicaSystemError(f"Invalid value for '-override': {override}") from ex
290-
291-
simargs[parts[0]] = override_dict
292-
293-
return simargs
294-
295-
296256
class ModelicaSystem:
297257
def __init__(
298258
self,
@@ -918,7 +878,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
918878
def simulate_cmd(
919879
self,
920880
resultfile: pathlib.Path,
921-
simflags: Optional[str] = None,
922881
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
923882
timeout: Optional[float] = None,
924883
) -> ModelicaSystemCmd:
@@ -932,13 +891,6 @@ def simulate_cmd(
932891
However, if only non-structural parameters are used, it is possible to reuse an existing instance of
933892
ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.
934893
935-
Parameters
936-
----------
937-
resultfile
938-
simflags
939-
simargs
940-
timeout
941-
942894
Returns
943895
-------
944896
An instance if ModelicaSystemCmd to run the requested simulation.
@@ -949,11 +901,7 @@ def simulate_cmd(
949901
# always define the result file to use
950902
om_cmd.arg_set(key="r", val=resultfile.as_posix())
951903

952-
# allow runtime simulation flags from user input
953-
if simflags is not None:
954-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
955-
956-
if simargs:
904+
if simargs is not None:
957905
om_cmd.args_set(args=simargs)
958906

959907
overrideFile = self._tempdir / f"{self._model_name}_override.txt"
@@ -988,7 +936,6 @@ def simulate_cmd(
988936
def simulate(
989937
self,
990938
resultfile: Optional[str] = None,
991-
simflags: Optional[str] = None,
992939
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
993940
timeout: Optional[float] = None,
994941
) -> None:
@@ -998,8 +945,6 @@ def simulate(
998945
999946
Args:
1000947
resultfile: Path to a custom result file
1001-
simflags: String of extra command line flags for the model binary.
1002-
This argument is deprecated, use simargs instead.
1003948
simargs: Dict with simulation runtime flags.
1004949
timeout: Maximum execution time in seconds.
1005950
@@ -1020,7 +965,6 @@ def simulate(
1020965

1021966
om_cmd = self.simulate_cmd(
1022967
resultfile=self._result_file,
1023-
simflags=simflags,
1024968
simargs=simargs,
1025969
timeout=timeout,
1026970
)
@@ -1405,17 +1349,18 @@ def optimize(self) -> dict[str, Any]:
14051349

14061350
return optimizeResult
14071351

1408-
def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = None,
1409-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1410-
timeout: Optional[float] = None) -> LinearizationResult:
1352+
def linearize(
1353+
self,
1354+
lintime: Optional[float] = None,
1355+
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1356+
timeout: Optional[int] = None,
1357+
) -> LinearizationResult:
14111358
"""Linearize the model according to linearization options.
14121359
14131360
See setLinearizationOptions.
14141361
14151362
Args:
14161363
lintime: Override "stopTime" value.
1417-
simflags: String of extra command line flags for the model binary.
1418-
This argument is deprecated, use simargs instead.
14191364
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
14201365
timeout: Maximum execution time in seconds.
14211366
@@ -1468,11 +1413,7 @@ def load_module_from_path(module_name, file_path):
14681413

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

1471-
# allow runtime simulation flags from user input
1472-
if simflags is not None:
1473-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
1474-
1475-
if simargs:
1416+
if simargs is not None:
14761417
om_cmd.args_set(args=simargs)
14771418

14781419
returncode = om_cmd.run()

tests/test_ModelicaSystemCmd.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ def test_simflags(mscmd_firstorder):
2929
"noEventEmit": None,
3030
"override": {'b': 2}
3131
})
32-
with pytest.deprecated_call():
33-
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))
3432

3533
assert mscmd.get_cmd() == [
3634
mscmd.get_exe().as_posix(),
3735
'-noEventEmit',
38-
'-override=b=2,a=1,x=3',
3936
'-noRestart',
37+
'-override=b=2'
4038
]

0 commit comments

Comments
 (0)