agentlib_mpc.optimization_backends.casadi_ package

Subpackages

Submodules

agentlib_mpc.optimization_backends.casadi_.admm module

class agentlib_mpc.optimization_backends.casadi_.admm.ADMMCollocation(options: CasadiDiscretizationOptions)[source]

Bases: DirectCollocation

class agentlib_mpc.optimization_backends.casadi_.admm.ADMMMultipleShooting(options: CasadiDiscretizationOptions)[source]

Bases: MultipleShooting

class agentlib_mpc.optimization_backends.casadi_.admm.CasADiADMMBackend(config: dict)[source]

Bases: CasADiBaseBackend, ADMMBackend

Class doing optimization of ADMM subproblems with CasADi.

cost_function: Callable | None
property coupling_grid

Returns the grid on which the coupling variables are discretized.

discretization: DiscretizationT
discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.collocation: <class 'agentlib_mpc.optimization_backends.casadi_.admm.ADMMCollocation'>, DiscretizationMethod.multiple_shooting: <class 'agentlib_mpc.optimization_backends.casadi_.admm.ADMMMultipleShooting'>}
it: int
model: ModelT
now: float
result_stats: list[str]
results: list[pd.DataFrame]
save_result_df(results: Results, now: float = 0)[source]

Save the results of solve into a dataframe at each time step.

Example results dataframe:

value_type variable … lower variable T_0 T_0_slack … T_0_slack mDot_0 time_step … 2 0.000000 298.160000 NaN … NaN NaN

101.431499 297.540944 -149.465942 … -inf 0.0 450.000000 295.779780 -147.704779 … -inf 0.0 798.568501 294.720770 -146.645769 … -inf 0.0

Parameters:
  • results

  • now

Returns:

system: CasadiADMMSystem
system_type

alias of CasadiADMMSystem

var_ref: mpc_datamodels.VariableReference | None
class agentlib_mpc.optimization_backends.casadi_.admm.CasadiADMMSystem[source]

Bases: FullSystem

algebraics: OptimizationVariable
controls: OptimizationVariable
cost_function: ca.MX
exchange_diff: OptimizationParameter
exchange_multipliers: OptimizationParameter
global_couplings: OptimizationParameter
initial_state: OptimizationParameter
initialize(model: CasadiModel, var_ref: VariableReference)[source]
last_control: OptimizationParameter
local_couplings: OptimizationVariable
local_exchange: OptimizationVariable
model_constraints: Constraint
model_parameters: OptimizationParameter
multipliers: OptimizationParameter
non_controlled_inputs: OptimizationParameter
ode: ca.MX
outputs: OptimizationVariable
penalty_factor: OptimizationParameter
r_del_u: OptimizationParameter
states: OptimizationVariable

agentlib_mpc.optimization_backends.casadi_.basic module

class agentlib_mpc.optimization_backends.casadi_.basic.BaseSystem[source]

Bases: System

algebraics: OptimizationVariable
controls: OptimizationVariable
cost_function: MX
initial_state: OptimizationParameter
initialize(model: CasadiModel, var_ref: VariableReference)[source]
model_constraints: Constraint
model_parameters: OptimizationParameter
non_controlled_inputs: OptimizationParameter
ode: MX
outputs: OptimizationVariable
states: OptimizationVariable
class agentlib_mpc.optimization_backends.casadi_.basic.CasADiBaseBackend(config: dict)[source]

Bases: CasADiBackend

Class doing optimization of ADMM subproblems with CasADi.

cost_function: Callable | None
discretization: DiscretizationT
discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.collocation: <class 'agentlib_mpc.optimization_backends.casadi_.basic.DirectCollocation'>, DiscretizationMethod.multiple_shooting: <class 'agentlib_mpc.optimization_backends.casadi_.basic.MultipleShooting'>}
model: ModelT
system: BaseSystem
system_type

alias of BaseSystem

var_ref: mpc_datamodels.VariableReference | None
class agentlib_mpc.optimization_backends.casadi_.basic.CollocationMatrices(order: int, root: numpy.ndarray, B: numpy.ndarray, C: numpy.ndarray, D: numpy.ndarray)[source]

Bases: object

B: ndarray
C: ndarray
D: ndarray
order: int
root: ndarray
class agentlib_mpc.optimization_backends.casadi_.basic.DirectCollocation(options: CasadiDiscretizationOptions)[source]

Bases: Discretization

initialize(system: BaseSystem, solver_factory: SolverFactory)[source]

Initializes the trajectory optimization problem, creating all symbolic variables of the OCP, the mapping function and the numerical solver.

class agentlib_mpc.optimization_backends.casadi_.basic.MultipleShooting(options: CasadiDiscretizationOptions)[source]

Bases: Discretization

initialize(system: BaseSystem, solver_factory: SolverFactory)[source]

Initializes the trajectory optimization problem, creating all symbolic variables of the OCP, the mapping function and the numerical solver.

agentlib_mpc.optimization_backends.casadi_.casadi_admm_ml module

class agentlib_mpc.optimization_backends.casadi_.casadi_admm_ml.CasADiADMMBackend_NN(config: dict)[source]

Bases: CasADiADMMBackend, CasADiBBBackend

Class doing optimization with an MLModel.

discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.multiple_shooting: <class 'agentlib_mpc.optimization_backends.casadi_.casadi_admm_ml.MultipleShootingADMMNN'>}
system: CasadiADMMNNSystem
system_type

alias of CasadiADMMNNSystem

class agentlib_mpc.optimization_backends.casadi_.casadi_admm_ml.CasadiADMMNNSystem[source]

Bases: CasadiADMMSystem, CasadiMLSystem

In this class, the lags are determined by the trainer alone and the lags are saved in the serialized MLModel so that it doesn’t have to be defined in the model again

initialize(model: CasadiMLModel, var_ref: VariableReference)[source]
property parameters: list[agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationParameter]
past_couplings: OptimizationParameter
past_exchange: OptimizationParameter
property quantities: list[Union[agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationParameter, agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationVariable]]
property sim_step_quantities: dict[str, Union[agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationParameter, agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationVariable]]
property variables: list[agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationVariable]
class agentlib_mpc.optimization_backends.casadi_.casadi_admm_ml.MultipleShootingADMMNN(options: CasadiDiscretizationOptions)[source]

Bases: ADMMMultipleShooting, MultipleShooting_ML

max_lag: int

agentlib_mpc.optimization_backends.casadi_.casadi_ml module

class agentlib_mpc.optimization_backends.casadi_.casadi_ml.CasADiBBBackend(config: dict)[source]

Bases: CasADiBaseBackend

Class doing optimization with a MLModel.

discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.multiple_shooting: <class 'agentlib_mpc.optimization_backends.casadi_.casadi_ml.MultipleShooting_ML'>}
get_lags_per_variable() dict[str, float][source]

Returns the name of variables which include lags and their lag. The MPC module can use this information to save relevant past data of lagged variables

lag_collection: Dict[str, deque] = {}
max_lag: int
system: CasadiMLSystem
system_type

alias of CasadiMLSystem

class agentlib_mpc.optimization_backends.casadi_.casadi_ml.CasadiMLSystem[source]

Bases: FullSystem

all_system_quantities() dict[str, agentlib_mpc.optimization_backends.casadi_.core.VariableGroup.OptimizationQuantity][source]
initialize(model: CasadiMLModel, var_ref: FullVariableReference)[source]
lags_dict: dict[str, int]
property max_lag: int
model: CasadiMLModel
sim_step: Function
class agentlib_mpc.optimization_backends.casadi_.casadi_ml.MultipleShooting_ML(options: CasadiDiscretizationOptions)[source]

Bases: MultipleShooting

initialize(system: CasadiMLSystem, solver_factory: SolverFactory)[source]

Initializes the trajectory optimization problem, creating all symbolic variables of the OCP, the mapping function and the numerical solver.

max_lag: int

agentlib_mpc.optimization_backends.casadi_.full module

class agentlib_mpc.optimization_backends.casadi_.full.CasADiFullBackend(config: dict)[source]

Bases: CasADiBackend

Class doing optimization of ADMM subproblems with CasADi.

cost_function: Callable | None
discretization: DiscretizationT
discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.collocation: <class 'agentlib_mpc.optimization_backends.casadi_.full.DirectCollocation'>, DiscretizationMethod.multiple_shooting: <class 'agentlib_mpc.optimization_backends.casadi_.full.MultipleShooting'>}
model: ModelT
system: FullSystem
system_type

alias of FullSystem

var_ref: mpc_datamodels.VariableReference | None
class agentlib_mpc.optimization_backends.casadi_.full.DirectCollocation(options: CasadiDiscretizationOptions)[source]

Bases: DirectCollocation

class agentlib_mpc.optimization_backends.casadi_.full.FullSystem[source]

Bases: BaseSystem

algebraics: OptimizationVariable
controls: OptimizationVariable
cost_function: ca.MX
initial_state: OptimizationParameter
initialize(model: CasadiModel, var_ref: FullVariableReference)[source]
last_control: OptimizationParameter
model_constraints: Constraint
model_parameters: OptimizationParameter
non_controlled_inputs: OptimizationParameter
ode: ca.MX
outputs: OptimizationVariable
r_del_u: OptimizationParameter
states: OptimizationVariable
class agentlib_mpc.optimization_backends.casadi_.full.MultipleShooting(options: CasadiDiscretizationOptions)[source]

Bases: MultipleShooting

agentlib_mpc.optimization_backends.casadi_.mhe module

class agentlib_mpc.optimization_backends.casadi_.mhe.CollocationMatrices(order: int, root: numpy.ndarray, B: numpy.ndarray, C: numpy.ndarray, D: numpy.ndarray)[source]

Bases: object

B: ndarray
C: ndarray
D: ndarray
order: int
root: ndarray
class agentlib_mpc.optimization_backends.casadi_.mhe.DirectCollocation(options: CasadiDiscretizationOptions)[source]

Bases: Discretization

initialize(system: MHESystem, solver_factory: SolverFactory)[source]

Initializes the trajectory optimization problem, creating all symbolic variables of the OCP, the mapping function and the numerical solver.

only_positive_times_in_results: bool = False
class agentlib_mpc.optimization_backends.casadi_.mhe.MHEBackend(config: dict)[source]

Bases: CasADiBackend

Class doing optimization of ADMM subproblems with CasADi.

discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.collocation: <class 'agentlib_mpc.optimization_backends.casadi_.mhe.DirectCollocation'>}
static sample(trajectory: float | int | Series | list[Union[float, int]], grid: list | ndarray, current: float = 0, method: str = 'linear') list[source]

Obtain the specified portion of the trajectory.

Parameters:
  • trajectory – The trajectory to be sampled. Scalars will be expanded onto the grid. Lists need to exactly match the provided grid. Otherwise, a list of tuples is accepted with the form ( timestamp, value). A dict with the keys ‘grid’ and ‘value’ is also accepted.

  • current – start time of requested trajectory

  • grid – target interpolation grid in seconds in relative terms (i.e. starting from 0 usually)

  • method – interpolation method, currently accepted: ‘linear’, ‘spline’, ‘previous’

Returns:

Sampled list of values.

Takes a slice of the trajectory from the current time step with the specified length and interpolates it to match the requested sampling. If the requested horizon is longer than the available data, the last available value will be used for the remainder.

Raises:
  • ValueError

  • TypeError

system: MHESystem
system_type

alias of MHESystem

class agentlib_mpc.optimization_backends.casadi_.mhe.MHESystem[source]

Bases: System

algebraics: OptimizationVariable
cost_function: MX
estimated_inputs: OptimizationVariable
estimated_parameters: OptimizationVariable
estimated_states: OptimizationVariable
initialize(model: CasadiModel, var_ref: MHEVariableReference)[source]
known_inputs: OptimizationParameter
known_parameters: OptimizationParameter
measured_states: OptimizationParameter
model_constraints: Constraint
ode: MX
outputs: OptimizationVariable

agentlib_mpc.optimization_backends.casadi_.minlp module

class agentlib_mpc.optimization_backends.casadi_.minlp.CasADiMINLPBackend(config: dict)[source]

Bases: CasADiBackend

Class doing optimization of ADMM subproblems with CasADi.

cost_function: Callable | None
discretization: DiscretizationT
discretization_types: dict[DiscretizationMethod, Type[DiscretizationT]] = {DiscretizationMethod.collocation: <class 'agentlib_mpc.optimization_backends.casadi_.minlp.DirectCollocation'>}
model: ModelT
system: CasadiMINLPSystem
system_type

alias of CasadiMINLPSystem

var_ref: mpc_datamodels.VariableReference | None
class agentlib_mpc.optimization_backends.casadi_.minlp.CasadiMINLPSystem[source]

Bases: BaseSystem

algebraics: OptimizationVariable
binary_controls: OptimizationVariable
controls: OptimizationVariable
cost_function: ca.MX
initial_state: OptimizationParameter
initialize(model: CasadiModel, var_ref: MINLPVariableReference)[source]
model_constraints: Constraint
model_parameters: OptimizationParameter
non_controlled_inputs: OptimizationParameter
ode: ca.MX
outputs: OptimizationVariable
states: OptimizationVariable
class agentlib_mpc.optimization_backends.casadi_.minlp.DirectCollocation(options: CasadiDiscretizationOptions)[source]

Bases: DirectCollocation

agentlib_mpc.optimization_backends.casadi_.minlp_cia module