Skip to content

Commit 795ee29

Browse files
committed
[ModelicaSystem] remove old style input for set*() functions
see PR OpenModelica#314 and PR OpenModelica#345
1 parent 171c0f5 commit 795ee29

File tree

1 file changed

+13
-69
lines changed

1 file changed

+13
-69
lines changed

OMPython/ModelicaSystem.py

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,6 @@ def getSolutions(self, varList: Optional[str | list[str]] = None, resultfile: Op
11151115

11161116
@staticmethod
11171117
def _prepare_input_data(
1118-
input_args: Any,
11191118
input_kwargs: dict[str, Any],
11201119
) -> dict[str, str]:
11211120
"""
@@ -1134,28 +1133,6 @@ def prepare_str(str_in: str) -> dict[str, str]:
11341133

11351134
input_data: dict[str, str] = {}
11361135

1137-
for input_arg in input_args:
1138-
if isinstance(input_arg, str):
1139-
warnings.warn(message="The definition of values to set should use a dictionary, "
1140-
"i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
1141-
"use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]",
1142-
category=DeprecationWarning,
1143-
stacklevel=3)
1144-
input_data = input_data | prepare_str(input_arg)
1145-
elif isinstance(input_arg, list):
1146-
warnings.warn(message="The definition of values to set should use a dictionary, "
1147-
"i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
1148-
"use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]",
1149-
category=DeprecationWarning,
1150-
stacklevel=3)
1151-
1152-
for item in input_arg:
1153-
if not isinstance(item, str):
1154-
raise ModelicaSystemError(f"Invalid input data type for set*() function: {type(item)}!")
1155-
input_data = input_data | prepare_str(item)
1156-
else:
1157-
raise ModelicaSystemError(f"Invalid input data type for set*() function: {type(input_arg)}!")
1158-
11591136
if len(input_kwargs):
11601137
for key, val in input_kwargs.items():
11611138
# ensure all values are strings to align it on one type: dict[str, str]
@@ -1229,21 +1206,15 @@ def isParameterChangeable(
12291206

12301207
def setContinuous(
12311208
self,
1232-
*args: Any,
12331209
**kwargs: dict[str, Any],
12341210
) -> bool:
12351211
"""
1236-
This method is used to set continuous values. It can be called:
1237-
with a sequence of continuous name and assigning corresponding values as arguments as show in the example below:
1238-
usage
1239-
>>> setContinuous("Name=value") # depreciated
1240-
>>> setContinuous(["Name1=value1","Name2=value2"]) # depreciated
1241-
1212+
This method is used to set continuous values.
12421213
>>> setContinuous(Name1="value1", Name2="value2")
12431214
>>> param = {"Name1": "value1", "Name2": "value2"}
12441215
>>> setContinuous(**param)
12451216
"""
1246-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1217+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
12471218

12481219
return self._set_method_helper(
12491220
inputdata=inputdata,
@@ -1253,21 +1224,15 @@ def setContinuous(
12531224

12541225
def setParameters(
12551226
self,
1256-
*args: Any,
12571227
**kwargs: dict[str, Any],
12581228
) -> bool:
12591229
"""
1260-
This method is used to set parameter values. It can be called:
1261-
with a sequence of parameter name and assigning corresponding value as arguments as show in the example below:
1262-
usage
1263-
>>> setParameters("Name=value") # depreciated
1264-
>>> setParameters(["Name1=value1","Name2=value2"]) # depreciated
1265-
1230+
This method is used to set parameter values.
12661231
>>> setParameters(Name1="value1", Name2="value2")
12671232
>>> param = {"Name1": "value1", "Name2": "value2"}
12681233
>>> setParameters(**param)
12691234
"""
1270-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1235+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
12711236

12721237
return self._set_method_helper(
12731238
inputdata=inputdata,
@@ -1277,21 +1242,15 @@ def setParameters(
12771242

12781243
def setSimulationOptions(
12791244
self,
1280-
*args: Any,
12811245
**kwargs: dict[str, Any],
12821246
) -> bool:
12831247
"""
1284-
This method is used to set simulation options. It can be called:
1285-
with a sequence of simulation options name and assigning corresponding values as arguments as show in the example below:
1286-
usage
1287-
>>> setSimulationOptions("Name=value") # depreciated
1288-
>>> setSimulationOptions(["Name1=value1","Name2=value2"]) # depreciated
1289-
1248+
This method is used to set simulation options.
12901249
>>> setSimulationOptions(Name1="value1", Name2="value2")
12911250
>>> param = {"Name1": "value1", "Name2": "value2"}
12921251
>>> setSimulationOptions(**param)
12931252
"""
1294-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1253+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
12951254

12961255
return self._set_method_helper(
12971256
inputdata=inputdata,
@@ -1301,21 +1260,15 @@ def setSimulationOptions(
13011260

13021261
def setLinearizationOptions(
13031262
self,
1304-
*args: Any,
13051263
**kwargs: dict[str, Any],
13061264
) -> bool:
13071265
"""
1308-
This method is used to set linearization options. It can be called:
1309-
with a sequence of linearization options name and assigning corresponding value as arguments as show in the example below
1310-
usage
1311-
>>> setLinearizationOptions("Name=value") # depreciated
1312-
>>> setLinearizationOptions(["Name1=value1","Name2=value2"]) # depreciated
1313-
1266+
This method is used to set linearization options.
13141267
>>> setLinearizationOptions(Name1="value1", Name2="value2")
13151268
>>> param = {"Name1": "value1", "Name2": "value2"}
13161269
>>> setLinearizationOptions(**param)
13171270
"""
1318-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1271+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
13191272

13201273
return self._set_method_helper(
13211274
inputdata=inputdata,
@@ -1325,21 +1278,17 @@ def setLinearizationOptions(
13251278

13261279
def setOptimizationOptions(
13271280
self,
1328-
*args: Any,
13291281
**kwargs: dict[str, Any],
13301282
) -> bool:
13311283
"""
13321284
This method is used to set optimization options. It can be called:
13331285
with a sequence of optimization options name and assigning corresponding values as arguments as show in the example below:
13341286
usage
1335-
>>> setOptimizationOptions("Name=value") # depreciated
1336-
>>> setOptimizationOptions(["Name1=value1","Name2=value2"]) # depreciated
1337-
13381287
>>> setOptimizationOptions(Name1="value1", Name2="value2")
13391288
>>> param = {"Name1": "value1", "Name2": "value2"}
13401289
>>> setOptimizationOptions(**param)
13411290
"""
1342-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1291+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
13431292

13441293
return self._set_method_helper(
13451294
inputdata=inputdata,
@@ -1349,23 +1298,18 @@ def setOptimizationOptions(
13491298

13501299
def setInputs(
13511300
self,
1352-
*args: Any,
13531301
**kwargs: dict[str, Any],
13541302
) -> bool:
13551303
"""
1356-
This method is used to set input values. It can be called with a sequence of input name and assigning
1357-
corresponding values as arguments as show in the example below. Compared to other set*() methods this is a
1358-
special case as value could be a list of tuples - these are converted to a string in _prepare_input_data()
1359-
and restored here via ast.literal_eval().
1360-
1361-
>>> setInputs("Name=value") # depreciated
1362-
>>> setInputs(["Name1=value1","Name2=value2"]) # depreciated
1304+
This method is used to set input values.
13631305
1306+
Compared to other set*() methods this is a special case as value could be a list of tuples - these are
1307+
converted to a string in _prepare_input_data() and restored here via ast.literal_eval().
13641308
>>> setInputs(Name1="value1", Name2="value2")
13651309
>>> param = {"Name1": "value1", "Name2": "value2"}
13661310
>>> setInputs(**param)
13671311
"""
1368-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1312+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
13691313

13701314
for key, val in inputdata.items():
13711315
if key not in self._inputs:

0 commit comments

Comments
 (0)