Skip to main content

Module implicit_diff

Module implicit_diff 

Source
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 = rhs via Gaussian elimination with partial pivoting.
solve_implicit_system_multi
Solve the system mat * X = rhs_matrix where rhs_matrix has k columns. Returns the solution matrix (n × k) in row-major form.