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.minimize(f: SX | MX, x: SX | MX) MinimizationProblemDescription[source]

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

class alpaqa.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, name: str = 'alpaqa_casadi_problem')[source]

High-level description of a minimization problem.

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

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

subject_to(g: SX | MX, D: ndarray | Tuple[ndarray, ndarray] | None = None) MinimizationProblemDescription[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) MinimizationProblemDescription[source]

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

with_l1_regularizer(λ: float | ndarray) MinimizationProblemDescription[source]

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

with_param(p: SX | MX, value: ndarray = None) MinimizationProblemDescription[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) MinimizationProblemDescription[source]

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

compile(**kwargs) CasADiProblem[source]

Generate, compile and load the problem.

A C compiler is required (e.g. GCC or Clang on Linux, Xcode on macOS, or Visual Studio on Windows). If no compiler is available, you could use the alpaqa.MinimizationProblemDescription.build() method instead.

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. SX expands the expressions and generally results in better run-time performance, while MX usually has faster compile times.

build(**kwargs) CasADiProblem[source]

Finalize the problem formulation and return a problem type that can be used by the solvers.

This method is usually not recommended: the alpaqa.MinimizationProblemDescription.compile() method is preferred because it pre-compiles the problem for better performance.

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.

  • sym: Callable – Symbolic variable constructor, usually either cs.SX.sym (default) or cs.MX.sym. SX expands the expressions and generally results in better run-time performance.