Skip to content

Commit f7c04b5

Browse files
committed
[ModelicaSystemCmd] remove depreciated simflags
1 parent d8c2d71 commit f7c04b5

2 files changed

Lines changed: 18 additions & 70 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 66 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
@@ -275,52 +274,6 @@ def run(self) -> int:
275274

276275
return returncode
277276

278-
@staticmethod
279-
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]:
280-
"""
281-
Parse a simflag definition; this is depreciated!
282-
283-
The return data can be used as input for self.args_set().
284-
285-
Parameters
286-
----------
287-
simflags : str
288-
289-
Returns
290-
-------
291-
dict
292-
"""
293-
warnings.warn("The argument 'simflags' is depreciated and will be removed in future versions; "
294-
"please use 'simargs' instead", DeprecationWarning, stacklevel=2)
295-
296-
simargs: dict[str, Optional[str | dict[str, str]]] = {}
297-
298-
args = [s for s in simflags.split(' ') if s]
299-
for arg in args:
300-
if arg[0] != '-':
301-
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
302-
arg = arg[1:]
303-
parts = arg.split('=')
304-
if len(parts) == 1:
305-
simargs[parts[0]] = None
306-
elif parts[0] == 'override':
307-
override = '='.join(parts[1:])
308-
309-
override_dict = {}
310-
for item in override.split(','):
311-
kv = item.split('=')
312-
if not 0 < len(kv) < 3:
313-
raise ModelicaSystemError(f"Invalid value for '-override': {override}")
314-
if kv[0]:
315-
try:
316-
override_dict[kv[0]] = kv[1]
317-
except (KeyError, IndexError) as ex:
318-
raise ModelicaSystemError(f"Invalid value for '-override': {override}") from ex
319-
320-
simargs[parts[0]] = override_dict
321-
322-
return simargs
323-
324277

325278
class ModelicaSystem:
326279
def __init__(
@@ -867,9 +820,12 @@ def getOptimizationOptions(self, names=None): # 10
867820

868821
raise ModelicaSystemError("Unhandled input for getOptimizationOptions()")
869822

870-
def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = None,
871-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
872-
timeout: Optional[int] = None): # 11
823+
def simulate(
824+
self,
825+
resultfile: Optional[str] = None,
826+
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
827+
timeout: Optional[int] = None
828+
): # 11
873829
"""
874830
This method simulates model according to the simulation options.
875831
usage
@@ -891,11 +847,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
891847
# always define the resultfile to use
892848
om_cmd.arg_set(key="r", val=self.resultfile.as_posix())
893849

894-
# allow runtime simulation flags from user input
895-
if simflags is not None:
896-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
897-
898-
if simargs:
850+
if simargs is not None:
899851
om_cmd.args_set(args=simargs)
900852

901853
overrideFile = self.tempdir / f"{self.modelName}_override.txt"
@@ -1258,15 +1210,16 @@ def optimize(self): # 21
12581210

12591211
return optimizeResult
12601212

1261-
def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = None,
1262-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1263-
timeout: Optional[int] = None) -> LinearizationResult:
1213+
def linearize(
1214+
self,
1215+
lintime: Optional[float] = None,
1216+
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1217+
timeout: Optional[int] = None,
1218+
) -> LinearizationResult:
12641219
"""Linearize the model according to linearOptions.
12651220
12661221
Args:
12671222
lintime: Override linearOptions["stopTime"] value.
1268-
simflags: A string of extra command line flags for the model
1269-
binary. - depreciated in favor of simargs
12701223
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
12711224
timeout: Possible timeout for the execution of OM.
12721225
@@ -1319,11 +1272,7 @@ def load_module_from_path(module_name, file_path):
13191272

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

1322-
# allow runtime simulation flags from user input
1323-
if simflags is not None:
1324-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
1325-
1326-
if simargs:
1275+
if simargs is not None:
13271276
om_cmd.args_set(args=simargs)
13281277

13291278
returncode = om_cmd.run()

tests/test_ModelicaSystemCmd.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ def test_simflags(model_firstorder):
2323
"noRestart": None,
2424
"override": {'b': 2}
2525
})
26-
with pytest.deprecated_call():
27-
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))
2826

2927
assert mscmd.get_cmd() == [
3028
mscmd.get_exe().as_posix(),
31-
'-noEventEmit', '-noRestart',
32-
'-override=b=2,a=1,x=3'
29+
'-noEventEmit',
30+
'-noRestart',
31+
'-override=b=2'
3332
]

0 commit comments

Comments
 (0)