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
DistributedMPCDistributedMPCConfig- Subpackages
- Submodules
- agentlib_mpc.modules.dmpc.coordinator module
CoordinatorCoordinatorConfigCoordinatorConfig.log_levelCoordinatorConfig.maxIterCoordinatorConfig.messages_inCoordinatorConfig.messages_outCoordinatorConfig.module_idCoordinatorConfig.shared_variable_fieldsCoordinatorConfig.time_out_non_respondersCoordinatorConfig.typeCoordinatorConfig.validate_incoming_valuesCoordinatorConfig.model_post_init()
- agentlib_mpc.modules.dmpc.employee module
MiniEmployeeMiniEmployeeConfigMiniEmployeeConfig.coordinatorMiniEmployeeConfig.log_levelMiniEmployeeConfig.messages_inMiniEmployeeConfig.messages_outMiniEmployeeConfig.module_idMiniEmployeeConfig.registration_intervalMiniEmployeeConfig.request_frequencyMiniEmployeeConfig.shared_variable_fieldsMiniEmployeeConfig.typeMiniEmployeeConfig.validate_incoming_valuesMiniEmployeeConfig.model_post_init()
- agentlib_mpc.modules.estimation package
- Submodules
- agentlib_mpc.modules.estimation.mhe module
MHEMHEConfigMHEConfig.estimated_inputsMHEConfig.estimated_parametersMHEConfig.horizonMHEConfig.known_inputsMHEConfig.known_parametersMHEConfig.optimization_backendMHEConfig.shared_variable_fieldsMHEConfig.state_weightsMHEConfig.statesMHEConfig.time_stepMHEConfig.model_post_init()MHEConfig.state_weights_are_in_states()MHEConfig.wrappedMHEConfig.decorator_infoMHEConfig.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
ANNTrainerANNTrainerConfigGPRTrainerGPRTrainerConfigLinRegTrainerLinRegTrainerConfigMLModelTrainerMLModelTrainer.agent_and_timeMLModelTrainer.build_ml_model()MLModelTrainer.create_inputs_and_outputs()MLModelTrainer.divide_in_tvt()MLModelTrainer.fit_ml_model()MLModelTrainer.input_namesMLModelTrainer.model_typeMLModelTrainer.output_namesMLModelTrainer.process()MLModelTrainer.register_callbacks()MLModelTrainer.resample()MLModelTrainer.retrain_model()MLModelTrainer.save_all()MLModelTrainer.save_ml_model()MLModelTrainer.serialize_ml_model()MLModelTrainer.training_info
MLModelTrainerConfigMLModelTrainerConfig.MLModelMLModelTrainerConfig.data_sourcesMLModelTrainerConfig.inputsMLModelTrainerConfig.interpolationsMLModelTrainerConfig.lagsMLModelTrainerConfig.output_typesMLModelTrainerConfig.outputsMLModelTrainerConfig.recursive_outputsMLModelTrainerConfig.retrain_delayMLModelTrainerConfig.save_dataMLModelTrainerConfig.save_directoryMLModelTrainerConfig.save_ml_modelMLModelTrainerConfig.save_plotsMLModelTrainerConfig.shared_variable_fieldsMLModelTrainerConfig.step_sizeMLModelTrainerConfig.test_shareMLModelTrainerConfig.time_series_lengthMLModelTrainerConfig.time_series_memory_sizeMLModelTrainerConfig.train_shareMLModelTrainerConfig.use_values_for_incomplete_dataMLModelTrainerConfig.validation_shareMLModelTrainerConfig.check_data_sources_existMLModelTrainerConfig.check_if_save_path_is_thereMLModelTrainerConfig.check_shares_amount_to_oneMLModelTrainerConfig.fill_interpolationsMLModelTrainerConfig.fill_lagsMLModelTrainerConfig.fill_output_typesMLModelTrainerConfig.fill_recursive_outputsMLModelTrainerConfig.model_post_init()
- agentlib_mpc.modules.ml_model_training.setpoint_generator module
SetPointGeneratorSetPointGeneratorConfigSetPointGeneratorConfig.day_endSetPointGeneratorConfig.day_lbSetPointGeneratorConfig.day_startSetPointGeneratorConfig.day_ubSetPointGeneratorConfig.intervalSetPointGeneratorConfig.night_lbSetPointGeneratorConfig.night_ubSetPointGeneratorConfig.shared_variable_fieldsSetPointGeneratorConfig.target_variableSetPointGeneratorConfig.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:
Indicates if the variable is going to be shared with other agents.
- 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
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
agentlib_mpc.modules.minlp_mpc module
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:
BaseModuleA 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:
BaseModuleConfigPydantic 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_fieldscheck_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
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.
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:
BaseMPCA 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:
BaseMPCConfigPydantic 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
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self – The BaseModel instance.
context – The context.