agentlib_mpc.optimization_backends package

pydantic model agentlib_mpc.optimization_backends.BackendImport[source]

Bases: BaseModel

Data-Class to import a given python file from import_path and load the given class_name

Fields:
field class_name: str [Required]
field import_path: str [Required]

Subpackages

Submodules

agentlib_mpc.optimization_backends.backend module

class agentlib_mpc.optimization_backends.backend.ADMMBackend(config: dict)[source]

Bases: OptimizationBackend

Base class for implementations of optimization backends for ADMM algorithms.

abstract property coupling_grid: list[float]

Returns the grid on which the coupling variables are discretized.

pydantic model agentlib_mpc.optimization_backends.backend.BackendConfig[source]

Bases: BaseModel

Config:
  • extra: str = forbid

Fields:
Validators:
field discretization_options: DiscretizationOptions [Required]
field model: dict [Required]
field name: str | None = None
field overwrite_result_file: bool | None = False
Validated by:
field results_file: Path | None = None
Validated by:
field save_results: bool | None = None
Validated by:
validator check_csv  »  results_file[source]
validator check_overwrite  »  overwrite_result_file[source]

Checks, whether the overwrite results sttings are valid, and deletes existing result files if applicable.

validator disable_results_if_no_file  »  save_results[source]
class agentlib_mpc.optimization_backends.backend.OptimizationBackend(config: dict)[source]

Bases: ABC

Base class for all optimization backends. OptimizationBackends are a plugin for the ‘mpc’ module. They provide means to setup and solve the underlying optimization problem of the MPC. They also can save data of the solutions.

config_type

alias of BackendConfig

cost_function: Callable | None
get_lags_per_variable() dict[str, float][source]

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

model: ModelT
model_from_config(model: dict)[source]

Set the model to the backend.

mpc_backend_parameters = ('time_step', 'prediction_horizon')
register_logger(logger: Logger)[source]

Registers a logger, can be used to use the module logger

results_file_exists() bool[source]

Checks if the results file already exists, and if not, creates it with headers.

abstract setup_optimization(var_ref: VariableReference)[source]

Performs all necessary steps to make the solve method usable.

Parameters:

var_ref – Variable Reference that specifies the role of each model variable in the mpc

abstract solve(now: float | datetime, current_vars: Dict[str, AgentVariable]) Results[source]

Solves the optimization problem given the current values of the corresponding AgentVariables and system time. The standardization of return values is a work in progress.

Parameters:
  • now – Current time used for interpolation of input trajectories.

  • current_vars – Dict of AgentVariables holding the values relevant to the optimization problem. Keys are the names

Returns:

A dataframe with all optimization variables over their respective grids. Depending on discretization, can include many nan’s, so care should be taken when using this, e.g. always use dropna() after accessing a column.

Example:

variables mDot | T_0 | slack_T

time 0 0.1 | 298 | nan 230 nan | 297 | 3 470 nan | 296 | 2 588 nan | 295 | 1 700 0.05 | 294 | nan 930 nan | 294 | 0.1

update_discretization_options(opts: dict)[source]

Updates the discretization options with the new dict.

update_model_variables(current_vars: Dict[str, AgentVariable])[source]

Internal method to write current data_broker to model variables. Only update values, not other module_types.

var_ref: VariableReference | None