DeePC#

class do_dpc.dpc.deepc.DeePC(dpc_params, training_data)[source]#

Bases: DPC

Implements DeePC based on DPC.

g_cp#

Slack decision variable used in the optimization.

Type:

cp.Variable

sigma_cp#

Slack parameter, needed for feasibility in the presence of noise.

Type:

cp.Parameter

specific_params#

Stores tunable parameters for the controller.

Type:

DeePCSpecificParameters

specific_params_set#

Flag indicating whether tunable parameters have been set.

Type:

bool

Methods#

add_custom_constraints#

do_dpc.dpc.deepc.DeePC.add_custom_constraints(self, constraints)#

Adds custom constraints to the optimization problem.

Note

  • Users should access cvxpy parameters and decision variables directly from the DPC class.

  • All such attributes are denoted by the _cp suffix.

  • Ensure that added constraints do not conflict with existing ones.

  • For simple linear inequality constraints, prefer using set_input_constraint or set_output_constraint.

Parameters:

constraints (list[Constraint]) – A list of cvxpy constraints.

add_input_constraints#

do_dpc.dpc.deepc.DeePC.add_input_constraints(self, u_bounds)#

Sets input constraints based on provided bounds.

Parameters:

u_bounds (Bounds) – An instance of Bounds containing upper (max_values) and lower (min_values) constraints for the control inputs.

Raises:
  • ValueError – If u_bounds.max_values and u_bounds.min_values have incorrect shapes.

  • ValueError – If u_bounds.max_values is smaller than u_bounds.min_values.

Special Cases:
  • To impose no bounds on specific inputs, set np.inf as the upper bound and -np.inf as the lower bound.

add_linear_constraints#

do_dpc.dpc.deepc.DeePC.add_linear_constraints(self, A, b)#

Adds linear inequality constraints to the optimization problem.

The constraints are applied in the form:

A @ [ y_f u_f ]^T <= b

where:
  • A is a matrix of shape (n_constraints, n_y_f + n_u_f)

  • y_f (future outputs) is of shape (n_y_f, )

  • u_f (future inputs) is of shape (n_u_f, )

  • b is a vector of shape (n_constraints, )

Parameters:
  • A (np.ndarray) – Constraint matrix of shape (n_constraints, n_y_f + n_u_f).

  • b (np.ndarray) – Constraint vector of shape (n_constraints, ).

Raises:
  • ValueError – If A and b have incompatible shapes.

  • TypeError – If A or b are not numpy arrays.

  • Warning – If the first p columns of A are nonzero, indicating constraints on the first outputs.

add_terminal_output_constraints#

do_dpc.dpc.deepc.DeePC.add_terminal_output_constraints(self, y_bounds)#

Adds terminal output constraints for the final step of the prediction horizon.

Notes

  • Only the final predicted output in the finite future horizon is constrained.

  • Due to system lag, immediate output constraints may not always be enforceable.

  • This design choice enhances solver feasibility for a wide range of systems.

  • If stricter constraints are needed, use add_custom_constraints.

Parameters:

y_bounds (Bounds) – A Bounds instance defining upper (max_values) and lower (min_values) constraints for system outputs.

Raises:
  • ValueError – If y_bounds.max_values and y_bounds.min_values have incorrect shapes.

  • ValueError – If any element in y_bounds.max_values is smaller than its corresponding y_bounds.min_values.

Special Cases:
  • To impose no bounds on specific outputs, set np.inf as the upper bound and -np.inf as the lower bound.

build_optimization_problem#

do_dpc.dpc.deepc.DeePC.build_optimization_problem(self)#
Raises:

Warning – If tunable parameters have not been explicitly set using set_specific_parameters().

calculate_closed_form_solution_matrices#

do_dpc.dpc.deepc.DeePC.calculate_closed_form_solution_matrices(self)#

Computes the closed-form gain matrices.

Returns:

The computed gain matrices if conditions are met; otherwise, None.

Return type:

Optional[DPCClosedFormSolutionMatrices]

Conditions:
  • If lambda_g_1 is nonzero, return None (1-norm differentiation issue).

  • If lambda_sigma is infinite, return None.

  • If lambda_p is zero, warning.

calculate_predictor_matrices#

do_dpc.dpc.deepc.DeePC.calculate_predictor_matrices(self)#

DeePC does not have any predictor matrices

Return type:

DeePCPredictorMatrices

calculate_regularization_matrices#

do_dpc.dpc.deepc.DeePC.calculate_regularization_matrices(self)#

Computes the regularization matrix for the DeePC controller.

Return type:

DeePCRegularizationMatrices

Returns:

DeePCRegularizationMatrices

get_next_control_action#

do_dpc.dpc.deepc.DeePC.get_next_control_action(self)#

Retrieves the next computed control input.

Returns:

The next control input of shape (m,).

Return type:

np.ndarray

Raises:
  • IndexError – If the control horizon is exceeded.

  • RuntimeError – If the optimization problem has not been solved or the solution is invalid.

get_predictor_constraint_expression#

do_dpc.dpc.deepc.DeePC.get_predictor_constraint_expression(self)#
Returns:

CVXPY constraints for u_f and y_f depending on the Hankel matrices and g.

Return type:

cp.Constraint

get_regularization_cost_expression#

do_dpc.dpc.deepc.DeePC.get_regularization_cost_expression(self)#

Calculates and returns the CVXPY expression for the regularization cost.

The regularization cost is calculated as follows:

\[r = \lambda_{g_1} \|g\|_1 + \lambda_{g_2} \|g\|_2^2 + \lambda_p \|I - \Pi g\|_2^2 + \lambda_{\sigma} \|\sigma\|_2^2\]
Returns:

The CVXPY expression for the regularization cost.

Return type:

cp.Expression

instantiate#

do_dpc.dpc.deepc.DeePC.instantiate(dpc_type, *args, **kwargs)#

Factory method to create an instance of a registered DPC subclass.

Parameters:
  • dpc_type (str) – The type of DPC controller to instantiate.

  • *args – Positional arguments for the subclass constructor.

  • **kwargs – Keyword arguments for the subclass constructor.

Returns:

An instance of the corresponding DPC subclass.

Return type:

DPC

Raises:

ValueError – If the specified dpc_type is not registered.

register#

do_dpc.dpc.deepc.DeePC.register(dpc_type)#

Decorator to register subclasses for dynamic instantiation.

Usage:

@DPC.register(“my_dpc”) class MyDPC(DPC):

Parameters:

dpc_type (str) – Name of the DPC subclass type.

Returns:

The decorator function.

Return type:

Callable[[Type[“DPC”]], Type[“DPC”]]

reset_constraints#

do_dpc.dpc.deepc.DeePC.reset_constraints(self)#

Removes all existing constraints from the optimization problem.

Return type:

None

set_specific_parameters#

do_dpc.dpc.deepc.DeePC.set_specific_parameters(self, specific_params)#

Sets the specific parameters for the DeePC controller.

Note

The closed-form data will be recalculated as the matrices depend on lambda_.

Parameters:

specific_params (DeePCSpecificParameters) – DeePCSpecificParameters

set_state_x#

do_dpc.dpc.deepc.DeePC.set_state_x(self, x_new)#

Sets the state (x) for the estimated model.

This method is intended to be overridden by subclasses that have a model, such as MPC variants.

solve#

do_dpc.dpc.deepc.DeePC.solve(self, verbose=False, solver='SCS', **kwargs)#

Solves the optimization problem to calculate the optimal control input.

Recommended to use SCS as it does not require a license. MOSEK should be used for better performance if a license is available.

Parameters:
  • verbose (bool) – If True, solver output is displayed.

  • solver (str) – Solver to use (default: SCS).

  • **kwargs – Additional solver parameters.

Raises:
  • ValueError – If the optimization problem is not properly built.

  • ValueError – If the cf_matrices are None while using the closed-form solution.

  • RuntimeError – If the solver encounters an issue or produces an infeasible result.

  • Warning – If another solver than Mosek is used.

update_past_measurements#

do_dpc.dpc.deepc.DeePC.update_past_measurements(self, z_p_new)#

Updates the stored past measurements with new incoming data.

Parameters:

z_p_new (np.ndarray) – New past measurement data (shape (mp,)).

Raises:

ValueError – If z_p_new does not match the expected shape.

update_tracking_reference#

do_dpc.dpc.deepc.DeePC.update_tracking_reference(self, y_r_new, u_r_new)#

Updates the tracking reference trajectory.

Parameters:
  • y_r_new (np.ndarray) – New reference trajectory for outputs (shape (p,)).

  • u_r_new (np.ndarray) – New reference trajectory for inputs (shape (m,)).

Raises:
  • ValueError – If y_r_new does not match expected dimensions (p,).

  • ValueError – If u_r_new does not match expected dimensions (m,).