46
46
import subprocess
47
47
import tempfile
48
48
import textwrap
49
- from typing import Optional , Any
50
- import warnings
49
+ from typing import Any , Optional
51
50
import xml .etree .ElementTree as ET
52
51
53
52
from OMPython .OMCSession import OMCSessionException , OMCSessionZMQ , OMCProcessLocal
@@ -255,45 +254,6 @@ def run(self) -> int:
255
254
256
255
return returncode
257
256
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
-
296
-
297
257
class ModelicaSystem :
298
258
def __init__ (
299
259
self ,
@@ -917,7 +877,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
917
877
def simulate_cmd (
918
878
self ,
919
879
result_file : pathlib .Path ,
920
- simflags : Optional [str ] = None ,
921
880
simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
922
881
timeout : Optional [float ] = None ,
923
882
) -> ModelicaSystemCmd :
@@ -931,13 +890,6 @@ def simulate_cmd(
931
890
However, if only non-structural parameters are used, it is possible to reuse an existing instance of
932
891
ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.
933
892
934
- Parameters
935
- ----------
936
- result_file
937
- simflags
938
- simargs
939
- timeout
940
-
941
893
Returns
942
894
-------
943
895
An instance if ModelicaSystemCmd to run the requested simulation.
@@ -948,11 +900,7 @@ def simulate_cmd(
948
900
# always define the result file to use
949
901
om_cmd .arg_set (key = "r" , val = result_file .as_posix ())
950
902
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 :
956
904
om_cmd .args_set (args = simargs )
957
905
958
906
overrideFile = self ._tempdir / f"{ self ._model_name } _override.txt"
@@ -990,7 +938,6 @@ def simulate_cmd(
990
938
def simulate (
991
939
self ,
992
940
resultfile : Optional [str ] = None ,
993
- simflags : Optional [str ] = None ,
994
941
simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
995
942
timeout : Optional [float ] = None ,
996
943
) -> None :
@@ -1000,8 +947,6 @@ def simulate(
1000
947
1001
948
Args:
1002
949
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.
1005
950
simargs: Dict with simulation runtime flags.
1006
951
timeout: Maximum execution time in seconds.
1007
952
@@ -1022,7 +967,6 @@ def simulate(
1022
967
1023
968
om_cmd = self .simulate_cmd (
1024
969
result_file = self ._result_file ,
1025
- simflags = simflags ,
1026
970
simargs = simargs ,
1027
971
timeout = timeout ,
1028
972
)
@@ -1516,17 +1460,18 @@ def optimize(self) -> dict[str, Any]:
1516
1460
1517
1461
return optimizeResult
1518
1462
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 :
1463
+ def linearize (
1464
+ self ,
1465
+ lintime : Optional [float ] = None ,
1466
+ simargs : Optional [dict [str , Optional [str | dict [str , str ]]]] = None ,
1467
+ timeout : Optional [int ] = None ,
1468
+ ) -> LinearizationResult :
1522
1469
"""Linearize the model according to linearization options.
1523
1470
1524
1471
See setLinearizationOptions.
1525
1472
1526
1473
Args:
1527
1474
lintime: Override "stopTime" value.
1528
- simflags: String of extra command line flags for the model binary.
1529
- This argument is deprecated, use simargs instead.
1530
1475
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
1531
1476
timeout: Maximum execution time in seconds.
1532
1477
@@ -1579,11 +1524,7 @@ def load_module_from_path(module_name, file_path):
1579
1524
1580
1525
om_cmd .arg_set (key = "l" , val = str (lintime or self ._linearization_options ["stopTime" ]))
1581
1526
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 :
1527
+ if simargs is not None :
1587
1528
om_cmd .args_set (args = simargs )
1588
1529
1589
1530
returncode = om_cmd .run ()
0 commit comments