slsqp_jax.slsqp.derivatives

Closure factories that build (grad, jac, hvp_contrib) from the user-supplied callables or default to JAX’s reverse-mode AD.

slsqp_jax.slsqp.derivatives

Gradient / Jacobian / HVP closure factories.

Centralises the dispatch between user-supplied derivative callables and the AD fallbacks so the SLSQP class can remain agnostic to which side provided each derivative.

Two helpers are public:

  • build_jacobian_impl() — returns a closure (y, args) -> J for a single constraint slot, parameterised by the user-supplied user_jac (or None) and the user-supplied constraint function.

  • build_hvp_contrib_impl() — returns a closure (y, v, args, multipliers) -> Σ μ_i H_{c_i} v for a single constraint slot, parameterised analogously.

The single-constraint-slot helpers eliminate the EQ/INEQ duplication in the legacy __check_init__: each side calls the same factory with its own slot’s user-supplied callables and m_constraints.

slsqp_jax.slsqp.derivatives.build_grad_impl(user_grad_fn)[source]

Closure (fn, y, args) -> ∇f(y) dispatching to user / AD.

Return type:

Callable

Parameters:

user_grad_fn (Callable | None)

slsqp_jax.slsqp.derivatives.build_hvp_contrib_impl(*, user_hvp, constraint_fn, n_constraints)[source]

Closure (y, v, args, μ) -> Σ μ_i H_{c_i}(y) v for one slot.

Mirrors build_jacobian_impl(): dispatches between user-supplied user_hvp, AD via jvp(grad(weighted)), or a zero-vector fallback.

Return type:

Callable

Parameters:
slsqp_jax.slsqp.derivatives.build_jacobian_impl(*, user_jac, constraint_fn, n_constraints)[source]

Closure (y, args) -> J(y) for one constraint slot.

Returns a zero-Jacobian closure when no constraint function is supplied or the slot is empty (n_constraints == 0).

Return type:

Callable

Parameters:
slsqp_jax.slsqp.derivatives.build_obj_hvp_impl(*, user_obj_hvp, use_exact_hvp_in_qp)[source]

Optional (fn, y, v, args) -> H_f v closure.

Returns None when no exact HVP source is available and Newton-CG is disabled, mirroring the legacy self._obj_hvp_impl is None sentinel used in step() to decide whether to probe the Hessian for the L-BFGS secant pair.

Return type:

Callable | None

Parameters: