Skip to content
Prev Previous commit
Next Next commit
[ModelicaSystem] define _linearization_options and _optimization_opti…
…ons as dict[str, str]

* after OMC is run, the values will be string anyway
* simplify code / align on one common definition for these dicts
  • Loading branch information
syntron committed Dec 29, 2025
commit cd3a9b9a3aa90fb870cf7b26b00a7255a303b2db
32 changes: 15 additions & 17 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ def __init__(
self._simulate_options: dict[str, str] = {}
self._override_variables: dict[str, str] = {}
self._simulate_options_override: dict[str, str] = {}
self._linearization_options: dict[str, str | float] = {
'startTime': 0.0,
'stopTime': 1.0,
'stepSize': 0.002,
'tolerance': 1e-8,
self._linearization_options: dict[str, str] = {
'startTime': str(0.0),
'stopTime': str(1.0),
'stepSize': str(0.002),
'tolerance': str(1e-8),
}
self._optimization_options = self._linearization_options | {
'numberOfIntervals': 500,
'numberOfIntervals': str(500),
}
self._linearized_inputs: list[str] = [] # linearization input list
self._linearized_outputs: list[str] = [] # linearization output list
Expand Down Expand Up @@ -950,7 +950,7 @@ def getSimulationOptions(
def getLinearizationOptions(
self,
names: Optional[str | list[str]] = None,
) -> dict[str, str | float] | list[str | float]:
) -> dict[str, str] | list[str]:
"""Get simulation options used for linearization.

Args:
Expand All @@ -964,17 +964,16 @@ def getLinearizationOptions(
returned.
If `names` is a list, a list with one value for each option name
in names is returned: [option1_value, option2_value, ...].
Some option values are returned as float when first initialized,
but always as strings after setLinearizationOptions is used to
change them.

The option values are always returned as strings.

Examples:
>>> mod.getLinearizationOptions()
{'startTime': 0.0, 'stopTime': 1.0, 'stepSize': 0.002, 'tolerance': 1e-08}
{'startTime': '0.0', 'stopTime': '1.0', 'stepSize': '0.002', 'tolerance': '1e-08'}
>>> mod.getLinearizationOptions("stopTime")
[1.0]
['1.0']
>>> mod.getLinearizationOptions(["tolerance", "stopTime"])
[1e-08, 1.0]
['1e-08', '1.0']
"""
if names is None:
return self._linearization_options
Expand All @@ -988,7 +987,7 @@ def getLinearizationOptions(
def getOptimizationOptions(
self,
names: Optional[str | list[str]] = None,
) -> dict[str, str | float] | list[str | float]:
) -> dict[str, str] | list[str]:
"""Get simulation options used for optimization.

Args:
Expand All @@ -1002,9 +1001,8 @@ def getOptimizationOptions(
returned.
If `names` is a list, a list with one value for each option name
in names is returned: [option1_value, option2_value, ...].
Some option values are returned as float when first initialized,
but always as strings after setOptimizationOptions is used to
change them.

The option values are always returned as string.

Examples:
>>> mod.getOptimizationOptions()
Expand Down