Skip to content

Commit 4263a08

Browse files
committed
[ModelicaSystemCmd] remove depreciated simflags
1 parent 691bbf8 commit 4263a08

File tree

2 files changed

+10
-71
lines changed

2 files changed

+10
-71
lines changed

OMPython/ModelicaSystem.py

Lines changed: 9 additions & 67 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,44 +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-
295256

296257
class ModelicaSystem:
297258
def __init__(
@@ -916,7 +877,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
916877
def simulate_cmd(
917878
self,
918879
result_file: pathlib.Path,
919-
simflags: Optional[str] = None,
920880
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
921881
timeout: Optional[float] = None,
922882
) -> ModelicaSystemCmd:
@@ -930,13 +890,6 @@ def simulate_cmd(
930890
However, if only non-structural parameters are used, it is possible to reuse an existing instance of
931891
ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.
932892
933-
Parameters
934-
----------
935-
result_file
936-
simflags
937-
simargs
938-
timeout
939-
940893
Returns
941894
-------
942895
An instance if ModelicaSystemCmd to run the requested simulation.
@@ -947,11 +900,7 @@ def simulate_cmd(
947900
# always define the result file to use
948901
om_cmd.arg_set(key="r", val=result_file.as_posix())
949902

950-
# allow runtime simulation flags from user input
951-
if simflags is not None:
952-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
953-
954-
if simargs:
903+
if simargs is not None:
955904
om_cmd.args_set(args=simargs)
956905

957906
overrideFile = self._tempdir / f"{self._model_name}_override.txt"
@@ -989,7 +938,6 @@ def simulate_cmd(
989938
def simulate(
990939
self,
991940
resultfile: Optional[str] = None,
992-
simflags: Optional[str] = None,
993941
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
994942
timeout: Optional[float] = None,
995943
) -> None:
@@ -999,8 +947,6 @@ def simulate(
999947
1000948
Args:
1001949
resultfile: Path to a custom result file
1002-
simflags: String of extra command line flags for the model binary.
1003-
This argument is deprecated, use simargs instead.
1004950
simargs: Dict with simulation runtime flags.
1005951
timeout: Maximum execution time in seconds.
1006952
@@ -1021,7 +967,6 @@ def simulate(
1021967

1022968
om_cmd = self.simulate_cmd(
1023969
result_file=self._result_file,
1024-
simflags=simflags,
1025970
simargs=simargs,
1026971
timeout=timeout,
1027972
)
@@ -1511,17 +1456,18 @@ def optimize(self) -> dict[str, Any]:
15111456

15121457
return optimizeResult
15131458

1514-
def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = None,
1515-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1516-
timeout: Optional[float] = None) -> LinearizationResult:
1459+
def linearize(
1460+
self,
1461+
lintime: Optional[float] = None,
1462+
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1463+
timeout: Optional[int] = None,
1464+
) -> LinearizationResult:
15171465
"""Linearize the model according to linearization options.
15181466
15191467
See setLinearizationOptions.
15201468
15211469
Args:
15221470
lintime: Override "stopTime" value.
1523-
simflags: String of extra command line flags for the model binary.
1524-
This argument is deprecated, use simargs instead.
15251471
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
15261472
timeout: Maximum execution time in seconds.
15271473
@@ -1565,11 +1511,7 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
15651511

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

1568-
# allow runtime simulation flags from user input
1569-
if simflags is not None:
1570-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
1571-
1572-
if simargs:
1514+
if simargs is not None:
15731515
om_cmd.args_set(args=simargs)
15741516

15751517
# the file create by the model executable which contains the matrix and linear inputs, outputs and states

tests/test_ModelicaSystemCmd.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ 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',
39-
'-noRestart',
36+
'-override=b=2'
4037
]

0 commit comments

Comments
 (0)