CasADi Interface#

For most purposes, it is recommended to use the the high-level problem API to compose optimization problems using CasADi. However, in some cases, you may want access to the alpaqa─CasADi interface directly. This lower-level interface is documented here.

alpaqa.casadi_generator.generate_casadi_problem(f: ~casadi.casadi.Function, g: ~casadi.casadi.Function | None, second_order: ~typing.Literal['no', 'full', 'prod', 'L', 'L_prod', 'psi', 'psi_prod'] = 'no', name: str = 'alpaqa_problem', sym: ~typing.Callable = <function GenSX.sym>) CodeGenerator[source]

Convert the objective and constraint functions into a CasADi code generator.

Parameters:
  • f – Objective function.

  • g – Constraint function.

  • second_order – Whether to generate functions for evaluating Hessians.

  • name – Optional string description of the problem (used for filename).

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

Returns:

Code generator that generates the functions and derivatives used by the solvers.

alpaqa.casadi_generator.generate_casadi_control_problem(f: Function, l: Function, l_N: Function, h: Function | None = None, h_N: Function | None = None, c: Function | None = None, c_N: Function | None = None, name: str = 'alpaqa_control_problem') CodeGenerator[source]

Convert the dynamics and cost functions into a CasADi code generator.

Parameters:
  • f – Dynamics.

  • name – Optional string description of the problem (used for filename).

Returns:

Code generator that generates the functions and derivatives used by the solvers.

alpaqa.casadi_generator.write_casadi_problem_data(sofile, C, D, param, l1_reg, penalty_alm_split)[source]
alpaqa.casadi_generator.write_casadi_control_problem_data(sofile, U, D, D_N, x_init, param)[source]
alpaqa.casadi_loader.generate_and_compile_casadi_problem(f: Function, g: Function, *, C=None, D=None, param=None, l1_reg=None, penalty_alm_split=None, second_order: Literal['no', 'full', 'prod', 'L', 'L_prod', 'psi', 'psi_prod'] = 'no', name: str = 'alpaqa_problem', **kwargs) CasADiProblem[source]

Compile the objective and constraint functions into a alpaqa Problem.

Parameters:
  • f – Objective function f(x).

  • g – Constraint function g(x).

  • C – Bound constraints on x.

  • D – Bound constraints on g(x).

  • param – Problem parameter values.

  • l1_reg – L1-regularization on x.

  • penalty_alm_split – This many components at the beginning of g(x) are handled using a quadratic penalty method rather than an augmented Lagrangian method.

  • second_order – Whether to generate functions for evaluating Hessians.

  • name – Optional string description of the problem (used for filename).

  • kwargs – Parameters passed to casadi_generator.generate_casadi_problem().

Returns:

Problem specification that can be passed to the solvers.

alpaqa._alpaqa.float64.load_casadi_problem(so_name: str) alpaqa._alpaqa.float64.CasADiProblem

Load a compiled CasADi problem.

class alpaqa._alpaqa.float64.CasADiProblem

C++ documentation: alpaqa::CasADiProblem

See alpaqa._alpaqa.float64.Problem for the full documentation.

__init__(self: alpaqa._alpaqa.float64.CasADiProblem, other: alpaqa._alpaqa.float64.CasADiProblem) None

Create a copy

eval_f(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]]) float
eval_f_grad_f(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], grad_fx: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) float
eval_g(*args, **kwargs)

Overloaded function.

  1. eval_g(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], gx: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> None

  2. eval_g(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]

eval_grad_L(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], grad_L: numpy.ndarray[numpy.float64[m, 1], flags.writeable], work_n: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) None
eval_grad_f(*args, **kwargs)

Overloaded function.

  1. eval_grad_f(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], grad_fx: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> None

  2. eval_grad_f(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]

eval_grad_g_prod(*args, **kwargs)

Overloaded function.

  1. eval_grad_g_prod(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], grad_gxy: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> None

  2. eval_grad_g_prod(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]

eval_grad_gi(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], i: int, grad_gi: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) None
eval_grad_ψ(*args, **kwargs)

Overloaded function.

  1. eval_grad_ψ(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]], grad_ψ: numpy.ndarray[numpy.float64[m, 1], flags.writeable], work_n: numpy.ndarray[numpy.float64[m, 1], flags.writeable], work_m: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> None

  2. eval_grad_ψ(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]

eval_hess_L_prod(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], scale: float, v: numpy.ndarray[numpy.float64[m, 1]], Hv: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) None
eval_hess_ψ_prod(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]], scale: float, v: numpy.ndarray[numpy.float64[m, 1]], Hv: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) None
eval_inactive_indices_res_lna(*args, **kwargs)

Overloaded function.

  1. eval_inactive_indices_res_lna(self: alpaqa._alpaqa.float64.CasADiProblem, γ: float, x: numpy.ndarray[numpy.float64[m, 1]], grad_ψ: numpy.ndarray[numpy.float64[m, 1]], J: numpy.ndarray[numpy.int64[m, 1], flags.writeable]) -> int

  2. eval_inactive_indices_res_lna(self: alpaqa._alpaqa.float64.CasADiProblem, γ: float, x: numpy.ndarray[numpy.float64[m, 1]], grad_ψ: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.int64[m, 1]]

eval_proj_diff_g(*args, **kwargs)

Overloaded function.

  1. eval_proj_diff_g(self: alpaqa._alpaqa.float64.CasADiProblem, z: numpy.ndarray[numpy.float64[m, 1]], e: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> None

  2. eval_proj_diff_g(self: alpaqa._alpaqa.float64.CasADiProblem, z: numpy.ndarray[numpy.float64[m, 1]]) -> numpy.ndarray[numpy.float64[m, 1]]

eval_proj_multipliers(self: alpaqa._alpaqa.float64.CasADiProblem, y: numpy.ndarray[numpy.float64[m, 1], flags.writeable], M: float) None
eval_prox_grad_step(*args, **kwargs)

Overloaded function.

  1. eval_prox_grad_step(self: alpaqa._alpaqa.float64.CasADiProblem, γ: float, x: numpy.ndarray[numpy.float64[m, 1]], grad_ψ: numpy.ndarray[numpy.float64[m, 1]], x_hat: numpy.ndarray[numpy.float64[m, 1], flags.writeable], p: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> float

  2. eval_prox_grad_step(self: alpaqa._alpaqa.float64.CasADiProblem, γ: float, x: numpy.ndarray[numpy.float64[m, 1]], grad_ψ: numpy.ndarray[numpy.float64[m, 1]]) -> Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], float]

eval_ψ(*args, **kwargs)

Overloaded function.

  1. eval_ψ(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]], ŷ: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> float

  2. eval_ψ(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]]) -> Tuple[float, numpy.ndarray[numpy.float64[m, 1]]]

eval_ψ_grad_ψ(*args, **kwargs)

Overloaded function.

  1. eval_ψ_grad_ψ(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]], grad_ψ: numpy.ndarray[numpy.float64[m, 1], flags.writeable], work_n: numpy.ndarray[numpy.float64[m, 1], flags.writeable], work_m: numpy.ndarray[numpy.float64[m, 1], flags.writeable]) -> float

  2. eval_ψ_grad_ψ(self: alpaqa._alpaqa.float64.CasADiProblem, x: numpy.ndarray[numpy.float64[m, 1]], y: numpy.ndarray[numpy.float64[m, 1]], Σ: numpy.ndarray[numpy.float64[m, 1]]) -> Tuple[float, numpy.ndarray[numpy.float64[m, 1]]]

get_box_C(self: alpaqa._alpaqa.float64.CasADiProblem) alpaqa._alpaqa.float64.Box
get_box_D(self: alpaqa._alpaqa.float64.CasADiProblem) alpaqa._alpaqa.float64.Box
property param

Parameter vector \(p\) of the problem

provides_eval_grad_gi(self: alpaqa._alpaqa.float64.CasADiProblem) bool
provides_eval_hess_L_prod(self: alpaqa._alpaqa.float64.CasADiProblem) bool
provides_eval_hess_ψ_prod(self: alpaqa._alpaqa.float64.CasADiProblem) bool