Skip to content

Commit 43d1449

Browse files
committed
[ModelicaSystem] remove old style input for set*() functions
see PR #314 and PR #345
1 parent 36c93c4 commit 43d1449

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
@@ -1203,7 +1203,6 @@ def getSolutions(self, varList: Optional[str | list[str]] = None, resultfile: Op
12031203

12041204
@staticmethod
12051205
def _prepare_input_data(
1206-
input_args: Any,
12071206
input_kwargs: dict[str, Any],
12081207
) -> dict[str, str]:
12091208
"""
@@ -1222,28 +1221,6 @@ def prepare_str(str_in: str) -> dict[str, str]:
12221221

12231222
input_data: dict[str, str] = {}
12241223

1225-
for input_arg in input_args:
1226-
if isinstance(input_arg, str):
1227-
warnings.warn(message="The definition of values to set should use a dictionary, "
1228-
"i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
1229-
"use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]",
1230-
category=DeprecationWarning,
1231-
stacklevel=3)
1232-
input_data = input_data | prepare_str(input_arg)
1233-
elif isinstance(input_arg, list):
1234-
warnings.warn(message="The definition of values to set should use a dictionary, "
1235-
"i.e. {'key1': 'val1', 'key2': 'val2', ...}. Please convert all cases which "
1236-
"use a string ('key=val') or list ['key1=val1', 'key2=val2', ...]",
1237-
category=DeprecationWarning,
1238-
stacklevel=3)
1239-
1240-
for item in input_arg:
1241-
if not isinstance(item, str):
1242-
raise ModelicaSystemError(f"Invalid input data type for set*() function: {type(item)}!")
1243-
input_data = input_data | prepare_str(item)
1244-
else:
1245-
raise ModelicaSystemError(f"Invalid input data type for set*() function: {type(input_arg)}!")
1246-
12471224
if len(input_kwargs):
12481225
for key, val in input_kwargs.items():
12491226
# ensure all values are strings to align it on one type: dict[str, str]
@@ -1317,21 +1294,15 @@ def isParameterChangeable(
13171294

13181295
def setContinuous(
13191296
self,
1320-
*args: Any,
13211297
**kwargs: dict[str, Any],
13221298
) -> bool:
13231299
"""
1324-
This method is used to set continuous values. It can be called:
1325-
with a sequence of continuous name and assigning corresponding values as arguments as show in the example below:
1326-
usage
1327-
>>> setContinuous("Name=value") # depreciated
1328-
>>> setContinuous(["Name1=value1","Name2=value2"]) # depreciated
1329-
1300+
This method is used to set continuous values.
13301301
>>> setContinuous(Name1="value1", Name2="value2")
13311302
>>> param = {"Name1": "value1", "Name2": "value2"}
13321303
>>> setContinuous(**param)
13331304
"""
1334-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1305+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
13351306

13361307
return self._set_method_helper(
13371308
inputdata=inputdata,
@@ -1341,21 +1312,15 @@ def setContinuous(
13411312

13421313
def setParameters(
13431314
self,
1344-
*args: Any,
13451315
**kwargs: dict[str, Any],
13461316
) -> bool:
13471317
"""
1348-
This method is used to set parameter values. It can be called:
1349-
with a sequence of parameter name and assigning corresponding value as arguments as show in the example below:
1350-
usage
1351-
>>> setParameters("Name=value") # depreciated
1352-
>>> setParameters(["Name1=value1","Name2=value2"]) # depreciated
1353-
1318+
This method is used to set parameter values.
13541319
>>> setParameters(Name1="value1", Name2="value2")
13551320
>>> param = {"Name1": "value1", "Name2": "value2"}
13561321
>>> setParameters(**param)
13571322
"""
1358-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1323+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
13591324

13601325
return self._set_method_helper(
13611326
inputdata=inputdata,
@@ -1365,21 +1330,15 @@ def setParameters(
13651330

13661331
def setSimulationOptions(
13671332
self,
1368-
*args: Any,
13691333
**kwargs: dict[str, Any],
13701334
) -> bool:
13711335
"""
1372-
This method is used to set simulation options. It can be called:
1373-
with a sequence of simulation options name and assigning corresponding values as arguments as show in the example below:
1374-
usage
1375-
>>> setSimulationOptions("Name=value") # depreciated
1376-
>>> setSimulationOptions(["Name1=value1","Name2=value2"]) # depreciated
1377-
1336+
This method is used to set simulation options.
13781337
>>> setSimulationOptions(Name1="value1", Name2="value2")
13791338
>>> param = {"Name1": "value1", "Name2": "value2"}
13801339
>>> setSimulationOptions(**param)
13811340
"""
1382-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1341+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
13831342

13841343
return self._set_method_helper(
13851344
inputdata=inputdata,
@@ -1389,21 +1348,15 @@ def setSimulationOptions(
13891348

13901349
def setLinearizationOptions(
13911350
self,
1392-
*args: Any,
13931351
**kwargs: dict[str, Any],
13941352
) -> bool:
13951353
"""
1396-
This method is used to set linearization options. It can be called:
1397-
with a sequence of linearization options name and assigning corresponding value as arguments as show in the example below
1398-
usage
1399-
>>> setLinearizationOptions("Name=value") # depreciated
1400-
>>> setLinearizationOptions(["Name1=value1","Name2=value2"]) # depreciated
1401-
1354+
This method is used to set linearization options.
14021355
>>> setLinearizationOptions(Name1="value1", Name2="value2")
14031356
>>> param = {"Name1": "value1", "Name2": "value2"}
14041357
>>> setLinearizationOptions(**param)
14051358
"""
1406-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1359+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
14071360

14081361
return self._set_method_helper(
14091362
inputdata=inputdata,
@@ -1413,21 +1366,17 @@ def setLinearizationOptions(
14131366

14141367
def setOptimizationOptions(
14151368
self,
1416-
*args: Any,
14171369
**kwargs: dict[str, Any],
14181370
) -> bool:
14191371
"""
14201372
This method is used to set optimization options. It can be called:
14211373
with a sequence of optimization options name and assigning corresponding values as arguments as show in the example below:
14221374
usage
1423-
>>> setOptimizationOptions("Name=value") # depreciated
1424-
>>> setOptimizationOptions(["Name1=value1","Name2=value2"]) # depreciated
1425-
14261375
>>> setOptimizationOptions(Name1="value1", Name2="value2")
14271376
>>> param = {"Name1": "value1", "Name2": "value2"}
14281377
>>> setOptimizationOptions(**param)
14291378
"""
1430-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1379+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
14311380

14321381
return self._set_method_helper(
14331382
inputdata=inputdata,
@@ -1437,23 +1386,18 @@ def setOptimizationOptions(
14371386

14381387
def setInputs(
14391388
self,
1440-
*args: Any,
14411389
**kwargs: dict[str, Any],
14421390
) -> bool:
14431391
"""
1444-
This method is used to set input values. It can be called with a sequence of input name and assigning
1445-
corresponding values as arguments as show in the example below. Compared to other set*() methods this is a
1446-
special case as value could be a list of tuples - these are converted to a string in _prepare_input_data()
1447-
and restored here via ast.literal_eval().
1448-
1449-
>>> setInputs("Name=value") # depreciated
1450-
>>> setInputs(["Name1=value1","Name2=value2"]) # depreciated
1392+
This method is used to set input values.
14511393
1394+
Compared to other set*() methods this is a special case as value could be a list of tuples - these are
1395+
converted to a string in _prepare_input_data() and restored here via ast.literal_eval().
14521396
>>> setInputs(Name1="value1", Name2="value2")
14531397
>>> param = {"Name1": "value1", "Name2": "value2"}
14541398
>>> setInputs(**param)
14551399
"""
1456-
inputdata = self._prepare_input_data(input_args=args, input_kwargs=kwargs)
1400+
inputdata = self._prepare_input_data(input_kwargs=kwargs)
14571401

14581402
for key, val in inputdata.items():
14591403
if key not in self._inputs:

0 commit comments

Comments
 (0)