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
@@ -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
316269class ModelicaSystem :
317270 def __init__ (
@@ -858,9 +811,12 @@ def getOptimizationOptions(self, names=None): # 10
858811
859812 raise ModelicaSystemError ("Unhandled input for getOptimizationOptions()" )
860813
861- def simulate (self , resultfile : Optional [str ] = None , simflags : Optional [str ] = None ,
862- simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
863- timeout : Optional [int ] = None ): # 11
814+ def simulate (
815+ self ,
816+ resultfile : Optional [str ] = None ,
817+ simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
818+ timeout : Optional [int ] = None
819+ ): # 11
864820 """
865821 This method simulates model according to the simulation options.
866822 usage
@@ -882,11 +838,7 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
882838 # always define the resultfile to use
883839 om_cmd .arg_set (key = "r" , val = self .resultfile .as_posix ())
884840
885- # allow runtime simulation flags from user input
886- if simflags is not None :
887- om_cmd .args_set (args = om_cmd .parse_simflags (simflags = simflags ))
888-
889- if simargs :
841+ if simargs is not None :
890842 om_cmd .args_set (args = simargs )
891843
892844 overrideFile = self .tempdir / f"{ self .modelName } _override.txt"
@@ -1242,15 +1194,16 @@ def optimize(self): # 21
12421194
12431195 return optimizeResult
12441196
1245- def linearize (self , lintime : Optional [float ] = None , simflags : Optional [str ] = None ,
1246- simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1247- timeout : Optional [int ] = None ) -> LinearizationResult :
1197+ def linearize (
1198+ self ,
1199+ lintime : Optional [float ] = None ,
1200+ simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1201+ timeout : Optional [int ] = None ,
1202+ ) -> LinearizationResult :
12481203 """Linearize the model according to linearOptions.
12491204
12501205 Args:
12511206 lintime: Override linearOptions["stopTime"] value.
1252- simflags: A string of extra command line flags for the model
1253- binary. - depreciated in favor of simargs
12541207 simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
12551208 timeout: Possible timeout for the execution of OM.
12561209
@@ -1303,11 +1256,7 @@ def load_module_from_path(module_name, file_path):
13031256
13041257 om_cmd .arg_set (key = "l" , val = str (lintime or self .linearOptions ["stopTime" ]))
13051258
1306- # allow runtime simulation flags from user input
1307- if simflags is not None :
1308- om_cmd .args_set (args = om_cmd .parse_simflags (simflags = simflags ))
1309-
1310- if simargs :
1259+ if simargs is not None :
13111260 om_cmd .args_set (args = simargs )
13121261
13131262 returncode = om_cmd .run ()
0 commit comments