Expand description
Core implicit differentiation engine for optimization layers.
Given an optimal solution z* satisfying KKT conditions F(z*, θ) = 0, the implicit function theorem yields:
dz*/dθ = -(∂F/∂z)⁻¹ · (∂F/∂θ)
This module builds the KKT Jacobian ∂F/∂z, solves the resulting linear system, and supports an active-set variant that restricts differentiation to active inequality constraints.
Functions§
- adjust_
complementarity_ diagonal - Adjust the complementarity diagonal block with the rhs h.
- compute_
active_ set_ implicit_ gradient - Compute implicit gradient using only active constraints.
- compute_
full_ implicit_ gradient - Compute the full implicit gradient dz*/dθ for a QP.
- compute_
kkt_ jacobian - Build the KKT Jacobian matrix ∂F/∂z for the QP:
- extract_
active_ constraints - Extract rows from G and h corresponding to the given active indices.
- identify_
active_ constraints - Identify active inequality constraints: those where h_i - G_i x ≤ tol (i.e., the slack is near zero).
- solve_
implicit_ system - Solve the linear system
A x = rhsvia Gaussian elimination with partial pivoting. - solve_
implicit_ system_ multi - Solve the system
mat * X = rhs_matrixwhere rhs_matrix haskcolumns. Returns the solution matrix (n × k) in row-major form.