Skip to content

API

Solvers

nlls_gram.LevenbergMarquardt

Bases: SolverBase

Euclidean-step Levenberg-Marquardt solver for NLLS and generalized Tikhonov.

compile(x0, args=None, *, p=None, state=None, max_steps=256, atol=0.0, gtol=0.0, xtol=0.0, callback=None, user_state=None, save_steps=False)

Compile the jitted solve loop and return (compile_time, peak_bytes).

hyperparams(dtype=None)

Return LMHyperparams built from constructor settings.

init(x0, args=None, *, p=None)

Build initial LMState at x0 without evaluating the residual.

solve(x0, args=None, *, p=None, state=None, max_steps=256, max_steps_is_success=False, atol=0.0, gtol=0.0, xtol=0.0, callback=None, user_state=None, save_steps=False, multi_start=None, jit=True)

Run solver updates until a stopping rule fires and support AD in p.

update(x, state, args=None, p=None)

Execute one Levenberg-Marquardt step and return (x_new, state, info).

nlls_gram.LMSettings dataclass

Scalar LevenbergMarquardt arguments at their defaults, for command lines.

nlls_gram.Newton

Bases: SolverBase

Euclidean-step Newton / Gauss-Newton solver with Armijo backtracking.

compile(x0, args=None, *, p=None, state=None, max_steps=256, atol=0.0, gtol=0.0, xtol=0.0, callback=None, user_state=None, save_steps=False)

Compile the jitted solve loop and return (compile_time, peak_bytes).

hyperparams(dtype=None)

Return NewtonHyperparams built from constructor settings.

init(x0, args=None, *, p=None)

Build initial NewtonState at x0 without evaluating the residual.

solve(x0, args=None, *, p=None, state=None, max_steps=256, max_steps_is_success=False, atol=0.0, gtol=0.0, xtol=0.0, callback=None, user_state=None, save_steps=False, multi_start=None, jit=True)

Run solver updates until a stopping rule fires and support AD in p.

update(x, state, args=None, p=None)

Execute one Newton + Armijo step and return (x_new, state, info).

nlls_gram.NewtonSettings dataclass

Scalar Newton arguments at their defaults, for command lines.

nlls_gram.BoxSecant

Safeguarded projected secant-bisection solver for 1D box optimization.

Minimizes or maximizes a scalar differentiable objective fn on a closed interval [lower, upper] using forward-mode directional derivatives, projected secant steps safeguarded by bracket bisection, fused custom_vmap batching, and box-aware implicit differentiation.

solve(lower, upper, args=None, *, x0=None, p=None, xtol=None, rtol=None, gtol=None, max_steps=32, max_steps_is_success=False, num_starts=1, loop=None, jit=True)

Optimize fn over [lower, upper] with implicit AD.

xtol and gtol default to eps ** 0.8 and rtol defaults to 4 * eps for the inferred floating dtype. num_starts > 1 partitions [lower, upper] into uniform sub-boxes (plus exact grid edges and optional x0) in a single fused loop. Returned x, fun, grad, lm, and aux support implicit AD wrt (lower, upper, p).

nlls_gram.ScalarNewton

Safeguarded second-order 1D unconstrained optimizer from an initial guess.

Minimizes or maximizes a scalar twice-differentiable objective fn starting from x0 using second-order forward-mode scalar jets, pluggable flat-loop globalization (default TrustRegion()), fused custom_vmap batching, and implicit differentiation wrt p.

solve(x0, args=None, *, p=None, xtol=None, rtol=None, gtol=None, max_steps=32, max_steps_is_success=False, loop=None, jit=True)

Optimize fn from x0 with implicit AD wrt p.

xtol and gtol default to eps ** 0.8 and rtol defaults to 4 * eps for the inferred floating dtype. Returned x, fun, grad, and aux support implicit AD wrt p at regular stationary points (f_xx != 0).

nlls_gram.ScalarGlobalization

Base class for 1D globalization strategies in ScalarNewton.

nlls_gram.TrustRegion dataclass

Bases: ScalarGlobalization

Scalar trust-region globalization for ScalarNewton.

When init_radius is None, the initial radius defaults to min(max(|x0|, 1), max_radius). When max_radius is None, it defaults to 1e4 * init_radius.

nlls_gram.AnnealRidge dataclass

Ridge-continuation callback reducing state.ridge down to ridge_floor.

init_state(dtype=None)

Return initial user_state trackers at +inf.

Linear solvers

nlls_gram.Cholesky dataclass

Bases: LinearSolver

Dense Cholesky solver on normal or Gram equations.

nlls_gram.QR dataclass

Bases: LinearSolver

Augmented and square-root Gram QR solver without forming normal equations.

nlls_gram.CG dataclass

Bases: _KrylovConfig

Matrix-free PCG on the parameter-space operator J'J + rho Q + mu I.

nlls_gram.GramCG dataclass

Bases: _KrylovConfig

Matrix-free preconditioned conjugate gradients in residual space.

nlls_gram.LU dataclass

Bases: LinearSolver

Direct LU factorization for square unpenalized Newton and implicit-AD systems.

nlls_gram.SVD dataclass

Bases: LinearSolver

Rank-aware SVD solver selecting the minimum-norm augmented LS step.

Ridge operators

nlls_gram.RidgeMetric

Symmetric PSD objective operator Q for generalized Tikhonov regularization.

Defines the objective penalty 0.5 * ridge * x' Q x without altering the Euclidean step geometry. Custom matrix-free subclasses for CG need only implement matvec(v, ctx) and register with register_pytree_dataclass.

nlls_gram.IdentityRidge dataclass

Bases: RidgeMetric

Identity penalty Q = I on leading size entries (all when None).

nlls_gram.DiagonalRidge dataclass

Bases: RidgeMetric

Nonnegative diagonal penalty Q = diag(weights) on leading coordinates.

nlls_gram.MatrixRidge dataclass

Bases: RidgeMetric

Dense symmetric PSD penalty Q on the leading Q.shape[0] coordinates.

nlls_gram.FactorRidge dataclass

Bases: RidgeMetric

Explicit factor L defining Q = L'L on leading L.shape[1] entries.

nlls_gram.RepeatedFactorRidge dataclass

Bases: RidgeMetric

Block-diagonal RKHS seminorm Q = blockdiag(L'L, ..., L'L, 0).

Preconditioners

nlls_gram.Preconditioner

Numerical preconditioner protocol for Krylov and dense linear solvers.

apply(v, damping, ctx) applies an SPD approximation of the damped operator inverse in original Euclidean coordinates (parameter space for CG, residual space for GramCG). Subclasses must register as JAX pytrees with register_pytree_dataclass. Set requires_positive_damping = True when apply divides by the live damping and cannot run at zero damping.

nlls_gram.IdentityPreconditioner dataclass

Bases: Preconditioner

Stateless identity preconditioner.

nlls_gram.DiagonalPreconditioner dataclass

Bases: Preconditioner

Diagonal Jacobi or equilibration preconditioner for Krylov and dense solvers.

When diagonal is a positive 1-D array d, Krylov solvers apply v / (d + damping) and dense solvers scale by 1 / sqrt(d + damping). When diagonal is None, dense Cholesky and QR solvers compute automatic diagonal equilibration from the assembled matrix diagonal or column/row norms without altering the target linear equation.

Residuals and constraints

nlls_gram.vmap_rows

vmap_rows(f=None, *, in_axes=None, chunk_size=None)

Map f over residual rows with single per-row jacrev per linearization.

in_axes defaults to (0, None, None, ...) when None and otherwise follows jax.vmap with outputs stacked along axis 0. Plain directional jax.jvp calls (including geodesic second directional derivatives) run jax.vmap(f, in_axes) directly. Under jax.linearize and reverse-mode autodiff, each row's Jacobian with respect to active floating inputs is evaluated once via jax.jacrev (batched with jax.vmap when chunk_size is None, or in batches via jax.lax.map when chunk_size is set) and contracted across tangent or cotangent directions.

nlls_gram.Residuals dataclass

Structured residual container for equality, inequality, and complementarity.

nlls_gram.Inequality dataclass

Nonlinear inequality residual margins representing value >= 0.

nlls_gram.InequalityPenalty dataclass

Configuration for nonlinear inequality residuals g(x) >= 0.

weight scales the half-objective penalty 0.5 * weight * ||psi(g)||_2^2 by multiplying the transformed inequality residual block by sqrt(weight). smoothing == 0 applies the exact violation min(g, 0) with zero derivative for g >= 0. Positive smoothing applies -smoothing * softplus(-g / smoothing) and decays toward smoothing_min by smoothing_decay when smoothing_decay < 1.

nlls_gram.Complementarity dataclass

Paired complementarity margins representing 0 <= lhs _|_ rhs >= 0.

nlls_gram.PDAS dataclass

Primal-dual active-set reformulation for complementarity residuals.

nlls_gram.FischerBurmeister dataclass

Scaled Fischer-Burmeister reformulation for complementarity residuals.

nlls_gram.Minimum dataclass

Componentwise min reformulation for complementarity residuals.

Multi-start

nlls_gram.MultiStart dataclass

Multi-start retry or parallel race configuration for solve(...).

nlls_gram.MultiStartInfo dataclass

Diagnostics attached to SolveResult.multi_start by a multi-start solve.

nlls_gram.DrawNNXModule

Multi-start draw hook re-initializing a flax nnx.Module.

State, caches, and results

nlls_gram.SolverStatus

Bases: IntEnum

Integer status codes returned by solve and reported per Newton step.

nlls_gram.SolverAction dataclass

Optional per-step callback override for solve.

nlls_gram.CallbackContext dataclass

Per-step context passed to a solve callback.

nlls_gram.SolveResult dataclass

Result returned by solve.

nlls_gram.CompileInfo

Bases: NamedTuple

Compilation wall time and XLA memory footprint returned by compile.

nlls_gram.BoxSolveResult dataclass

Result returned by BoxSecant.solve.

nlls_gram.LagrangeMultipliers dataclass

Nonnegative KKT shadow prices for active lower and upper box bounds.

nlls_gram.ScalarSolveResult dataclass

Result returned by ScalarNewton.solve.

nlls_gram.TrustRegionInfo dataclass

Diagnostics carried in ScalarSolveResult.info under TrustRegion.

nlls_gram.SolverContext dataclass

Live solver context passed to ridge metrics and preconditioners.

nlls_gram.LMState dataclass

Carried state threaded through init, update, and solve.

nlls_gram.LMInfo dataclass

Per-step diagnostics returned by LevenbergMarquardt.update.

nlls_gram.LMHyperparams dataclass

Traced Levenberg-Marquardt hyperparameters carried in LMState.hyper.

nlls_gram.NewtonState dataclass

Carried state threaded through Newton.init, update, and solve.

nlls_gram.NewtonInfo dataclass

Per-step diagnostics returned by Newton.update.

nlls_gram.NewtonHyperparams dataclass

Traced Newton and Armijo hyperparameters carried in NewtonState.hyper.

nlls_gram.CholeskyCache dataclass

Cached pre-damping symmetric matrix for Cholesky across rejected steps.

nlls_gram.QRCache dataclass

Cached pre-damping thin QR factors for QR across rejected steps.

nlls_gram.register_pytree_dataclass(cls, *, data_fields, meta_fields=())

Register a frozen dataclass as a JAX pytree.

data_fields become traced children and meta_fields become static hashable structure. Unflatten bypasses __init__ and __post_init__. Every dataclass field must appear in either data_fields or meta_fields.