Skip to content

Commit cd3a9b9

Browse files
committed
[ModelicaSystem] define _linearization_options and _optimization_options as dict[str, str]
* after OMC is run, the values will be string anyway * simplify code / align on one common definition for these dicts
1 parent 1f3ec87 commit cd3a9b9

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,14 @@ def __init__(
331331
self._simulate_options: dict[str, str] = {}
332332
self._override_variables: dict[str, str] = {}
333333
self._simulate_options_override: dict[str, str] = {}
334-
self._linearization_options: dict[str, str | float] = {
335-
'startTime': 0.0,
336-
'stopTime': 1.0,
337-
'stepSize': 0.002,
338-
'tolerance': 1e-8,
334+
self._linearization_options: dict[str, str] = {
335+
'startTime': str(0.0),
336+
'stopTime': str(1.0),
337+
'stepSize': str(0.002),
338+
'tolerance': str(1e-8),
339339
}
340340
self._optimization_options = self._linearization_options | {
341-
'numberOfIntervals': 500,
341+
'numberOfIntervals': str(500),
342342
}
343343
self._linearized_inputs: list[str] = [] # linearization input list
344344
self._linearized_outputs: list[str] = [] # linearization output list
@@ -950,7 +950,7 @@ def getSimulationOptions(
950950
def getLinearizationOptions(
951951
self,
952952
names: Optional[str | list[str]] = None,
953-
) -> dict[str, str | float] | list[str | float]:
953+
) -> dict[str, str] | list[str]:
954954
"""Get simulation options used for linearization.
955955
956956
Args:
@@ -964,17 +964,16 @@ def getLinearizationOptions(
964964
returned.
965965
If `names` is a list, a list with one value for each option name
966966
in names is returned: [option1_value, option2_value, ...].
967-
Some option values are returned as float when first initialized,
968-
but always as strings after setLinearizationOptions is used to
969-
change them.
967+
968+
The option values are always returned as strings.
970969
971970
Examples:
972971
>>> mod.getLinearizationOptions()
973-
{'startTime': 0.0, 'stopTime': 1.0, 'stepSize': 0.002, 'tolerance': 1e-08}
972+
{'startTime': '0.0', 'stopTime': '1.0', 'stepSize': '0.002', 'tolerance': '1e-08'}
974973
>>> mod.getLinearizationOptions("stopTime")
975-
[1.0]
974+
['1.0']
976975
>>> mod.getLinearizationOptions(["tolerance", "stopTime"])
977-
[1e-08, 1.0]
976+
['1e-08', '1.0']
978977
"""
979978
if names is None:
980979
return self._linearization_options
@@ -988,7 +987,7 @@ def getLinearizationOptions(
988987
def getOptimizationOptions(
989988
self,
990989
names: Optional[str | list[str]] = None,
991-
) -> dict[str, str | float] | list[str | float]:
990+
) -> dict[str, str] | list[str]:
992991
"""Get simulation options used for optimization.
993992
994993
Args:
@@ -1002,9 +1001,8 @@ def getOptimizationOptions(
10021001
returned.
10031002
If `names` is a list, a list with one value for each option name
10041003
in names is returned: [option1_value, option2_value, ...].
1005-
Some option values are returned as float when first initialized,
1006-
but always as strings after setOptimizationOptions is used to
1007-
change them.
1004+
1005+
The option values are always returned as string.
10081006
10091007
Examples:
10101008
>>> mod.getOptimizationOptions()

0 commit comments

Comments
 (0)