agentlib_mpc.modules package
This package contains all modules for the distributed model predictive control using multi agent systems.
It contains classes for local optimization and global coordination.
Subpackages
- agentlib_mpc.modules.InputPrediction package
- agentlib_mpc.modules.dmpc package
DistributedMPC
DistributedMPCConfig
- Subpackages
- Submodules
- agentlib_mpc.modules.dmpc.coordinator module
Coordinator
CoordinatorConfig
CoordinatorConfig.log_level
CoordinatorConfig.maxIter
CoordinatorConfig.messages_in
CoordinatorConfig.messages_out
CoordinatorConfig.module_id
CoordinatorConfig.shared_variable_fields
CoordinatorConfig.time_out_non_responders
CoordinatorConfig.type
CoordinatorConfig.validate_incoming_values
CoordinatorConfig.model_post_init()
- agentlib_mpc.modules.dmpc.employee module
MiniEmployee
MiniEmployeeConfig
MiniEmployeeConfig.coordinator
MiniEmployeeConfig.log_level
MiniEmployeeConfig.messages_in
MiniEmployeeConfig.messages_out
MiniEmployeeConfig.module_id
MiniEmployeeConfig.registration_interval
MiniEmployeeConfig.request_frequency
MiniEmployeeConfig.shared_variable_fields
MiniEmployeeConfig.type
MiniEmployeeConfig.validate_incoming_values
MiniEmployeeConfig.model_post_init()
- agentlib_mpc.modules.estimation package
- Submodules
- agentlib_mpc.modules.estimation.mhe module
MHE
MHEConfig
MHEConfig.estimated_inputs
MHEConfig.estimated_parameters
MHEConfig.horizon
MHEConfig.known_inputs
MHEConfig.known_parameters
MHEConfig.optimization_backend
MHEConfig.shared_variable_fields
MHEConfig.state_weights
MHEConfig.states
MHEConfig.time_step
MHEConfig.model_post_init()
MHEConfig.state_weights_are_in_states()
MHEConfig.wrapped
MHEConfig.decorator_info
MHEConfig.shim
- agentlib_mpc.modules.ml_model_training package
- Submodules
- agentlib_mpc.modules.ml_model_training.data_reduction module
- agentlib_mpc.modules.ml_model_training.ml_model_trainer module
ANNTrainer
ANNTrainerConfig
GPRTrainer
GPRTrainerConfig
LinRegTrainer
LinRegTrainerConfig
MLModelTrainer
MLModelTrainer.agent_and_time
MLModelTrainer.build_ml_model()
MLModelTrainer.create_inputs_and_outputs()
MLModelTrainer.divide_in_tvt()
MLModelTrainer.fit_ml_model()
MLModelTrainer.input_names
MLModelTrainer.model_type
MLModelTrainer.output_names
MLModelTrainer.process()
MLModelTrainer.register_callbacks()
MLModelTrainer.resample()
MLModelTrainer.retrain_model()
MLModelTrainer.save_all()
MLModelTrainer.save_ml_model()
MLModelTrainer.serialize_ml_model()
MLModelTrainer.training_info
MLModelTrainerConfig
MLModelTrainerConfig.MLModel
MLModelTrainerConfig.data_sources
MLModelTrainerConfig.inputs
MLModelTrainerConfig.interpolations
MLModelTrainerConfig.lags
MLModelTrainerConfig.output_types
MLModelTrainerConfig.outputs
MLModelTrainerConfig.recursive_outputs
MLModelTrainerConfig.retrain_delay
MLModelTrainerConfig.save_data
MLModelTrainerConfig.save_directory
MLModelTrainerConfig.save_ml_model
MLModelTrainerConfig.save_plots
MLModelTrainerConfig.shared_variable_fields
MLModelTrainerConfig.step_size
MLModelTrainerConfig.test_share
MLModelTrainerConfig.time_series_length
MLModelTrainerConfig.time_series_memory_size
MLModelTrainerConfig.train_share
MLModelTrainerConfig.use_values_for_incomplete_data
MLModelTrainerConfig.validation_share
MLModelTrainerConfig.check_data_sources_exist
MLModelTrainerConfig.check_if_save_path_is_there
MLModelTrainerConfig.check_shares_amount_to_one
MLModelTrainerConfig.fill_interpolations
MLModelTrainerConfig.fill_lags
MLModelTrainerConfig.fill_output_types
MLModelTrainerConfig.fill_recursive_outputs
MLModelTrainerConfig.model_post_init()
- agentlib_mpc.modules.ml_model_training.setpoint_generator module
SetPointGenerator
SetPointGeneratorConfig
SetPointGeneratorConfig.day_end
SetPointGeneratorConfig.day_lb
SetPointGeneratorConfig.day_start
SetPointGeneratorConfig.day_ub
SetPointGeneratorConfig.interval
SetPointGeneratorConfig.night_lb
SetPointGeneratorConfig.night_ub
SetPointGeneratorConfig.shared_variable_fields
SetPointGeneratorConfig.target_variable
SetPointGeneratorConfig.model_post_init()
Submodules
agentlib_mpc.modules.data_source module
- class agentlib_mpc.modules.data_source.DataSource(config: dict, agent: Agent)[source]
Bases:
BaseModule
- pydantic model agentlib_mpc.modules.data_source.DataSourceConfig[source]
Bases:
BaseModuleConfig
- Config:
arbitrary_types_allowed: bool = True
validate_assignment: bool = True
extra: str = forbid
frozen: bool = True
- Fields:
- Validators:
- field columns: List[str] | None = None
Optional list of columns of data frame that should be sent.If ommited, all datapoint in frame are sent.
- field data: DataFrame | Path = Empty DataFrame Columns: [] Index: []
Data that should be communicated during execution.Index should be either numeric or Datetime, numeric values are interpreted as seconds.
- Validated by:
- field data_offset: Timedelta | float | None = 0
Offset will be subtracted from index.
- field interpolation_method: InterpolationMethods | None = InterpolationMethods.previous
Interpolation method used for resampling of data.Only ‘linear’ and ‘previous’ are allowed.
- Validated by:
- field t_sample: float | int = 1
Sample time of data source. Default is 1 s.
- validator check_interpolation_method » interpolation_method[source]
- model_post_init(context: Any, /) None
We need to both initialize private attributes and call the user-defined model_post_init method.
agentlib_mpc.modules.minlp_mpc module
- class agentlib_mpc.modules.minlp_mpc.MINLPMPC(config: dict, agent: Agent)[source]
Bases:
BaseMPC
- pydantic model agentlib_mpc.modules.minlp_mpc.MINLPMPCConfig[source]
Bases:
BaseMPCConfig
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 binary_controls: List[MPCVariable] = []
List of all binary control variables of the MPC.
- Validated by:
- model_post_init(context: Any, /) None
We need to both initialize private attributes and call the user-defined model_post_init method.
- validator validate_binary_bounds » binary_controls[source]
Assures all binary variables have 0 and 1 as boundaries.
agentlib_mpc.modules.ml_model_simulator module
agentlib_mpc.modules.mpc module
Holds the base class for MPCs.
- class agentlib_mpc.modules.mpc.BaseMPC(config: dict, agent: Agent)[source]
Bases:
BaseModule
A model predictive controller. More info to follow.
- assert_mpc_variables_are_in_model() dict[str, set[str]] [source]
Checks whether all variables of var_ref are contained in the model. Returns names of model variables not contained in the var_ref, sorted by keys: ‘states’, ‘inputs’, ‘outputs’, ‘parameters’.
- assert_subset(mpc_names, model_names, message_head)[source]
Helper function for assert assert_mpc_variables_are_in_model. Asserts the variables of the var_ref corresponding to ref_key are a subset of a list of names provided (usually obtained from the model) and prints out an error if false. Returns the portion of model_names that are not in the given var_ref.
- 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: VariableReference = None) Dict[str, AgentVariable] [source]
Gets all variables noted in the var ref and puts them in a flat dictionary.
- 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.
- property model: Model
Getter for current simulation model
- Returns:
Current simulation model
- Return type:
agentlib.model
- pre_computation_hook()[source]
This method is called in every computation step before the optimization starts. Overwrite this method in a derived subclass if you want to take some actions each time before the optimal control problem is solved.
- 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.
- re_init_optimization(parameter: AgentVariable)[source]
Re-initializes the optimization backend with new parameters.
- 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 the init_optimization callback to all parameters which cannot be changed without recreating the optimization problem.
- set_actuation(solution: Results)[source]
Takes the solution from optimization backend and sends the first step to AgentVariables.
- pydantic model agentlib_mpc.modules.mpc.BaseMPCConfig[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:
controls (List[agentlib_mpc.data_structures.mpc_datamodels.MPCVariable])
inputs (List[agentlib_mpc.data_structures.mpc_datamodels.MPCVariable])
outputs (List[agentlib_mpc.data_structures.mpc_datamodels.MPCVariable])
parameters (List[agentlib_mpc.data_structures.mpc_datamodels.MPCVariable])
states (List[agentlib_mpc.data_structures.mpc_datamodels.MPCVariable])
- Validators:
check_valid_fields
»shared_variable_fields
check_valid_level
»log_level
- field controls: List[MPCVariable] = []
List of all control variables of the MPC.
- field inputs: List[MPCVariable] = []
List of all input variables of the MPC. Includes predictions for disturbances, set_points, dynamic constraint boundaries etc.
- field log_level: str | None = None
The log level for this Module. Default uses the root-loggers level.Options: DEBUG; INFO; WARNING; ERROR; CRITICAL
- Validated by:
check_valid_level
- field module_id: str [Required]
The unqiue id of the module within an agent, used only to communicate withing the agent.
- field optimization_backend: dict [Required]
- field outputs: List[MPCVariable] = []
List of all shared outputs of the MPC.
- field parameters: List[MPCVariable] = []
List of model parameters of the MPC. They are constant over the horizon. Parameters not listed here will have their default from the model file.
- field prediction_horizon: int = 5
Prediction horizon of the MPC.
- Constraints:
ge = 0
- field sampling_time: float | None = None
Sampling interval for control steps. If None, will be the same as time step. Does not affect the discretization of the MPC, only the interval with which there will be optimization steps.
- Validated by:
- field set_outputs: bool = False
Sets the full output time series to the data broker.
- Validated by:
check_valid_fields
- field states: List[MPCVariable] = []
List of all differential states of the MPC. The entries can define the boundaries and the source for the measurements
- field time_step: float = 60
Time step of the MPC.
- Constraints:
ge = 0
- field type: str | Dict[str, str] [Required]
The type of the Module. Used to find the Python-Object from all agentlib-core and plugin Module options. If a dict is given,it must contain the keys ‘file’ and ‘class_name’. ‘file’ is the filepath of a python file containing the Module.’class_name’ is the name of the Module class within this file.
- field validate_incoming_values: bool | None = True
If true, the validator of the AgentVariable value is called when receiving a new value from the DataBroker.
- validator default_sampling_time » sampling_time[source]
- model_post_init(context: Any, /) None
We need to both initialize private attributes and call the user-defined model_post_init method.
agentlib_mpc.modules.mpc_full module
Holds the class for full featured MPCs.
- class agentlib_mpc.modules.mpc_full.MPC(config: dict, agent: Agent)[source]
Bases:
BaseMPC
A model predictive controller. More info to follow.
- collect_variables_for_optimization(var_ref: VariableReference = None) dict[str, agentlib.core.datamodels.AgentVariable] [source]
Gets all variables noted in the var ref and puts them in a flat dictionary.
- pydantic model agentlib_mpc.modules.mpc_full.MPCConfig[source]
Bases:
BaseMPCConfig
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 r_del_u: dict[str, float] = {}
Weights that are applied to the change in control variables.
- Validated by:
- validator check_r_del_u_in_controls » r_del_u[source]
Ensures r_del_u is only set for control variables.
- model_post_init(context: Any, /) None
We need to both initialize private attributes and call the user-defined model_post_init method.