4545import subprocess
4646import tempfile
4747import textwrap
48- from typing import Optional , Any
49- import warnings
48+ from typing import Any , Optional
5049import xml .etree .ElementTree as ET
5150
5251from 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
296257class ModelicaSystem :
297258 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"
@@ -992,7 +941,6 @@ def simulate_cmd(
992941 def simulate (
993942 self ,
994943 resultfile : Optional [str ] = None ,
995- simflags : Optional [str ] = None ,
996944 simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
997945 timeout : Optional [float ] = None ,
998946 ) -> None :
@@ -1002,8 +950,6 @@ def simulate(
1002950
1003951 Args:
1004952 resultfile: Path to a custom result file
1005- simflags: String of extra command line flags for the model binary.
1006- This argument is deprecated, use simargs instead.
1007953 simargs: Dict with simulation runtime flags.
1008954 timeout: Maximum execution time in seconds.
1009955
@@ -1024,7 +970,6 @@ def simulate(
1024970
1025971 om_cmd = self .simulate_cmd (
1026972 result_file = self ._result_file ,
1027- simflags = simflags ,
1028973 simargs = simargs ,
1029974 timeout = timeout ,
1030975 )
@@ -1414,17 +1359,18 @@ def optimize(self) -> dict[str, Any]:
14141359
14151360 return optimizeResult
14161361
1417- def linearize (self , lintime : Optional [float ] = None , simflags : Optional [str ] = None ,
1418- simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1419- timeout : Optional [float ] = None ) -> LinearizationResult :
1362+ def linearize (
1363+ self ,
1364+ lintime : Optional [float ] = None ,
1365+ simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1366+ timeout : Optional [int ] = None ,
1367+ ) -> LinearizationResult :
14201368 """Linearize the model according to linearization options.
14211369
14221370 See setLinearizationOptions.
14231371
14241372 Args:
14251373 lintime: Override "stopTime" value.
1426- simflags: String of extra command line flags for the model binary.
1427- This argument is deprecated, use simargs instead.
14281374 simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
14291375 timeout: Maximum execution time in seconds.
14301376
@@ -1477,11 +1423,7 @@ def load_module_from_path(module_name, file_path):
14771423
14781424 om_cmd .arg_set (key = "l" , val = str (lintime or self ._linearization_options ["stopTime" ]))
14791425
1480- # allow runtime simulation flags from user input
1481- if simflags is not None :
1482- om_cmd .args_set (args = om_cmd .parse_simflags (simflags = simflags ))
1483-
1484- if simargs :
1426+ if simargs is not None :
14851427 om_cmd .args_set (args = simargs )
14861428
14871429 returncode = om_cmd .run ()
0 commit comments