Commit 04772624 authored by Jorn Baayen's avatar Jorn Baayen

Add typing hints.

parent 15ffd8cd
......@@ -1728,7 +1728,7 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass=ABC
nominal = self.variable_nominal(state)
if nominal != 1:
accumulation_states[i] *= nominal
accumulation_states = ca.transpose(horzcat(*accumulation_states))
accumulation_states = ca.transpose(ca.horzcat(*accumulation_states))
# Prepare derivatives (backwards differencing, consistent with the evaluation of path expressions during transcription)
accumulation_derivatives = [None] * len(derivatives)
......@@ -1760,11 +1760,11 @@ class CollocatedIntegratedOptimizationProblem(OptimizationProblem, metaclass=ABC
collocation_times, constant_input.times, values, 0.0, 0.0)
accumulation_constant_inputs = ca.transpose(
horzcat(*accumulation_constant_inputs))
ca.horzcat(*accumulation_constant_inputs))
# Map
values = fmap(accumulation_states, accumulation_derivatives,
accumulation_constant_inputs, ca.repmat(
vertcat(*self.__parameter_values_ensemble_member_0), 1, n_collocation_times),
ca.vertcat(*self.__parameter_values_ensemble_member_0), 1, n_collocation_times),
np.transpose(collocation_times))
return ca.transpose(values)
from typing import Dict, List, Union
import numpy as np
import logging
......@@ -12,7 +13,7 @@ class ControlTreeMixin(OptimizationProblem):
Adds a stochastic control tree to your optimization problem.
"""
def control_tree_options(self):
def control_tree_options(self) -> Dict[str, Union[List[str], List[float], int]]:
"""
Returns a dictionary of options controlling the creation of a k-ary stochastic tree.
......
......@@ -384,7 +384,7 @@ class CSVMixin(OptimizationProblem):
for variable in self.__output_timeseries])
return variables
def min_timeseries_id(self, variable):
def min_timeseries_id(self, variable: str) -> str:
"""
Returns the name of the lower bound timeseries for the specified variable.
......@@ -392,7 +392,7 @@ class CSVMixin(OptimizationProblem):
"""
return '_'.join((variable, 'Min'))
def max_timeseries_id(self, variable):
def max_timeseries_id(self, variable: str) -> str:
"""
Returns the name of the upper bound timeseries for the specified variable.
......
from typing import Dict
import logging
from .optimization_problem import OptimizationProblem
......@@ -43,7 +44,7 @@ class HomotopyMixin(OptimizationProblem):
return parameters
def homotopy_options(self):
def homotopy_options(self) -> Dict[str, Union[str, float]]:
"""
Returns a dictionary of options controlling the homotopy process.
......
from typing import List, Tuple, Union
from .goal_programming_mixin import GoalProgrammingMixin, Goal
......@@ -51,7 +52,7 @@ class InitialStateEstimationMixin(GoalProgrammingMixin):
"""
def initial_state_measurements(self):
def initial_state_measurements(self) -> List[Union[Tuple[str, str], Tuple[str, str, float]]]:
"""
List of pairs ``(state, measurement_id)`` or triples ``(state, measurement_id, max_deviation)``,
relating states to measurement time series IDs.
......@@ -60,7 +61,7 @@ class InitialStateEstimationMixin(GoalProgrammingMixin):
"""
return []
def initial_state_smoothing_pairs(self):
def initial_state_smoothing_pairs(self) -> List[Union[Tuple[str, str], Tuple[str, str, float]]]:
"""
List of pairs ``(state1, state2)`` or triples ``(state1, state2, max_deviation)``, relating
states the distance of which is to be minimized.
......
......@@ -18,7 +18,7 @@ class LinearizationMixin(OptimizationProblem):
return parameters
def linearization_parameters(self):
def linearization_parameters(self) -> Dict[str, str]:
"""
:returns: A dictionary of parameter names mapping to time series identifiers.
"""
......
from typing import Dict, Union
import pymola
import pymola.backends.casadi.api
import casadi as ca
......@@ -123,7 +124,7 @@ class ModelicaMixin(OptimizationProblem):
super().__init__(**kwargs)
@cached
def compiler_options(self):
def compiler_options(self) -> Dict[str, Union[str, bool]]:
"""
Subclasses can configure the `pymola <http://github.com/jgoppert/pymola>`_ compiler options here.
......
......@@ -428,7 +428,7 @@ class PIMixin(OptimizationProblem):
for variable in self.__output_timeseries])
return variables
def min_timeseries_id(self, variable):
def min_timeseries_id(self, variable: str) -> str:
"""
Returns the name of the lower bound timeseries for the specified variable.
......@@ -436,7 +436,7 @@ class PIMixin(OptimizationProblem):
"""
return '_'.join((variable, 'Min'))
def max_timeseries_id(self, variable):
def max_timeseries_id(self, variable: str) -> str:
"""
Returns the name of the upper bound timeseries for the specified variable.
......
import numpy as np
import casadi as ca
from typing import Union
class Timeseries:
......@@ -6,7 +8,7 @@ class Timeseries:
Time series object, bundling time stamps with values.
"""
def __init__(self, times, values):
def __init__(self, times: np.ndarray, values: Union[np.ndarray, list, ca.DM]):
"""
Create a new time series object.
......@@ -22,21 +24,21 @@ class Timeseries:
self.__values = np.full_like(times, values, dtype=np.float64)
@property
def times(self):
def times(self) -> np.ndarray:
"""
Array of time stamps.
"""
return self.__times
@property
def values(self):
def values(self) -> np.ndarray:
"""
Array of values.
"""
return self.__values
def __neg__(self):
def __neg__(self) -> 'Timeseries':
return self.__class__(self.times, -self.values)
def __repr__(self):
def __repr__(self) -> str:
return 'Timeseries({}, {})'.format(self.__times, self.__values)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment