High-level problem formulation#

This is the main API for defining optimization problems using CasADi expressions.

For examples, see the lasso and nonlinear regression examples.

alpaqa.pyapi.minimize.minimize(f: SX | MX, x: SX | MX) MinimizationProblemDescription[source]

Formulate a minimization problem with objective function \(f(x)\) and unknown variables \(x\).

class alpaqa.pyapi.minimize.MinimizationProblemDescription(objective_expr: SX | MX, variable: SX | MX, constraints_expr: SX | MX | None = None, penalty_constraints_expr: SX | MX | None = None, parameter: SX | MX | None = None, parameter_value: ndarray | None = None, regularizer: float | ndarray | None = None, bounds: Tuple[ndarray, ndarray] | None = None, constraints_bounds: Tuple[ndarray, ndarray] | None = None, penalty_constraints_bounds: Tuple[ndarray, ndarray] | None = None)[source]

High-level description of a minimization problem.

subject_to_box(C: Tuple[ndarray, ndarray])[source]

Add box constraints \(x \in C\) on the problem variables.

subject_to(g: SX | MX, D: ndarray | Tuple[ndarray, ndarray] | None = None)[source]

Add general constraints \(g(x) \in D\), handled using an augmented Lagrangian method.

subject_to_penalty(g: SX | MX, D: ndarray | Tuple[ndarray, ndarray] | None = None)[source]

Add general constraints \(g(x) \in D\), handled using a quadratic penalty method.

with_l1_regularizer(λ: float | ndarray)[source]

Add an \(\ell_1\)-regularization term \(\|\lambda x\|_1\) to the objective.

with_param(p: SX | MX, value: ndarray | None = None)[source]

Make the problem depend on a symbolic parameter, with an optional default value. The value can be changed after the problem has been loaded, as wel as in between solves.

with_param_value(value: ndarray)[source]

Explicitly change the parameter value for the parameter added by with_param().

compile(**kwargs) CasADiProblem[source]

Generate, compile and load the problem.

Parameters:

**kwargs – Arguments passed to alpaqa.casadi_loader.generate_and_compile_casadi_problem().

Keyword Arguments:
  • second_order: str – Whether to generate functions for evaluating second-order derivatives:

    • 'no': only first-order derivatives (default).

    • 'full': Hessians and Hessian-vector products of the Lagrangian and the augmented Lagrangian.

    • 'prod': Hessian-vector products of the Lagrangian and the augmented Lagrangian.

    • 'L': Hessian of the Lagrangian.

    • 'L_prod': Hessian-vector product of the Lagrangian.

    • 'psi': Hessian of the augmented Lagrangian.

    • 'psi_prod': Hessian-vector product of the augmented Lagrangian.

  • name: str – Optional string description of the problem (used for filenames).

  • sym: Callable – Symbolic variable constructor, usually either cs.SX.sym (default) or cs.MX.sym.