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,45 +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-
295-
296256class ModelicaSystem :
297257 def __init__ (
298258 self ,
@@ -917,7 +877,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
917877 def simulate_cmd (
918878 self ,
919879 result_file : pathlib .Path ,
920- simflags : Optional [str ] = None ,
921880 simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
922881 timeout : Optional [float ] = None ,
923882 ) -> ModelicaSystemCmd :
@@ -931,13 +890,6 @@ def simulate_cmd(
931890 However, if only non-structural parameters are used, it is possible to reuse an existing instance of
932891 ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.
933892
934- Parameters
935- ----------
936- result_file
937- simflags
938- simargs
939- timeout
940-
941893 Returns
942894 -------
943895 An instance if ModelicaSystemCmd to run the requested simulation.
@@ -948,11 +900,7 @@ def simulate_cmd(
948900 # always define the result file to use
949901 om_cmd .arg_set (key = "r" , val = result_file .as_posix ())
950902
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 :
903+ if simargs is not None :
956904 om_cmd .args_set (args = simargs )
957905
958906 overrideFile = self ._tempdir / f"{ self ._model_name } _override.txt"
@@ -992,7 +940,6 @@ def simulate_cmd(
992940 def simulate (
993941 self ,
994942 resultfile : Optional [str ] = None ,
995- simflags : Optional [str ] = None ,
996943 simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
997944 timeout : Optional [float ] = None ,
998945 ) -> None :
@@ -1002,8 +949,6 @@ def simulate(
1002949
1003950 Args:
1004951 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.
1007952 simargs: Dict with simulation runtime flags.
1008953 timeout: Maximum execution time in seconds.
1009954
@@ -1024,7 +969,6 @@ def simulate(
1024969
1025970 om_cmd = self .simulate_cmd (
1026971 result_file = self ._result_file ,
1027- simflags = simflags ,
1028972 simargs = simargs ,
1029973 timeout = timeout ,
1030974 )
@@ -1414,17 +1358,18 @@ def optimize(self) -> dict[str, Any]:
14141358
14151359 return optimizeResult
14161360
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 :
1361+ def linearize (
1362+ self ,
1363+ lintime : Optional [float ] = None ,
1364+ simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1365+ timeout : Optional [int ] = None ,
1366+ ) -> LinearizationResult :
14201367 """Linearize the model according to linearization options.
14211368
14221369 See setLinearizationOptions.
14231370
14241371 Args:
14251372 lintime: Override "stopTime" value.
1426- simflags: String of extra command line flags for the model binary.
1427- This argument is deprecated, use simargs instead.
14281373 simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
14291374 timeout: Maximum execution time in seconds.
14301375
@@ -1477,11 +1422,7 @@ def load_module_from_path(module_name, file_path):
14771422
14781423 om_cmd .arg_set (key = "l" , val = str (lintime or self ._linearization_options ["stopTime" ]))
14791424
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 :
1425+ if simargs is not None :
14851426 om_cmd .args_set (args = simargs )
14861427
14871428 returncode = om_cmd .run ()
0 commit comments