4646import subprocess
4747import tempfile
4848import textwrap
49- from typing import Optional , Any
50- import warnings
49+ from typing import Any , Optional
5150import xml .etree .ElementTree as ET
5251
5352from OMPython .OMCSession import OMCSessionException , OMCSessionZMQ , OMCProcessLocal
@@ -255,44 +254,6 @@ def run(self) -> int:
255254
256255 return returncode
257256
258- @staticmethod
259- def parse_simflags (simflags : str ) -> dict [str , Optional [str | dict [str , str ]]]:
260- """
261- Parse a simflag definition; this is deprecated!
262-
263- The return data can be used as input for self.args_set().
264- """
265- warnings .warn ("The argument 'simflags' is depreciated and will be removed in future versions; "
266- "please use 'simargs' instead" , DeprecationWarning , stacklevel = 2 )
267-
268- simargs : dict [str , Optional [str | dict [str , str ]]] = {}
269-
270- args = [s for s in simflags .split (' ' ) if s ]
271- for arg in args :
272- if arg [0 ] != '-' :
273- raise ModelicaSystemError (f"Invalid simulation flag: { arg } " )
274- arg = arg [1 :]
275- parts = arg .split ('=' )
276- if len (parts ) == 1 :
277- simargs [parts [0 ]] = None
278- elif parts [0 ] == 'override' :
279- override = '=' .join (parts [1 :])
280-
281- override_dict = {}
282- for item in override .split (',' ):
283- kv = item .split ('=' )
284- if not 0 < len (kv ) < 3 :
285- raise ModelicaSystemError (f"Invalid value for '-override': { override } " )
286- if kv [0 ]:
287- try :
288- override_dict [kv [0 ]] = kv [1 ]
289- except (KeyError , IndexError ) as ex :
290- raise ModelicaSystemError (f"Invalid value for '-override': { override } " ) from ex
291-
292- simargs [parts [0 ]] = override_dict
293-
294- return simargs
295-
296257
297258class ModelicaSystem :
298259 def __init__ (
@@ -917,7 +878,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
917878 def simulate_cmd (
918879 self ,
919880 result_file : pathlib .Path ,
920- simflags : Optional [str ] = None ,
921881 simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
922882 timeout : Optional [float ] = None ,
923883 ) -> ModelicaSystemCmd :
@@ -931,13 +891,6 @@ def simulate_cmd(
931891 However, if only non-structural parameters are used, it is possible to reuse an existing instance of
932892 ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.
933893
934- Parameters
935- ----------
936- result_file
937- simflags
938- simargs
939- timeout
940-
941894 Returns
942895 -------
943896 An instance if ModelicaSystemCmd to run the requested simulation.
@@ -948,11 +901,7 @@ def simulate_cmd(
948901 # always define the result file to use
949902 om_cmd .arg_set (key = "r" , val = result_file .as_posix ())
950903
951- # allow runtime simulation flags from user input
952- if simflags is not None :
953- om_cmd .args_set (args = om_cmd .parse_simflags (simflags = simflags ))
954-
955- if simargs :
904+ if simargs is not None :
956905 om_cmd .args_set (args = simargs )
957906
958907 overrideFile = self ._tempdir / f"{ self ._model_name } _override.txt"
@@ -990,7 +939,6 @@ def simulate_cmd(
990939 def simulate (
991940 self ,
992941 resultfile : Optional [str ] = None ,
993- simflags : Optional [str ] = None ,
994942 simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
995943 timeout : Optional [float ] = None ,
996944 ) -> None :
@@ -1000,8 +948,6 @@ def simulate(
1000948
1001949 Args:
1002950 resultfile: Path to a custom result file
1003- simflags: String of extra command line flags for the model binary.
1004- This argument is deprecated, use simargs instead.
1005951 simargs: Dict with simulation runtime flags.
1006952 timeout: Maximum execution time in seconds.
1007953
@@ -1022,7 +968,6 @@ def simulate(
1022968
1023969 om_cmd = self .simulate_cmd (
1024970 result_file = self ._result_file ,
1025- simflags = simflags ,
1026971 simargs = simargs ,
1027972 timeout = timeout ,
1028973 )
@@ -1516,17 +1461,18 @@ def optimize(self) -> dict[str, Any]:
15161461
15171462 return optimizeResult
15181463
1519- def linearize (self , lintime : Optional [float ] = None , simflags : Optional [str ] = None ,
1520- simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1521- timeout : Optional [float ] = None ) -> LinearizationResult :
1464+ def linearize (
1465+ self ,
1466+ lintime : Optional [float ] = None ,
1467+ simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1468+ timeout : Optional [int ] = None ,
1469+ ) -> LinearizationResult :
15221470 """Linearize the model according to linearization options.
15231471
15241472 See setLinearizationOptions.
15251473
15261474 Args:
15271475 lintime: Override "stopTime" value.
1528- simflags: String of extra command line flags for the model binary.
1529- This argument is deprecated, use simargs instead.
15301476 simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
15311477 timeout: Maximum execution time in seconds.
15321478
@@ -1579,11 +1525,7 @@ def load_module_from_path(module_name, file_path):
15791525
15801526 om_cmd .arg_set (key = "l" , val = str (lintime or self ._linearization_options ["stopTime" ]))
15811527
1582- # allow runtime simulation flags from user input
1583- if simflags is not None :
1584- om_cmd .args_set (args = om_cmd .parse_simflags (simflags = simflags ))
1585-
1586- if simargs :
1528+ if simargs is not None :
15871529 om_cmd .args_set (args = simargs )
15881530
15891531 returncode = om_cmd .run ()
0 commit comments