Skip to content

ssqpy.solvers

solvers

Submodule containing classes related to the SSQP solvers.

SolverState

Bases: Enum

The state of the solver.
States:

  • Success: Convergence was achieved.
  • Loose Success: Solver stopped after loose success tolerance was reached.
  • Constraint Success: Solver stopped after constraints were satisfied (with relevant option enabled).
  • Primal Infeasible: A QP subproblem was detected as primal infeasible (ADMM only).
  • Max Iter Reached: Maximum number of iterations reached before convergence was achieved.
  • Time Limit Reached: Maximum solve time reached before convergence was achieved.
  • Ongoing: The solver is ongoing.

LineSearchMethod

Bases: Enum

The line search method to use for the SSQP update step.
Available line search methods:

  • Filter line search: Accepts an update if there is an improvement in any of the three criteria functions (norm, gap or violation)
  • Merit function line search: Uses a merit function that is a weighted sum of each of the three criteria functions and its gradient to determine the update step

QPSolverType

Bases: Enum

The solver type to use to solve the QP at each step.
Available solvers:

  • ADMM: The custom ADMM implementation.
  • HPIPM: The HPIPM interior point solver, using the HPIPM library.

HPIPMMode

Bases: Enum

The HPIPM solver mode.
Available modes:

  • Robust
  • Speed
  • Balance

ssqpIterationConvergenceData

SSQP iteration convergence data.

qp_iters property

qp_iters

Number of QP solver iterations.

qp_duration property

qp_duration

QP solver runtime (us).

iter_duration property

iter_duration

Total SSQP iteration duration (us).

step_size property

step_size

Line search step size.

norm_dx property

norm_dx

Norm of lagrangian's derivative with respect to x after update.

norm_du property

norm_du

Norm of lagrangian's derivative with respect to u after update.

trajectory_cost property

trajectory_cost

Total current trajectory cost

trajectory_stage_gap property

trajectory_stage_gap

Total current trajectory stage gap.

trajectory_constraint_violation property

trajectory_constraint_violation

Total current trajectory constraint violation.

first_violation_stage property

first_violation_stage

First stage where a gap/constraint is violated.

violation property

violation

Violation at first violation stage.

gap_violations property

gap_violations

Gap violations per stage.

constraint_violations property

constraint_violations

Constraint violations per stage.

print

print()

Print iteration convergence data.

ssqpConvergenceData

SSQP convergence data

iteration_data property

iteration_data

Iteration convergence data.

total_duration property

total_duration

SSQP solver runtime (us).

iterations property

iterations

Number of SSQP solver iterations.

loose_success property

loose_success

Whether termination occurred due to loose criteria satisfaction.

constraint_success property

constraint_success

Whether termination occurred due to constraint success satisfaction only.

max_iter_reached property

max_iter_reached

Whether termination occurred due to the maximum iterations being reached.

time_limit_reached property

time_limit_reached

Whether termination occurred due to the time limit being reached.

trajectory_cost property

trajectory_cost

Total final trajectory cost

trajectory_stage_gap property

trajectory_stage_gap

Total final trajectory stage gap.

trajectory_constraint_violation property

trajectory_constraint_violation

Total final trajectory constraint violation.

print

print()

Print convergence data.

ssqpParams

SSQP solver parameters.

max_iter property writable

max_iter

Maximum number of SSQP iterations.

max_time property writable

max_time

Maximum solve time (in seconds)
Iterations expected to end past it are skipped
Use -1.0 to ignore

tolerance property writable

tolerance

(Initial) Tolerance for lagrangian jacobian norms.

constraint_tolerance property writable

constraint_tolerance

Constraint satisfaction tolerance
If positive, defines a separate tolerance for constraints than the
general tolerance used for dx/du norms

tolerance_final property writable

tolerance_final

Final tolerance for lagrangian jacobian norms
This value will be reached after tolerance_update_steps SSQP steps
Use -1.0 to ignore

tolerance_update_steps property writable

tolerance_update_steps

Number of steps to go from tolerance to tolerance_final
Updates are done linearly per step
Ignored if tolerance_final is -1.0

stop_after_constraint_satisfaction property writable

stop_after_constraint_satisfaction

Whether to stop the SSQP solver after the constraints and stage gaps have been satisfied.
This will stop the solver regardless of the lagrangian jacobian norm values.

loose_success property writable

loose_success

Whether to enable loose success
Loose success will terminate if there are no updates for
loose_success_stale_iters that are larger than
loose_success_tolerance

loose_success_tolerance property writable

loose_success_tolerance

Tolerance for change in cost jacobian norms.

loose_success_stale_iters property writable

loose_success_stale_iters

Number of iterations for stale cost jacobian norms.

line_search_method property writable

line_search_method

Which type of line search to use
Choose between:

  • Filter line search
  • Merit function line search

filter_size property writable

filter_size

Size of filter history.

merit_mu_gamma property writable

merit_mu_gamma

Weight for stage gap term

merit_mu_c property writable

merit_mu_c

Weight for constraint violation term.

merit_armijo_beta property writable

merit_armijo_beta

Factor for gradient of merit function.

inv_alpha_scale_factor property writable

inv_alpha_scale_factor

Factor to divide α (step size) by each line search step.

min_alpha property writable

min_alpha

Minimum α (step size) value.

accept_worse_update property writable

accept_worse_update

Whether to update with min_alpha if it is reached
Automatically also skips regularization

skip_regularization property writable

skip_regularization

Whether to skip regularization step if line search fails
Will throw an exception instead

stop_on_qp_infeasibility property writable

stop_on_qp_infeasibility

Whether to stop when the QP solver reports an infeasible QP
Otherwise ADMM skips infeasibility detection and runs as usual

qp_solver_type property writable

qp_solver_type

The type of QP solver to use.

admmParams property writable

admmParams

Parameters for the ADMM QP solver.

hpipmParams property writable

hpipmParams

Parameters for the HPIPM QP solver.

admmParams

admmParams()

init_rho property writable

init_rho

Initial rho value.

alpha property writable

alpha

Over-relaxation parameter.

sigma property writable

sigma

Proximal regularization parameter.

rho_update property writable

rho_update

Whether to perform rho update.

rho_min property writable

rho_min

Minimum possible rho value.

rho_max property writable

rho_max

Maximum possible rho value.

adaptive_rho_tolerance property writable

adaptive_rho_tolerance

Factor by which rho must change to actually perform rho update.

rho_update_iter_freq property writable

rho_update_iter_freq

Number of iterations to wait before updating rho
Also affects checking for termination

max_iter property writable

max_iter

Maximum number of ADMM iterations.

abs_tolerance property writable

abs_tolerance

Absolute ADMM tolerance.

abs_tolerance_final property writable

abs_tolerance_final

Final absolute ADMM tolerance
This value will be reached after tolerance_update_steps ADMM steps
Use -1.0 to ignore

rel_tolerance property writable

rel_tolerance

Relative ADMM tolerance.

rel_tolerance_final property writable

rel_tolerance_final

Final relative ADMM tolerance
This value will be reached after tolerance_update_steps ADMM steps
Use -1.0 to ignore

tolerance_update_steps property writable

tolerance_update_steps

Number of steps to go from initial to final tolerances
Updates are done linearly per step
Ignored (per tolerance) if tolerance is -1.0

primal_infs_tolerance property writable

primal_infs_tolerance

Primal infeasibility tolerance, relative to the change in y
Checked every rho_update_iter_freq iterations
Use -1.0 to ignore

warm_start property writable

warm_start

Whether to warm start ADMM with the unconstrained solution
Note: set to false if using Inverse Dynamics

reset_rho property writable

reset_rho

Whether to reset the rho parameter between each new ADMM formulation
Note: setting to false may often cause oscillations

reset_y property writable

reset_y

Whether to reset the y parameter between each new ADMM formulation
Note: setting to false may often cause oscillations

hpipmParams

hpipmParams()

mode property writable

mode

The HPIPM solver mode.

alpha_min property writable

alpha_min

The minimum step size.

mu0 property writable

mu0

The initial barrier parameter.

max_iter property writable

max_iter

Maximum number of HPIPM iterations.

reg_prim property writable

reg_prim

The regularization term.

warm_start property writable

warm_start

Whether to warm start.

prediction_correction property writable

prediction_correction

Whether to perform prediction correction.

square_root_riccati property writable

square_root_riccati

Whether to use the square root riccati algorithm.

split_step property writable

split_step

Whether to use different step for primal and dual variables.

ssqp

Defines an SSQP problem solver based on a given SSQP model and the desired
parameters.

SSQP is a Structure-exploiting Sequential Quadratic Programming solver.
The solver starts with an initial guess (either provided, or zero) for the
states (x) and controls (u) of an optimization problem over a time horizon H.

At each step, SSQP constructs a Quadratic Program at the current SSQP guess
with a quadratic cost function and linearized constraints. This is done using
the SSQP model, a model of the system being optimized which provides the
necessary methods to linearize at each guess, like gradients and hessians.

The solver then utilizes a QP solver to produce a solution to the constructed
QP, which can act as an update step for the current SSQP guess. Based on this
solution, a line search method is used to update the current guess.

Termination criteria are then checked for the new SSQP guess. The process is
repeated until convergence is reached.

solve

solve()

Solve the defined problem using SSQP.

write

write(filepath)

Write the current solution to the output file at the provided path.

getConvergenceData

getConvergenceData()

Get the SSQP solver's convergence data (after solving).

setReducedOutput

setReducedOutput(arg)

Set the reduced SSQP output flag.

feedbackGain

feedbackGain(stage)

Feedback gain K (nu-by-nx) of the last QP at the given stage, giving
the change du = K dx of the stage's controls for a change dx of its
state. dx is in the tangent space of the dynamics, as returned by
state_right_minus.

HPIPM returns the Riccati gain of its last interior point iteration.
ADMM returns the gain of its final LQR, which also penalizes inactive
constraints, so it is stiffer.

MPC

MPC(model, ssqp_params=..., *, sqp_iters=5, qp_iters=50, max_time=-1.0, keep_convergence_data=False)

Helper class which utilizes SSQP to perform MPC for real-time SSQP-based
control.

Repeatedly uses SSQP with low iterations to solve a problem for the current
state of a system, applies the first of the generated controls, updates
the initial guess using feedback from the system and a warm start using the
previous solution and repeats the process.

Initialize an MPC helper for the given model, the given MPC, SSQP and
QP parameters.
Note that the max iterations used for SSQP and the QP solver, and the
SSQP time limit (max_time, in seconds), will be determined by the MPC
parameters only.

getConvergenceData

getConvergenceData()

Returns stored convergence data

feedbackGain

feedbackGain(stage)

Feedback gain K (nu-by-nx) of the last step at the given stage, giving
the change du = K dx of the stage's controls for a change dx of its
state. dx is in the tangent space of the dynamics, as returned by
state_right_minus. Between steps, it corrects the first stage's
controls for the measured state:
u = u.stage(0) + K @ dynamics.state_right_minus(state, x.stage(0))

HPIPM returns the Riccati gain of its last interior point iteration.
ADMM returns the gain of its final LQR, which also penalizes inactive
constraints, so it is stiffer.

FlatVec

Flattened vector of all stage data.

stage

stage(k)

Return the vector for a given stage.

stages

stages()

Return the total number of stages.

print

print()

Output the flattened vector to the terminal.

toarray

toarray()

Return the flattened vector as a list of arrays.

loadTrajectory

loadTrajectory(filepath)

Load a previously generated SSQP trajectory from a file
Input:

  • filepath: The path for the trajectory file output by ssqp::write

Returns: a pair of FlatVec for the full state and control vectors