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 ¶
ssqpConvergenceData ¶
SSQP convergence data
loose_success
property
¶
Whether termination occurred due to loose criteria satisfaction.
constraint_success
property
¶
Whether termination occurred due to constraint success satisfaction only.
max_iter_reached
property
¶
Whether termination occurred due to the maximum iterations being reached.
time_limit_reached
property
¶
Whether termination occurred due to the time limit being reached.
trajectory_constraint_violation
property
¶
Total final trajectory constraint violation.
ssqpParams ¶
SSQP solver parameters.
max_time
property
writable
¶
Maximum solve time (in seconds)
Iterations expected to end past it are skipped
Use -1.0 to ignore
constraint_tolerance
property
writable
¶
Constraint satisfaction tolerance
If positive, defines a separate tolerance for constraints than the
general tolerance used for dx/du norms
tolerance_final
property
writable
¶
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
¶
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
¶
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
¶
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
¶
Tolerance for change in cost jacobian norms.
loose_success_stale_iters
property
writable
¶
Number of iterations for stale cost jacobian norms.
line_search_method
property
writable
¶
Which type of line search to use
Choose between:
- Filter line search
- Merit function line search
inv_alpha_scale_factor
property
writable
¶
Factor to divide α (step size) by each line search step.
accept_worse_update
property
writable
¶
Whether to update with min_alpha if it is reached
Automatically also skips regularization
skip_regularization
property
writable
¶
Whether to skip regularization step if line search fails
Will throw an exception instead
stop_on_qp_infeasibility
property
writable
¶
Whether to stop when the QP solver reports an infeasible QP
Otherwise ADMM skips infeasibility detection and runs as usual
admmParams ¶
adaptive_rho_tolerance
property
writable
¶
Factor by which rho must change to actually perform rho update.
rho_update_iter_freq
property
writable
¶
Number of iterations to wait before updating rho
Also affects checking for termination
abs_tolerance_final
property
writable
¶
Final absolute ADMM tolerance
This value will be reached after tolerance_update_steps ADMM steps
Use -1.0 to ignore
rel_tolerance_final
property
writable
¶
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
¶
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 infeasibility tolerance, relative to the change in y
Checked every rho_update_iter_freq iterations
Use -1.0 to ignore
warm_start
property
writable
¶
Whether to warm start ADMM with the unconstrained solution
Note: set to false if using Inverse Dynamics
reset_rho
property
writable
¶
Whether to reset the rho parameter between each new ADMM formulation
Note: setting to false may often cause oscillations
reset_y
property
writable
¶
Whether to reset the y parameter between each new ADMM formulation
Note: setting to false may often cause oscillations
hpipmParams ¶
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.
feedbackGain ¶
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.
feedbackGain ¶
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 ¶
loadTrajectory ¶
Load a previously generated SSQP trajectory from a file
Input:
filepath: The path for the trajectory file output byssqp::write
Returns: a pair of FlatVec for the full state and control vectors