![]() |
Sleipnir
A linearity-exploiting reverse mode autodiff library and nonlinear program solver DSL.
|
This page documents the algorithms Sleipnir implements.
In reverse accumulation AD, the dependent variable to be differentiated is fixed and the derivative is computed with respect to each subexpression recursively. In a pen-and-paper calculation, the derivative of the outer functions is repeatedly substituted in the chain rule:
(∂y/∂x) = (∂y/∂w₁) ⋅ (∂w₁/∂x) = ((∂y/∂w₂) ⋅ (∂w₂/∂w₁)) ⋅ (∂w₁/∂x) = ...
In reverse accumulation, the quantity of interest is the adjoint, denoted with a bar (w̄); it is a derivative of a chosen dependent variable with respect to a subexpression w: ∂y/∂w.
Given the expression f(x₁,x₂) = sin(x₁) + x₁x₂, the computational graph is:
The operations to compute the derivative:
w̄₅ = 1 (seed)
w̄₄ = w̄₅(∂w₅/∂w₄) = w̄₅
w̄₃ = w̄₅(∂w₅/∂w₃) = w̄₅
w̄₂ = w̄₃(∂w₃/∂w₂) = w̄₃w₁
w̄₁ = w̄₄(∂w₄/∂w₁) + w̄₃(∂w₃/∂w₁) = w̄₄cos(w₁) + w̄₃w₂
https://en.wikipedia.org/wiki/Automatic_differentiation#Beyond_forward_and_reverse_accumulation
We want to solve the following optimization problem.
where f(x) is the cost function.
The Lagrangian of the problem is
The gradients are
The first-order necessary conditions for optimality (KKT conditions) are
Next, we'll apply Newton's method to the optimality conditions. Let H be ∂²L/∂x² and pˣ be the step for x.
In summary, the following system gives the iterate pₖˣ.
The iterate is applied like so
We want to solve the following optimization problem.
where f(x) is the cost function and cₑ(x) is the equality constraints.
The Lagrangian of the problem is
The gradients are
The first-order necessary conditions for optimality (KKT conditions) are
where Aₑ = ∂cₑ/∂x. We'll rearrange them for the primal-dual system.
Next, we'll apply Newton's method to the optimality conditions. Let H be ∂²L/∂x², pˣ be the step for x, and pʸ be the step for y.
Group them into a matrix equation.
Invert pʸ.
In summary, the reduced 2x2 block system gives the iterates pₖˣ and pₖʸ.
The iterates are applied like so
Local infeasibility is only declared when the feasibility restoration phase converges to a minimizer of the constraint violation that still violates the constraints; testing for infeasibility at arbitrary iterates risks false positives. See section 3.3, p. 14 of [^2].
We want to solve the following optimization problem.
where f(x) is the cost function, cₑ(x) is the equality constraints, and cᵢ(x) is the inequality constraints. First, we'll reformulate the inequality constraints as equality constraints with slack variables.
To make this easier to solve, we'll reformulate it as the following barrier problem.
where μ is the barrier parameter. As μ → 0, the solution of the barrier problem approaches the solution of the original problem.
The Lagrangian of the barrier problem is
The gradients are
The first-order necessary conditions for optimality (KKT conditions) are
where Aₑ = ∂cₑ/∂x, Aᵢ = ∂cᵢ/∂x, S = diag(s), and e is a column vector of ones. We'll rearrange them for the primal-dual system.
Next, we'll apply Newton's method to the optimality conditions. Let H be ∂²L/∂x², Σ be the primal-dual barrier term Hessian S⁻¹Z, pˣ be the step for x, pˢ be the step for s, pʸ be the step for y, and pᶻ be the step for z.
Group them into a matrix equation.
Invert pʸ and pᶻ.
Multiply the second row by S⁻¹ and replace S⁻¹Z with Σ.
Solve the fourth row for pˢ.
Solve the second row for pᶻ.
Substitute pᶻ into the first row, expand, and cancel Aᵢᵀz from both sides.
Substitute pˢ, distribute AᵢᵀΣ, and collect the pˣ terms.
Since pˢ and pᶻ can be recovered by back-substitution, eliminate their rows and columns.
In summary, the reduced 2x2 block system gives the iterates pₖˣ and pₖʸ.
The iterates pˢ and pᶻ are given by
The iterates are applied like so
where αₖᵐᵃˣ and αₖᶻ are computed via the fraction-to-the-boundary rule shown in equations (15a) and (15b) of [^2].
Local infeasibility is only declared when the feasibility restoration phase converges to a minimizer of the constraint violation that still violates the constraints; testing for infeasibility at arbitrary iterates risks false positives. See section 3.3, p. 14 of [^2].
Sleipnir scales the cost and constraints to improve numerical stability. The cost and each constraint are scaled so that the largest gradient component at the starting point is at most g_max. For an initial point x₀, define
where D_c = diag(d_c) and A = ∂c/∂x is the constraint Jacobian. The scaled Lagrangian is:
The Hessian of the scaled Lagrangian with respect to x is:
Recall that the original KKT matrix is:
Scaling the KKT matrix for this problem gives:
With D_x = I, this reduces to:
Expanding ∇²ₓₓL yields:
where D_c A replaces A and d_f ∇²ₓₓf + Σᵢ (D_c λ)ᵢ ∇²ₓₓcᵢ replaces ∇²ₓₓf + ∇²ₓₓc in the original KKT matrix.
The algorithm is described in more detail in section 3.8 of [^2].
[^1]: Nocedal, J. and Wright, S. "Numerical Optimization", 2nd. ed., Ch. 19. Springer, 2006.
[^2]: Wächter, A. and Biegler, L. "On the implementation of an interior-point filter line-search algorithm for large-scale nonlinear programming", 2005. http://cepac.cheme.cmu.edu/pasilectures/biegler/ipopt.pdf
[^3]: Gu, C. and Zhu, D. "A Dwindling Filter Algorithm with a Modified Subproblem for Nonlinear Inequality Constrained Optimization", 2014. https://sci-hub.st/10.1007/s11401-014-0826-z
[^4]: Hinder, O. and Ye, Y. "A one-phase interior point method for nonconvex optimization", 2018. https://arxiv.org/pdf/1801.03072.pdf