Skip to content

Commit 7db5e97

Browse files
committed
[ModelicaSystem] more type hints fixes / cleanups
1 parent 6eaf3ee commit 7db5e97

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def __init__(
377377

378378
self._quantities: list[dict[str, Any]] = []
379379
self._params: dict[str, str] = {} # even numerical values are stored as str
380-
self._inputs: dict[str, list | None] = {}
380+
self._inputs: dict[str, list[tuple[float, float]]] = {}
381381
# _outputs values are str before simulate(), but they can be
382382
# np.float64 after simulate().
383383
self._outputs: dict[str, Any] = {}
@@ -386,8 +386,15 @@ def __init__(
386386
self._simulate_options: dict[str, str] = {}
387387
self._override_variables: dict[str, str] = {}
388388
self._simulate_options_override: dict[str, str] = {}
389-
self._linearization_options = {'startTime': 0.0, 'stopTime': 1.0, 'stepSize': 0.002, 'tolerance': 1e-8}
390-
self._optimization_options = self._linearization_options | {'numberOfIntervals': 500}
389+
self._linearization_options: dict[str, str | float] = {
390+
'startTime': 0.0,
391+
'stopTime': 1.0,
392+
'stepSize': 0.002,
393+
'tolerance': 1e-8,
394+
}
395+
self._optimization_options = self._linearization_options | {
396+
'numberOfIntervals': 500,
397+
}
391398
self._linearized_inputs: list[str] = [] # linearization input list
392399
self._linearized_outputs: list[str] = [] # linearization output list
393400
self._linearized_states: list[str] = [] # linearization states list
@@ -797,7 +804,7 @@ def getParameters(
797804
def getInputs(
798805
self,
799806
names: Optional[str | list[str]] = None,
800-
) -> dict[str, list[tuple[numbers.Real]]] | list[tuple[numbers.Real]]:
807+
) -> dict[str, list[tuple[float, float]]] | list[list[tuple[float, float]]]:
801808
"""Get values of input signals.
802809
803810
Args:
@@ -942,7 +949,7 @@ def getSimulationOptions(
942949
def getLinearizationOptions(
943950
self,
944951
names: Optional[str | list[str]] = None,
945-
) -> dict[str, str | numbers.Real] | list[str | numbers.Real]:
952+
) -> dict[str, str | float] | list[str | float]:
946953
"""Get simulation options used for linearization.
947954
948955
Args:
@@ -980,7 +987,7 @@ def getLinearizationOptions(
980987
def getOptimizationOptions(
981988
self,
982989
names: Optional[str | list[str]] = None,
983-
) -> dict[str, str | numbers.Real] | list[str | numbers.Real]:
990+
) -> dict[str, str | float] | list[str | float]:
984991
"""Get simulation options used for optimization.
985992
986993
Args:
@@ -1789,9 +1796,9 @@ def linearize(
17891796
continue
17901797

17911798
target = body_part.targets[0].id # type: ignore
1792-
value = ast.literal_eval(body_part.value)
1799+
value_ast = ast.literal_eval(body_part.value)
17931800

1794-
linear_data[target] = value
1801+
linear_data[target] = value_ast
17951802
except (AttributeError, IndexError, ValueError, SyntaxError, TypeError) as ex:
17961803
raise ModelicaSystemError(f"Error parsing linearization file {linear_file}!") from ex
17971804

0 commit comments

Comments
 (0)