agentlib_mpc.models package

Submodules

agentlib_mpc.models.ann_model module

agentlib_mpc.models.casadi_model module

Holds the classes for CasADi variables and the CasADi model.

class agentlib_mpc.models.casadi_model.CasadiInput(*, name: str, timestamp: float | None = None, unit: str = 'Not defined', description: str = 'Not defined', ub=inf, lb=-inf, clip: bool = False, allowed_values: List[Any] = [], value: Any = None, causality: Causality = None, variability: Variability = None, type: str | None = 'float', sim_time: float = 0.0, _sym: MX | SX | DM | Sparsity = None)[source]

Bases: CasadiVariable

Class that stores various attributes of control variables.

property alg: MX | SX | DM | Sparsity
class agentlib_mpc.models.casadi_model.CasadiModel(**kwargs)[source]

Bases: Model

Base Class for CasADi models. To implement your own model, inherit from this class, specify the variables (inputs, outputs, states, parameters and override the setup_system() method.

property auxiliaries: List[CasadiState]

List of all CasadiStates without an associated equation. Common uses for this are slack variables that appear in cost functions and constraints of optimization models.

property differentials: List[CasadiState]

List of all CasadiStates with an associated differential equation.

do_step(*, t_start, t_sample=None)[source]

Performing one simulation step :param t_start: start time for integration :param t_sample: increment of solver integration

Returns:

get(name: str) CasadiVariable[source]

Get any variable from using name:

Parameters:

name (str) – The item to get from config by name of Variable. Hence, item=ModelVariable.name

Returns:

The matching variable

Return type:

var (ModelVariable)

Raises:

AttributeError – If the item was not found in the variables of the module.

get_constraints() List[ModelConstraint][source]

List of constraints of the form (lower, function, upper).

get_differential_values()[source]
get_input_values()[source]
initialize(**ignored)[source]

Initializes Casadi model. Creates the integrator to be used in do_step(). The integrator takes the current state and input values as input and returns the state values at the end of the interval and the value of the cost function integrated over the interval.

property inputs: list[agentlib_mpc.models.casadi_model.CasadiInput]

Get all model inputs as a list

property output_equations: List[MX | SX | DM | Sparsity]

List of algebraic equations RHS in the form 0 = z - g(x, z, p, … )

property outputs: list[agentlib_mpc.models.casadi_model.CasadiOutput]

Get all model outputs as a list

property parameters: list[agentlib_mpc.models.casadi_model.CasadiParameter]

Get all model parameters as a list

set_differential_values(values: List | ndarray)[source]

Sets the values for all differential variables. Provided values list MUST match the order in which differentials are saved, there is no check.

set_output_values(values: List | ndarray)[source]

Sets the values for all outputs. Provided values list MUST match the order in which outputs are saved, there is no check.

abstract setup_system()[source]
property states: list[agentlib_mpc.models.casadi_model.CasadiState]

Get all model states as a list

pydantic model agentlib_mpc.models.casadi_model.CasadiModelConfig[source]

Bases: ModelConfig

Config:
  • validate_assignment: bool = True

  • arbitrary_types_allowed: bool = True

  • extra: str = forbid

Fields:
Validators:
  • include_default_model_variables » inputs

  • include_default_model_variables » outputs

  • include_default_model_variables » parameters

  • include_default_model_variables » states

field cost_function: MX | SX | DM | Sparsity = None
field inputs: List[CasadiInput] = []
Validated by:
  • include_default_model_variables

field outputs: List[CasadiOutput] = []
Validated by:
  • include_default_model_variables

field parameters: List[CasadiParameter] = []
Validated by:
  • include_default_model_variables

field states: List[CasadiState] = []
Validated by:
  • include_default_model_variables

field system: MX | SX | DM | Sparsity = None
model_post_init(context: Any, /) None

We need to both initialize private attributes and call the user-defined model_post_init method.

class agentlib_mpc.models.casadi_model.CasadiOutput(*, name: str, timestamp: float | None = None, unit: str = 'Not defined', description: str = 'Not defined', ub=inf, lb=-inf, clip: bool = False, allowed_values: List[Any] = [], value: Any = None, causality: Causality = None, variability: Variability = None, type: str | None = 'float', sim_time: float = 0.0, _sym: MX | SX | DM | Sparsity = None, _alg: MX | SX | DM | Sparsity = None)[source]

Bases: CasadiVariable

Class that stores various attributes of control variables.

property alg: MX | SX | DM | Sparsity
json(**kwargs)[source]

Serializes the Variable in json format and returns a string

class agentlib_mpc.models.casadi_model.CasadiParameter(*, name: str, timestamp: float | None = None, unit: str = 'Not defined', description: str = 'Not defined', ub=inf, lb=-inf, clip: bool = False, allowed_values: List[Any] = [], value: Any = None, causality: Causality = None, variability: Variability = None, type: str | None = 'float', sim_time: float = 0.0, _sym: MX | SX | DM | Sparsity = None)[source]

Bases: CasadiVariable

Class that stores various attributes of parameters.

class agentlib_mpc.models.casadi_model.CasadiState(*, name: str, timestamp: float | None = None, unit: str = 'Not defined', description: str = 'Not defined', ub=inf, lb=-inf, clip: bool = False, allowed_values: List[Any] = [], value: Any = None, causality: Causality = None, variability: Variability = None, type: str | None = 'float', sim_time: float = 0.0, _sym: MX | SX | DM | Sparsity = None, _ode: MX | SX | DM | Sparsity | None = None)[source]

Bases: CasadiVariable

Class that stores various attributes of CasADi differential variables.

property alg: MX | SX | DM | Sparsity
json(indent: int = 2, **kwargs)[source]

Serializes the Variable in json format and returns a string

property ode: MX | SX | DM | Sparsity
class agentlib_mpc.models.casadi_model.CasadiVariable(*, name: str, timestamp: float | None = None, unit: str = 'Not defined', description: str = 'Not defined', ub=inf, lb=-inf, clip: bool = False, allowed_values: List[Any] = [], value: Any = None, causality: Causality = None, variability: Variability = None, type: str | None = 'float', sim_time: float = 0.0, _sym: MX | SX | DM | Sparsity = None)[source]

Bases: ModelVariable

Base Class for variables used in Casadi Models for simulation and optimization. Implements the standard arithmetic operations, so CasadiVariables can be used in equations. .. attribute:: sym

The symbolic CasADi variable used to define ode’s and optimization problems.

create_sym() MX[source]

Ensures a symbolic MX variable is created with each CasadiVariable instance, and that its dimensions are consistent.

property sym: MX
agentlib_mpc.models.casadi_model.get_symbolic(equation)[source]

agentlib_mpc.models.casadi_model_ann module

agentlib_mpc.models.casadi_neural_network module

agentlib_mpc.models.serialized_ann module

Module contents

Package containing models for agentlib_mpc.