slsqp_jax.slsqp.solver¶
The SLSQP Optimistix AbstractMinimiser class — holds the config, constraint functions, and derivative overrides; delegates the step body to the helpers below.
slsqp_jax.slsqp.solver
SLSQP outer-loop minimiser.
This module replaces the legacy monolithic slsqp_jax/solver.py. The
high-level SLSQP class accepts a single SLSQPConfig
instance grouping the previous 40+ flat keyword arguments, plus the
constraint structure (functions, counts, bounds), optional
user-supplied derivatives, an optional pluggable inner solver, and the
verbose printer.
The class implements the four optimistix.AbstractMinimiser
methods (init, step, terminate, postprocess) and
delegates as much logic as possible to:
slsqp_jax.slsqp.bounds— NLP-level bound machinery.slsqp_jax.slsqp.derivatives— gradient / Jacobian / HVP closure factories.slsqp_jax.slsqp.preconditioner— preconditioner factories.slsqp_jax.slsqp.hvp— Lagrangian HVP factories.slsqp_jax.slsqp.termination— single source of truth for the termination classification.slsqp_jax.slsqp.verbose— verbose printer callbacks.slsqp_jax.qp.bound_fixing— reduced-space bound-fixing pass.
- class slsqp_jax.slsqp.solver.SLSQP[source]¶
Bases:
AbstractMinimiserSLSQP minimiser using Sequential Quadratic Programming.
See
README.mdanddocs/source/index.mdfor the full algorithmic description. The user-facing API collapses the legacy 40+ flat keyword arguments into a singleSLSQPConfiginstance grouping the parameters by purpose; consultslsqp_jax.configfor the sub-config dataclasses.- Attributes:
- config: Aggregate configuration. Defaults to
SLSQPConfigwith all sub-config defaults.- eq_constraint_fn: Function
(x, args) -> c_eq(x)evaluated for equality-constraint feasibility
c_eq(x) = 0.- ineq_constraint_fn: Function
(x, args) -> c_ineq(x) evaluated for inequality-constraint feasibility
c_ineq(x) >= 0.
n_eq_constraints: Number of equality constraints (static). n_ineq_constraints: Number of inequality constraints (static). bounds: Optional
(n, 2)array of[lower, upper]pervariable; iterates are projected onto this box after every step. Use
-inf/+inffor unbounded dimensions.obj_grad_fn / eq_jac_fn / ineq_jac_fn / obj_hvp_fn / eq_hvp_fn / ineq_hvp_fn: Optional user-supplied derivative
callables; the AD fallbacks (
jax.grad/jax.jacrev/ forward-over-reversejvp(grad(.))) are used when these areNone.- inner_solver: Optional pluggable inner equality-constrained
QP solver.
Noneconstructs a defaultProjectedCGCholeskyderived fromconfig.- verbose:
True/Falseor a custom(**kwargs) -> None callable for per-step diagnostics.
- norm() Shaped[Array, '']¶
Compute the L-infinity norm of a PyTree of arrays.
This is the largest absolute elementwise value. Considering the input x as a flat vector (x_1, …, x_n), then this computes max_i |x_i|.
- Parameters:
x (PyTree[jax.Array | numpy.ndarray | numpy.bool | numpy.number | bool | int | float | complex | jax._src.literals.TypedNdArray])
- Return type:
Shaped[Array, ‘’]
- config: SLSQPConfig¶
- eq_hvp_fn: Callable[[Float[Array, 'n'], Float[Array, 'n'], Any], Float[Array, 'm n']] | None = None¶
- ineq_hvp_fn: Callable[[Float[Array, 'n'], Float[Array, 'n'], Any], Float[Array, 'm n']] | None = None¶
- inner_solver: AbstractInnerSolver | None = None¶
- init(fn, y, args, options, f_struct, aux_struct, tags)[source]¶
Perform all initial computation needed to initialise the solver state.
For example, the [optimistix.Chord][] method computes the Jacobian df/dy with respect to the initial guess y, and then uses it throughout the computation.
Arguments:
- fn: The function to iterate over. This is expected to take two argumetns
fn(y, args) and return a pytree of arrays in the first element, and any auxiliary data in the second argument.
y: The value of y at the current (first) iteration.
args: Passed as the args of fn(y, args).
- options: Individual solvers may accept additional runtime arguments.
See each individual solver’s documentation for more details.
- f_struct: A pytree of `jax.ShapeDtypeStruct`s of the same shape as the
output of fn. This is used to initialise any information in the state which may rely on the pytree structure, array shapes, or dtype of the output of fn.
- aux_struct: A pytree of `jax.ShapeDtypeStruct`s of the same shape as the
auxiliary data returned by fn.
- tags: exact meaning depends on whether this is a fixed point, root find,
least squares, or minimisation problem; see their relevant entry points.
Returns:
A PyTree representing the initial state of the solver.
- step(fn, y, args, options, state, tags)[source]¶
Perform one step of the iterative solve.
Arguments:
- fn: The function to iterate over. This is expected to take two argumetns
fn(y, args) and return a pytree of arrays in the first element, and any auxiliary data in the second argument.
y: The value of y at the current (first) iteration.
args: Passed as the args of fn(y, args).
- options: Individual solvers may accept additional runtime arguments.
See each individual solver’s documentation for more details.
- state: A pytree representing the state of a solver. The shape of this
pytree is solver-dependent.
- tags: exact meaning depends on whether this is a fixed point, root find,
least squares, or minimisation problem; see their relevant entry points.
Returns:
A 3-tuple containing the new y value in the first element, the next solver state in the second element, and the aux output of fn(y, args) in the third element.
- terminate(fn, y, args, options, state, tags)[source]¶
Determine whether or not to stop the iterative solve.
Arguments:
- fn: The function to iterate over. This is expected to take two argumetns
fn(y, args) and return a pytree of arrays in the first element, and any auxiliary data in the second argument.
y: The value of y at the current iteration.
args: Passed as the args of fn(y, args).
- options: Individual solvers may accept additional runtime arguments.
See each individual solver’s documentation for more details.
- state: A pytree representing the state of a solver. The shape of this
pytree is solver-dependent.
- tags: exact meaning depends on whether this is a fixed point, root find,
least squares, or minimisation problem; see their relevant entry points.
Returns:
A 2-tuple containing a bool indicating whether or not to stop iterating in the first element, and an [optimistix.RESULTS][] object in the second element.
- postprocess(fn, y, aux, args, options, state, tags, result)[source]¶
Any final postprocessing to perform on the result of the solve.
Arguments:
- fn: The function to iterate over. This is expected to take two argumetns
fn(y, args) and return a pytree of arrays in the first element, and any auxiliary data in the second argument.
y: The value of y at the last iteration.
aux: The auxiliary output at the last iteration.
args: Passed as the args of fn(y, args).
- options: Individual solvers may accept additional runtime arguments.
See each individual solver’s documentation for more details.
- state: A pytree representing the final state of a solver. The shape of this
pytree is solver-dependent.
- tags: exact meaning depends on whether this is a fixed point, root find,
least squares, or minimisation problem; see their relevant entry points.
result: as returned by the final call to terminate.
Returns:
A 3-tuple of:
final_y: the final y to return as the solution of the solve.
final_aux: the final aux to return as the auxiliary output of the solve.
stats: any additional information to place in the sol.stats dictionary.
!!! info
- __init__(norm=<function max_norm>, config=<factory>, eq_constraint_fn=None, ineq_constraint_fn=None, n_eq_constraints=0, n_ineq_constraints=0, bounds=None, _lower_bound_mask=None, _upper_bound_mask=None, _n_lower_bounds=0, _n_upper_bounds=0, _lower_indices=None, _upper_indices=None, obj_grad_fn=None, eq_jac_fn=None, ineq_jac_fn=None, obj_hvp_fn=None, eq_hvp_fn=None, ineq_hvp_fn=None, _grad_impl=None, _eq_jac_impl=None, _ineq_jac_impl=None, _eq_hvp_contrib_impl=None, _ineq_hvp_contrib_impl=None, _obj_hvp_impl=None, inner_solver=None, _stagnation_window=10, _proximal_mu_min=1e-06, _proximal_mu_max=0.1, verbose=False)¶
- Parameters:
norm (Callable)
config (SLSQPConfig)
eq_constraint_fn (Callable[[Float[Array, 'n'], Any], Float[Array, 'm']] | None)
ineq_constraint_fn (Callable[[Float[Array, 'n'], Any], Float[Array, 'm']] | None)
n_eq_constraints (int)
n_ineq_constraints (int)
bounds (Float[Array, 'n 2'] | None)
_n_lower_bounds (int)
_n_upper_bounds (int)
obj_grad_fn (Callable[[Float[Array, 'n'], Any], Float[Array, 'n']] | None)
eq_jac_fn (Callable[[Float[Array, 'n'], Any], Float[Array, 'm n']] | None)
ineq_jac_fn (Callable[[Float[Array, 'n'], Any], Float[Array, 'm n']] | None)
obj_hvp_fn (Callable[[Float[Array, 'n'], Float[Array, 'n'], Any], Float[Array, 'n']] | None)
eq_hvp_fn (Callable[[Float[Array, 'n'], Float[Array, 'n'], Any], Float[Array, 'm n']] | None)
ineq_hvp_fn (Callable[[Float[Array, 'n'], Float[Array, 'n'], Any], Float[Array, 'm n']] | None)
_grad_impl (Callable)
_eq_jac_impl (Callable)
_ineq_jac_impl (Callable)
_eq_hvp_contrib_impl (Callable)
_ineq_hvp_contrib_impl (Callable)
_obj_hvp_impl (Callable | None)
inner_solver (AbstractInnerSolver | None)
_stagnation_window (int)
_proximal_mu_min (float)
_proximal_mu_max (float)
verbose (Callable)
- Return type:
None