Skip to content

Commit 29f7eab

Browse files
committed
[ModelicaSystemCmd] remove depreciated simflags
1 parent d7b5bca commit 29f7eab

1 file changed

Lines changed: 14 additions & 65 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import tempfile
4747
import textwrap
4848
from typing import Optional
49-
import warnings
5049
import xml.etree.ElementTree as ET
5150

5251
from OMPython.OMCSession import OMCSessionException, OMCSessionZMQ
@@ -266,52 +265,6 @@ def run(self) -> int:
266265

267266
return returncode
268267

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

316269
class ModelicaSystem:
317270
def __init__(
@@ -855,9 +808,12 @@ def getOptimizationOptions(self, names=None): # 10
855808

856809
raise ModelicaSystemError("Unhandled input for getOptimizationOptions()")
857810

858-
def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = None,
859-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
860-
timeout: Optional[int] = None): # 11
811+
def simulate(
812+
self,
813+
resultfile: Optional[str] = None,
814+
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
815+
timeout: Optional[int] = None
816+
): # 11
861817
"""
862818
This method simulates model according to the simulation options.
863819
usage
@@ -879,11 +835,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
879835
# always define the resultfile to use
880836
om_cmd.arg_set(key="r", val=self.resultfile.as_posix())
881837

882-
# allow runtime simulation flags from user input
883-
if simflags is not None:
884-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
885-
886-
if simargs:
838+
if simargs is not None:
887839
om_cmd.args_set(args=simargs)
888840

889841
overrideFile = self.tempdir / f"{self.modelName}_override.txt"
@@ -1239,15 +1191,16 @@ def optimize(self): # 21
12391191

12401192
return optimizeResult
12411193

1242-
def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = None,
1243-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1244-
timeout: Optional[int] = None) -> LinearizationResult:
1194+
def linearize(
1195+
self,
1196+
lintime: Optional[float] = None,
1197+
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1198+
timeout: Optional[int] = None,
1199+
) -> LinearizationResult:
12451200
"""Linearize the model according to linearOptions.
12461201
12471202
Args:
12481203
lintime: Override linearOptions["stopTime"] value.
1249-
simflags: A string of extra command line flags for the model
1250-
binary. - depreciated in favor of simargs
12511204
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
12521205
timeout: Possible timeout for the execution of OM.
12531206
@@ -1300,11 +1253,7 @@ def load_module_from_path(module_name, file_path):
13001253

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

1303-
# allow runtime simulation flags from user input
1304-
if simflags is not None:
1305-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
1306-
1307-
if simargs:
1256+
if simargs is not None:
13081257
om_cmd.args_set(args=simargs)
13091258

13101259
returncode = om_cmd.run()

0 commit comments

Comments
 (0)