agentlib_mpc.modules.estimation package

Submodules

agentlib_mpc.modules.estimation.mhe module

class agentlib_mpc.modules.estimation.mhe.MHE(config: dict, agent: Agent)[source]

Bases: BaseModule

A moving horizon estimator.

cleanup_results()[source]

Deletes all files this module created.

Override this method, if your module creates e.g. results files etc.

collect_variables_for_optimization(var_ref: MHEVariableReference = None) Dict[str, AgentVariable][source]

Gets all variables noted in the var ref and puts them in a flat dictionary. The MHE Version of this function has to perform some checks and lookups extra, since variables come from different sources, and some need to incorporate trajectories of past values.

config_type

alias of MHEConfig

get_results() DataFrame | None[source]

Read the results that were saved from the optimization backend and returns them as Dataframe.

Returns:

(results, stats) tuple of Dataframes.

process()[source]

This abstract method must be implemented in order to sync the module with the other processes of the agent and the whole MAS.

static read_results_file(results_file: str) Tuple[DataFrame, DataFrame][source]

Read the provided csv-file as an MPC results file. :param results_file: File path

Returns:

results, stats results is the Dataframe with all inputs and outputs of the MPC optimizations. stats is the Dataframe with matching solver stats

register_callbacks()[source]

Registers callbacks which listen to the variables which have to be saved as time series. These callbacks save the values in the history for use in the optimization.

var_ref: MHEVariableReference
pydantic model agentlib_mpc.modules.estimation.mhe.MHEConfig[source]

Bases: BaseModuleConfig

Pydantic data model for MPC configuration parser

Config:
  • arbitrary_types_allowed: bool = True

  • validate_assignment: bool = True

  • extra: str = forbid

  • frozen: bool = True

Fields:
Validators:
field estimated_inputs: List[MPCVariable] = []

List of unknown input variables of the MHE. Includes mainly disturbances.

field estimated_parameters: List[MPCVariable] = []

List of unknown parameters of the MHE. They are constant over the horizon and will be estimated.

field horizon: int = 5

Estimation horizon of the MHE.

Constraints:
  • ge = 0

field known_inputs: List[MPCVariable] = []

List of known input variables of the MHE. Includes controls, disturbances, setpoints, dynamic constraint boundaries etc.

field known_parameters: List[MPCVariable] = []

List of known parameters of the MHE. They are constant over the horizon. Parameters not listed here will have their default from the model file.

field optimization_backend: dict [Required]
field shared_variable_fields: list[str] = []
Validated by:
  • check_valid_fields

field state_weights: dict[str, float] = {}

Mapping of state names to their weight in the MHE problem. If you are certain with your measurement, chose a high value. If you dont have a measurement / do not trust it, choose 0. Default is 0.

field states: List[MPCVariable] = []

List of all differential states of the MHE.

field time_step: float = 60

Time step of the MHE.

Constraints:
  • ge = 0

model_post_init(context: Any, /) None

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

classmethod state_weights_are_in_states(state_weights: dict, info: ValidationInfo)[source]

Wrap a classmethod, staticmethod, property or unbound function and act as a descriptor that allows us to detect decorated items from the class’ attributes.

This class’ __get__ returns the wrapped item’s __get__ result, which makes it transparent for classmethods and staticmethods.

wrapped

The decorator that has to be wrapped.

decorator_info

The decorator info.

shim

A wrapper function to wrap V1 style function.