pysolver_view.diagnostics.kkt module

pysolver_view.diagnostics.kkt module#

Assess first-order KKT conditions without evaluating or changing a model.

Public inputs use h(x)=0, g(x)<=0, and lower<=x<=upper. The Lagrangian is L = f + lambda*h + mu*g - z_lower*(x-lower) + z_upper*(x-upper). Equality multipliers are unrestricted; inequality and bound multipliers must be nonnegative. All metrics use the supplied objective, constraint, and variable units. Positive rescaling changes tolerance meanings even though the fitted multipliers transform consistently.

assess_kkt estimates sign-feasible multipliers by jointly minimizing the infinity norm of stationarity and complementarity residuals. It then reconstructs the residuals with the original coefficients, independently of the LP’s success flag. evaluate_kkt_residuals performs only that reconstruction for a supplied complete multiplier set, permitting independent checks of native multipliers.

The minimax estimator is adapted from Turbodash’s generic numerical checker. No active-set threshold, model callback, history recording, or solver state is needed. A passing first-order check does not prove a minimum or second-order sufficiency; interpretation also depends on derivative accuracy and constraint qualifications. assess_kkt_nonnegative is the private SLSQP sign adapter.

pysolver_view.diagnostics.kkt.assess_kkt(x, gradient, equality_values, equality_jacobian, inequality_values, inequality_jacobian, lower, upper, *, feasibility_tol=1e-06, optimality_tol=0.0001)[source]#

Estimate sign-feasible multipliers and independently assess first-order KKT.

All inequalities and finite bounds participate in a linear minimax fit of stationarity and complementarity; equality multipliers remain unrestricted. Column equilibration and gradient scaling protect small gradients and positive constraint rescaling. Returned residuals and tolerances are in the supplied coordinates and units, not the equilibrated fitting system. Failed numerical fitting returns available=False, passed=False and a reason. Invalid inputs raise ValueError. No model is evaluated or history mutated.

pysolver_view.diagnostics.kkt.assess_kkt_nonnegative(x, gradient, equality_values, equality_jacobian, inequality_values, inequality_jacobian, lower, upper, *, feasibility_tol=1e-06, optimality_tol=0.0001)[source]#

Adapt the private SLSQP convention c>=0 and L=f-lambda*h-mu*c.

Constraint values and Jacobians are negated once. Equality multipliers are converted back to the driver’s minus-sign convention; bound and inequality multipliers are unchanged. Residual norms and acceptance remain identical.

pysolver_view.diagnostics.kkt.evaluate_kkt_residuals(x, gradient, equality_values, equality_jacobian, inequality_values, inequality_jacobian, lower, upper, *, multipliers, feasibility_tol=1e-06, optimality_tol=0.0001, multiplier_source='supplied')[source]#

Evaluate KKT residuals for a complete, explicitly supplied multiplier set.

Inputs use inequalities <=0 and the plus-sign public Lagrangian. Supply a mapping containing equality, inequality, lower, and upper multiplier arrays; bound arrays have one element per variable, zero where the bound is absent. Missing bound multipliers are not silently filled from an estimator. Negative inequality/bound multipliers are accepted as inputs and fail dual feasibility. The source label records provenance and does not alter the numerical checks.