direct_data_driven_mpc.utilities.controller.data_driven_mpc_sim

direct_data_driven_mpc.utilities.controller.data_driven_mpc_sim#

Functions for simulating data-driven MPC control loops.

This module provides functions for simulating the closed-loop operation of both LTI and nonlinear data-driven MPC controllers applied to a system.

Functions

print_mpc_step_info(verbose, step, ...[, ...])

Print MPC step information based on the verbosity level.

simulate_lti_data_driven_mpc_control_loop(...)

Simulate a Data-Driven MPC control loop applied to a Linear Time-Invariant (LTI) system and return the resulting input-output data sequences.

simulate_nonlinear_data_driven_mpc_control_loop(...)

Simulate a Data-Driven MPC control loop applied to a nonlinear system and return the resulting input-output data sequences.

simulate_lti_data_driven_mpc_control_loop(system_model: LTIModel, data_driven_mpc_controller: LTIDataDrivenMPCController, n_steps: int, np_random: Generator, verbose: int) tuple[ndarray, ndarray][source]#

Simulate a Data-Driven MPC control loop applied to a Linear Time-Invariant (LTI) system and return the resulting input-output data sequences.

This function simulates the closed-loop operation of a Data-Driven MPC controller designed for LTI systems, following the Data-Driven MPC schemes described in Algorithm 1 (Nominal) and Algorithm 2 (Robust) of [1].

Parameters:
  • system_model (LTIModel) – An LTIModel instance representing a Linear Time-Invariant (LTI) system.

  • data_driven_mpc_controller (LTIDataDrivenMPCController) – An LTIDataDrivenMPCController instance representing a Data-Driven MPC controller designed for Linear Time-Invariant (LTI) systems.

  • n_steps (int) – The number of time steps for the simulation.

  • np_random (Generator) – A Numpy random number generator for generating random noise for the system’s output.

  • verbose (int) – The verbosity level: 0 = no output, 1 = minimal output, 2 = detailed output.

Returns:

tuple[np.ndarray, np.ndarray] – A tuple containing two arrays:

  • An array of shape (n_steps, m) representing the optimal control inputs applied to the system, where m is the number of control inputs.

  • An array of shape (n_steps, p) representing the output response of the system, where p is the number of system outputs.

References

[1] J. Berberich, J. Köhler, M. A. Müller and F. Allgöwer, “Data-Driven Model Predictive Control With Stability and Robustness Guarantees,” in IEEE Transactions on Automatic Control, vol. 66, no. 4, pp. 1702-1717, April 2021, doi: 10.1109/TAC.2020.3000182.

simulate_nonlinear_data_driven_mpc_control_loop(system_model: NonlinearSystem, data_driven_mpc_controller: NonlinearDataDrivenMPCController, n_steps: int, np_random: Generator, verbose: int, callback: Callable[[int, NonlinearSystem, ndarray, ndarray, ndarray], None] | None = None) tuple[ndarray, ndarray][source]#

Simulate a Data-Driven MPC control loop applied to a nonlinear system and return the resulting input-output data sequences.

This function simulates the closed-loop operation of a Data-Driven MPC controller designed for nonlinear systems, following the Nonlinear Data-Driven MPC scheme described in Algorithm 1 of [2].

Parameters:
  • system_model (NonlinearSystem) – A NonlinearSystem instance representing a nonlinear system.

  • data_driven_mpc_controller (NonlinearDataDrivenMPCController) – A NonlinearDataDrivenMPCController instance representing a Data-Driven MPC controller designed for nonlinear systems.

  • n_steps (int) – The number of time steps for the simulation.

  • np_random (Generator) – A Numpy random number generator for generating random noise for the system’s output.

  • verbose (int) – The verbosity level: 0 = no output, 1 = minimal output, 2 = detailed output.

  • callback (Callable | None) – A function executed after each control step. It should follow the signature (step: int, system_model: NonlinearSystem, u_sys_k: np.ndarray, y_sys_k: np.ndarray, y_r: np.ndarray).

Returns:

tuple[np.ndarray, np.ndarray] – A tuple containing two arrays:

  • An array of shape (n_steps, m) representing the optimal control inputs applied to the system, where m is the number of control inputs.

  • An array of shape (n_steps, p) representing the output response of the system, where p is the number of system outputs.

References

[2] J. Berberich, J. Köhler, M. A. Müller and F. Allgöwer, “Linear Tracking MPC for Nonlinear Systems—Part II: The Data-Driven Case,” in IEEE Transactions on Automatic Control, vol. 67, no. 9, pp. 4406-4421, Sept. 2022, doi: 10.1109/TAC.2022.3166851.

print_mpc_step_info(verbose: int, step: int, mpc_cost_val: float, y_sys_k: ndarray, y_s: ndarray, u_sys_k: ndarray | None = None, u_s: ndarray | None = None, progress_bar: tqdm | None = None) None[source]#

Print MPC step information based on the verbosity level.

Parameters:
  • verbose (int) – The verbosity level. 1: Updates the progress bar with the current step information. 2: Prints detailed step information, including input and output errors.

  • step (int) – Current time step.

  • mpc_cost_val (float) – The current MPC cost value.

  • u_s (np.ndarray | None) – The input setpoint array. If None, input errors will not be printed. Defaults to None.

  • u_sys_k (np.ndarray | None) – The input vector for the current time step. If None, input errors will not be printed. Defaults to None.

  • y_s (numpy.ndarray) – The output setpoint array.

  • y_sys_k (numpy.ndarray) – The output vector for the current time step.

  • progress_bar (tqdm | None) – A progress bar displaying simulation progress information.