KKT systems
MadNLP manipulates KKT systems using two abstractions: an AbstractKKTSystem storing the KKT system' matrix and an AbstractKKTVector storing the KKT system's right-hand-side.
AbstractKKTSystem
MadNLP.AbstractKKTSystem — Type
AbstractKKTSystem{T, VT<:AbstractVector{T}, MT<:AbstractMatrix{T}, QN<:AbstractHessian{T, VT}}Abstract type for KKT system.
MadNLP implements three different types of AbstractKKTSystem, depending how far we reduce the KKT system.
MadNLP.AbstractUnreducedKKTSystem — Type
AbstractUnreducedKKTSystem{T, VT, MT, QN} <: AbstractKKTSystem{T, VT, MT, QN}Augmented KKT system associated to the linearization of the KKT conditions at the current primal-dual iterate $(x, s, y, z, ν, w)$.
The associated matrix is
[Wₓₓ 0 Aₑ' Aᵢ' V½ 0 ] [Δx]
[0 0 0 -I 0 W½ ] [Δs]
[Aₑ 0 0 0 0 0 ] [Δy]
[Aᵢ -I 0 0 0 0 ] [Δz]
[V½ 0 0 0 -X 0 ] [Δτ]
[0 W½ 0 0 0 -S ] [Δρ]with
- $Wₓₓ$: Hessian of the Lagrangian.
- $Aₑ$: Jacobian of the equality constraints
- $Aᵢ$: Jacobian of the inequality constraints
- $X = diag(x)$
- $S = diag(s)$
- $V = diag(ν)$
- $W = diag(w)$
- $Δτ = -W^{-½}Δν$
- $Δρ = -W^{-½}Δw$
MadNLP.AbstractReducedKKTSystem — Type
AbstractReducedKKTSystem{T, VT, MT, QN} <: AbstractKKTSystem{T, VT, MT, QN}The reduced KKT system is a simplification of the original Augmented KKT system. Compared to AbstractUnreducedKKTSystem, AbstractReducedKKTSystem removes the two last rows associated to the bounds' duals $(ν, w)$.
At a primal-dual iterate $(x, s, y, z)$, the matrix writes
[Wₓₓ + Σₓ 0 Aₑ' Aᵢ'] [Δx]
[0 Σₛ 0 -I ] [Δs]
[Aₑ 0 0 0 ] [Δy]
[Aᵢ -I 0 0 ] [Δz]with
- $Wₓₓ$: Hessian of the Lagrangian.
- $Aₑ$: Jacobian of the equality constraints
- $Aᵢ$: Jacobian of the inequality constraints
- $Σₓ = X⁻¹ V$
- $Σₛ = S⁻¹ W$
MadNLP.AbstractCondensedKKTSystem — Type
AbstractCondensedKKTSystem{T, VT, MT, QN} <: AbstractKKTSystem{T, VT, MT, QN}The condensed KKT system simplifies further the AbstractReducedKKTSystem by removing the rows associated to the slack variables $s$ and the inequalities.
At the primal-dual iterate $(x, y)$, the matrix writes
[Wₓₓ + Σₓ + Aᵢ' Σₛ Aᵢ Aₑ'] [Δx]
[ Aₑ 0 ] [Δy]with
- $Wₓₓ$: Hessian of the Lagrangian.
- $Aₑ$: Jacobian of the equality constraints
- $Aᵢ$: Jacobian of the inequality constraints
- $Σₓ = X⁻¹ V$
- $Σₛ = S⁻¹ W$
Each AbstractKKTSystem follows the interface described below:
MadNLP.create_kkt_system — Function
create_kkt_system(
::Type{KKT},
cb::AbstractCallback,
linear_solver::Type{LinSol};
opt_linear_solver=default_options(linear_solver),
hessian_approximation=ExactHessian,
qn_options=QuasiNewtonOptions(),
) where {KKT<:AbstractKKTSystem, LinSol<:AbstractLinearSolver}Instantiate a new KKT system with type KKT, associated to the nonlinear program encoded inside the callback cb. The callback also stores the indexes of the equality and inequality constraints and of the variables' bounds. In addition, the user should pass the linear solver linear_solver that will be used to solve the KKT system after it has been assembled.
MadNLP.num_variables — Function
Number of primal variables (including slacks) associated to the KKT system.
MadNLP.get_kkt — Function
get_kkt(kkt::AbstractKKTSystem)::AbstractMatrixReturn a pointer to the KKT matrix implemented in kkt. The pointer is passed afterward to a linear solver.
MadNLP.get_jacobian — Function
Get Jacobian matrix
MadNLP.get_hessian — Function
Get Hessian matrix
MadNLP.initialize! — Function
initialize!(kkt::AbstractKKTSystem)Initialize KKT system with default values. Called when we initialize the MadNLPSolver storing the current KKT system kkt.
MadNLP.build_kkt! — Function
build_kkt!(kkt::AbstractKKTSystem)Assemble the KKT matrix before calling the factorization routine.
MadNLP.factorize_kkt! — Function
factorize_kkt!(kkt::AbstractKKTSystem)Factorize the KKT matrix using the linear solver stored in kkt.
MadNLP.solve_kkt! — Function
solve_kkt!(kkt::AbstractKKTSystem, w::AbstractKKTVector)Solve the KKT system $K x = w$ with the linear solver stored inside kkt and stores the result inplace inside the AbstractKKTVector w.
MadNLP.compress_hessian! — Function
compress_hessian!(kkt::AbstractKKTSystem)Compress the Hessian inside kkt's internals. This function is called every time a new Hessian is evaluated.
Default implementation does nothing.
MadNLP.compress_jacobian! — Function
compress_jacobian!(kkt::AbstractKKTSystem)Compress the Jacobian inside kkt's internals. This function is called every time a new Jacobian is evaluated.
By default, the function updates in the Jacobian the coefficients associated to the slack variables.
MadNLP.jtprod! — Function
jtprod!(y::AbstractVector, kkt::AbstractKKTSystem, x::AbstractVector)Multiply with transpose of Jacobian and store the result in y, such that $y = A' x$ (with $A$ current Jacobian).
MadNLP.regularize_diagonal! — Function
regularize_diagonal!(kkt::AbstractKKTSystem, primal_values::Number, dual_values::Number)Regularize the values in the diagonal of the KKT system in an incremental fashion. Called internally inside the interior-point routine.
MadNLP.is_inertia_correct — Function
is_inertia_correct(kkt::AbstractKKTSystem, n::Int, m::Int, p::Int)Check if the inertia $(n, m, p)$ returned by the linear solver is adapted to the KKT system implemented in kkt.
MadNLP.should_regularize_dual — Function
should_regularize_dual(kkt::AbstractKKTSystem, num_pos, num_zero, num_neg)Check if the inertia $(num_pos, num_zero, num_neg)$ returned by the linear solver necessitates the dual regularization of the KKT system.
MadNLP.nnz_jacobian — Function
Nonzero in Jacobian
Sparse KKT systems
By default, MadNLP stores a AbstractReducedKKTSystem in sparse format, as implemented by SparseKKTSystem:
MadNLP.SparseKKTSystem — Type
SparseKKTSystem{T, VT, MT, QN} <: AbstractReducedKKTSystem{T, VT, MT, QN}Implement the AbstractReducedKKTSystem in sparse COO format.
The user has the alternative choices:
MadNLP.SparseUnreducedKKTSystem — Type
SparseUnreducedKKTSystem{T, VT, MT, QN} <: AbstractUnreducedKKTSystem{T, VT, MT, QN}Implement the AbstractUnreducedKKTSystem in sparse COO format.
MadNLP.SparseCondensedKKTSystem — Type
SparseCondensedKKTSystem{T, VT, MT, QN} <: AbstractCondensedKKTSystem{T, VT, MT, QN}Implement the AbstractCondensedKKTSystem in sparse COO format.
MadNLP.ScaledSparseKKTSystem — Type
ScaledSparseKKTSystem{T, VT, MT, QN} <: AbstractReducedKKTSystem{T, VT, MT, QN}Scaled version of the AbstractReducedKKTSystem (using the K2.5 formulation introduced in [GOS]).
The K2.5 formulation of the augmented KKT system has a better conditioning than the original (K2) formulation. It is recommended to switch to a ScaledSparseKKTSystem if you encounter numerical difficulties in MadNLP.
At a primal-dual iterate $(x, s, y, z)$, the matrix writes
[√Ξₓ Wₓₓ √Ξₓ + Δₓ 0 √Ξₓ Aₑ' √Ξₓ Aᵢ'] [√Ξₓ⁻¹ Δx]
[0 Δₛ 0 -√Ξₛ ] [√Ξₛ⁻¹ Δs]
[Aₑ√Ξₓ 0 0 0 ] [Δy ]
[Aᵢ√Ξₓ -√Ξₛ 0 0 ] [Δz ]with
- $Wₓₓ$: Hessian of the Lagrangian.
- $Aₑ$: Jacobian of the equality constraints
- $Aᵢ$: Jacobian of the inequality constraints
- $Δₓ = Xᵤ Zₗˣ + Xₗ Zᵤˣ$
- $Δₛ = Sᵤ Zₗˢ + Sₗ Zᵤˢ$
- $Ξₓ = Xₗ Xᵤ$
- $Ξₛ = Sₗ Sᵤ$
References
[GOS] Ghannad, Alexandre, Dominique Orban, and Michael A. Saunders. "Linear systems arising in interior methods for convex optimization: a symmetric formulation with bounded condition number." Optimization Methods and Software 37, no. 4 (2022): 1344-1369.
Dense KKT systems
MadNLP provides also two structures to store the KKT system in a dense matrix. Although less efficient than their sparse counterparts, these two structures allow to store the KKT system efficiently when the problem is instantiated on the GPU.
MadNLP.DenseKKTSystem — Type
DenseKKTSystem{T, VT, MT, QN, VI} <: AbstractReducedKKTSystem{T, VT, MT, QN}Implement AbstractReducedKKTSystem with dense matrices.
Requires a dense linear solver to be factorized (otherwise an error is returned).
MadNLP.DenseCondensedKKTSystem — Type
DenseCondensedKKTSystem{T, VT, MT, QN} <: AbstractCondensedKKTSystem{T, VT, MT, QN}Implement AbstractCondensedKKTSystem with dense matrices.
Requires a dense linear solver to factorize the associated KKT system (otherwise an error is returned).
Schur complement KKT system
For two-stage stochastic programs with a block-arrowhead structure, MadNLP provides a specialized KKT system that eliminates the per-scenario blocks and reduces the linear system to a dense nd × nd Schur complement on the design variables.
MadNLP.SchurComplementKKTSystem — Type
SchurComplementKKTSystem{T, VT, MT, QN, LS, LS2, VI} <: AbstractCondensedKKTSystem{T, VT, MT, QN}KKT system exploiting block-arrowhead structure from two-stage stochastic programs via Schur complement decomposition, using sparse COO/CSC storage for the global Hessian and Jacobian and sparse per-scenario block solvers.
Variable layout: [v_1, ..., v_ns, d] where v_k ∈ R^nv, d ∈ R^nd. Constraint layout: [c_1, ..., c_ns] where c_k ∈ R^nc.
The augmented per-scenario block A_k (size blk_size × blk_size) is stored as a sparse lower-triangular SparseMatrixCSC and factored by a configurable sparse solver (default MumpsSolver — each A_k is symmetric indefinite, not SQD in general). The coupling blocks C_dk remain dense. The Schur complement S = aug_com (size nd × nd) is dense.
AbstractKKTVector
Each instance of AbstractKKTVector implements the following interface.
MadNLP.AbstractKKTVector — Type
AbstractKKTVector{T, VT}Supertype for KKT's right-hand-side vectors $(x, s, y, z, ν, w)$.
MadNLP.number_primal — Function
number_primal(X::AbstractKKTVector)Get total number of primal values $(x, s)$ in KKT vector X.
MadNLP.number_dual — Function
number_dual(X::AbstractKKTVector)Get total number of dual values $(y, z)$ in KKT vector X.
MadNLP.full — Function
full(X::AbstractKKTVector)Return all the values stored inside the KKT vector X.
MadNLP.primal — Function
primal(X::AbstractKKTVector)Return the primal values $(x, s)$ stored in the KKT vector X.
MadNLP.dual — Function
dual(X::AbstractKKTVector)Return the dual values $(y, z)$ stored in the KKT vector X.
MadNLP.primal_dual — Function
primal_dual(X::AbstractKKTVector)Return both the primal and the dual values $(x, s, y, z)$ stored in the KKT vector X.
MadNLP.dual_lb — Function
dual_lb(X::AbstractKKTVector)Return the dual values $ν$ associated to the lower-bound stored in the KKT vector X.
MadNLP.dual_ub — Function
dual_ub(X::AbstractKKTVector)Return the dual values $w$ associated to the upper-bound stored in the KKT vector X.
By default, MadNLP provides one implementation of an AbstractKKTVector.
MadNLP.UnreducedKKTVector — Type
UnreducedKKTVector{T, VT<:AbstractVector{T}} <: AbstractKKTVector{T, VT}Full KKT vector $(x, s, y, z, ν, w)$, associated to a AbstractUnreducedKKTSystem.