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:

class slsqp_jax.slsqp.solver.SLSQP[source]

Bases: AbstractMinimiser

SLSQP minimiser using Sequential Quadratic Programming.

See README.md and docs/source/index.md for the full algorithmic description. The user-facing API collapses the legacy 40+ flat keyword arguments into a single SLSQPConfig instance grouping the parameters by purpose; consult slsqp_jax.config for the sub-config dataclasses.

Attributes:
config: Aggregate configuration. Defaults to

SLSQPConfig with 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] per

variable; iterates are projected onto this box after every step. Use -inf / +inf for 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-reverse jvp(grad(.))) are used when these are None.

inner_solver: Optional pluggable inner equality-constrained

QP solver. None constructs a default ProjectedCGCholesky derived from config.

verbose: True/False or 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_constraint_fn: Callable[[Float[Array, 'n'], Any], Float[Array, 'm']] | None = None
ineq_constraint_fn: Callable[[Float[Array, 'n'], Any], Float[Array, 'm']] | None = None
n_eq_constraints: int = 0
n_ineq_constraints: int = 0
bounds: Float[Array, 'n 2'] | None = None
obj_grad_fn: Callable[[Float[Array, 'n'], Any], Float[Array, 'n']] | None = None
eq_jac_fn: Callable[[Float[Array, 'n'], Any], Float[Array, 'm n']] | None = None
ineq_jac_fn: Callable[[Float[Array, 'n'], Any], Float[Array, 'm n']] | None = None
obj_hvp_fn: Callable[[Float[Array, 'n'], Float[Array, 'n'], Any], Float[Array, 'n']] | None = None
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
verbose: Callable = False
property rtol: float
property atol: float
property max_steps: int
property min_steps: int
property stagnation_tol: float
property divergence_factor: float
property divergence_patience: int
property lbfgs_memory: int
property damping_threshold: float
property lbfgs_diag_floor: float
property lbfgs_diag_ceil: float
property line_search_max_steps: int
property armijo_c1: float
property ls_failure_patience: int
property qp_max_iter: int
property qp_max_cg_iter: int
property qp_failure_patience: int
property zero_step_patience: int
property qp_ping_pong_threshold: int
property mult_drop_floor: float
property cg_regularization: float
property use_exact_hvp_in_qp: bool
property proximal_tau: float
property proximal_mu_min: float | None
property proximal_mu_max: float
property use_preconditioner: bool
property preconditioner_type: str
property diagonal_n_probes: int
property active_set_method: str
property lpeca_sigma: float
property lpeca_beta: float | None
property lpeca_use_lp: bool
property lpeca_trust_threshold: float
property lpeca_warmup_steps: int
property lpeca_predict_bounds: bool
property adaptive_cg_tol: bool
property use_inexact_stationarity: bool
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.

Return type:

SLSQPState

Parameters:
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.

Return type:

tuple[Float[Array, 'n'], SLSQPState, Any]

Parameters:
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.

Return type:

tuple[Bool[Array, ''], Any]

Parameters:
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

Most solvers will not need to use this, so that this method may be defined as: ```python def postprocess(self, fn, y, aux, args, options, state, tags, result):

return y, aux, {}

```

Return type:

tuple[Float[Array, 'n'], Any, dict[str, Any]]

Parameters:
__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)

  • _lower_bound_mask (tuple[bool, ...] | None)

  • _upper_bound_mask (tuple[bool, ...] | None)

  • _n_lower_bounds (int)

  • _n_upper_bounds (int)

  • _lower_indices (tuple[int, ...] | None)

  • _upper_indices (tuple[int, ...] | None)

  • 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