API Reference

Generated from the docstrings in soar_lite/. The public surface is soar_lite.__all__, grouped here in seven: the entry point, the results, the domain, the evaluation seams, the local solvers, the global models, and the projections.

Starting out? The tutorial builds a run end to end, and the Example under n_path_schedule below is a whole run you can paste. This page gives the contract for each name; How it works gives the reasoning behind it.

Vocabulary

A few names carry fixed meanings across the page. These are worth reading once; everything after them assumes them.

The run. A path is one independent descent: a current point plus that descent's own solver state. A restart replaces the current point, so what one path holds across a run is continuous in identity, not in space. The flock is the points the paths hold at one moment - one per path, hence n_paths of them; flock_x is the flock as the run ended.

What gets evaluated. A point is one candidate: coordinates and the value there, with the gradient once it has been bought; the point a path commits - coordinates, value and gradient - is a PathPoint. A batch is the (M, d) points one call serves. A fused pass is one call that returns value and gradient together. A trial is one point a step looks at, served through serve_trials; one round of that hook is one trial per path in the cohort and one batch. When eval_f is connected a trial costs its value alone, and without it each round is itself a fused pass. A step is one path's move — what LocalSolver.propose does for that path: read as many trials as it wants and answer a winner for it, or None to stop it where it stands; the engine makes one propose call for the whole cohort. A winner that was read travels as a ValuePoint with its gradient still owed, and whatever the step owes is bought in one fused batch over the whole iteration - the engine's settle phase - so with eval_f connected an iteration adds one fused pass however many trials it read. A winner that does not survive that batch's finite check, or that was read as non-finite, stalls the path rather than being committed.

The other refusal is not a stall. A coordinate the run cannot hold - not finite, or outside domain - is a bug in whoever produced it, so the engine raises ValueError at the seam that handed it over. And the settle batch is conditional: it serves whatever still owes a gradient, so an iteration that decides nothing buys nothing.

The seams. A seam is a name the engine calls through, named by what it carries: an evaluation seam is a function handed in (eval_f_g, the fused pass, and eval_f, value only), while a plugin seam is a protocol whose methods the engine calls (LocalSolver, GlobalModel). An arm is one variant of a plugin, an ask is one propose call, and a cohort is the set of paths that step this iteration - neither the redraw set nor stalled; the model's propose covers the redraw set instead.

Names with an entry below are exported from soar_lite. The words owed, arm and ask are this page's vocabulary for how the engine works - there is no such import; settle and cohort come from the glossary in CONTEXT.md.

Entry point

n_path_schedule

n_path_schedule(
    eval_f_g: EvalFG,
    *,
    n_paths: int,
    domain: Domain,
    x0: ndarray | None = None,
    eval_f: EvalF | None = None,
    max_iters: int | None = None,
    time_limit: float | None = None,
    budget_check: Callable[[Work], bool] | None = None,
    restart_stalled: bool = True,
    global_model: GlobalModel | None = None,
    local_solver: LocalSolver | None = None,
    key: ndarray | None = None,
) -> NPathResult

Advance a flock of paths in x from the caller's initial points.

The engine owns the schedule: it checks every point against domain and refuses the ones that miss, serves each batch as one call through the seam it came from - eval_f_g for a fused batch, eval_f for a value-only one - buys the iteration's deferred gradients in one batch, keeps the n-path state machine, and owns the best f⋆ (f in the result). Two things are injected, named global_model and local_solver, in that order wherever they appear: global_model supplies where a restart lands (one point per restarting path, inside the box) and is also the run's evidence sink, while local_solver owns direction, step size, acceptance, and the enumeration inside a step, keeping its per-path state inside itself. restart_stalled is one flag on top of them: when a path stalls is the local solver's own stopping test or the finite commit gate refusing its point, whether it is then re-drawn is restart_stalled, and where the new start lands is global_model.propose, so the engine needs no restart rule of its own. The flag is on by default, because with restarts off, a stalled path just idles.

n_paths is the run's width and nothing else; the dimension is domain.d, so a run never spells it twice. Iteration 0 needs no special case in the move loop: no path holds a point yet, and a path without a point restarts, so the first move places the whole flock as one fused batch - which is why the run's schedule sees iteration 0 as the flock's placement. It is x0 where one was handed in, and otherwise one start per path from the global model. A start whose served value or gradient comes back non-finite is never placed: the path keeps the point it held - none at iteration 0 - and is marked stalled. restart_stalled governs a path that holds a point, so an unplaceable flock is asked for a fresh start every iteration whatever the flag says.

domain is the run's box and the coordinate space the engine works in: the engine tests every point against it and knows nothing about any map from these coordinates to the caller's physical ones. It is also what the default model draws from, and the only statement of the dimension. With global_model=None the engine builds a SampleGlobalModel and lets the domain draw (Domain.draw); key seeds those draws, and an injected model owns its randomness instead.

The run's own stop is the horizon: at most max_iters iterations, or the wall-clock deadline when time_limit is given. Iterations are the unit on purpose - one iteration is one pass of the loop, so the same iteration count reproduces the same run on any machine - but it is not a cost bound: one iteration serves one or more batches, so migrating a batch budget to max_iters can multiply the work done. budget_check is the caller's extra stop, asked of the engine's own ledger rather than kept beside it, and it is additional: a run is complete with a horizon alone. NPathStatus names what each of these writes.

f is the true minimum over every feasible eval with a finite value - every served point when the objective reports no mask, only the points its mask passes otherwise. A feasible -inf is the answer rather than a contender: the run ends on the spot and reports that point as x with f = -inf. The paths themselves move on every served value, mask or no mask. Work is reported, never budgeted: four counts on two axes that do not mix - points against batches, and f against f+g - and none of them stops the run (see NPathResult).

The caller's inputs are validated here, once per run: the horizon bounds, n_paths, and x0's shape, finiteness and containment raise ValueError. The domain refused a malformed box when it was built. The two plugin objects are taken on their types - a type checker refuses a wrong one, and nothing here re-checks it at run time.

Parameters:
  • eval_f_g (EvalFG) –

    the one seam a run must supply: the objective as one batched pass; pointwise builds one from a per-point scalar. Takes rows x of shape (M, d) and returns (f: (M,), g: (M, d), feas: (M,) | None) - value, gradient and optional feasibility mask. A mask holds 0/1 (or booleans) and nothing else: 0 marks a point infeasible, 1 marks it feasible, and any other value is refused rather than read.

  • n_paths (int) –

    how many paths to drive, one current point each.

  • domain (Domain) –

    the run's box, a Domain.

  • x0 (ndarray | None, default: None ) –

    the caller's flock: one start per path, shape (n_paths, d), placed by iteration 0 exactly where given and never used again. None draws the flock from the global model like any other restart; with nothing observed yet, both shipped models answer that ask with the domain's own draw, so iteration 0 is a draw from domain when x0 is left out. Validated at the entry: a start outside the declared box raises rather than clips, so a start the caller authored is never silently relocated. It still passes the same finite gate as any start, so a non-finite value or gradient there leaves the path unplaced: it stalls with no point of its own, and is asked again next iteration.

  • eval_f (EvalF | None, default: None ) –

    the objective's value half alone, same x rows, returning (f: (M,), feas: (M,) | None). None means every served trial takes its gradient in the same fused pass; supplying it lets a method that enumerates its step serve trials for their values alone and buy the winners' gradients afterwards, together in one fused batch. That same final batch also buys the value and gradient of a winner the method never read, and of a redraw start: both are committed without anyone reading a value, so neither is served before it.

  • max_iters (int | None, default: None ) –

    the run's horizon in iterations (None leaves it to time_limit); a run needs at least one of the two. 0 is legal: the loop's first stop query holds, so nothing is placed, n_iters is 0 and every flock_x row and every flock_f entry is nan.

  • time_limit (float | None, default: None ) –

    a wall-clock deadline in seconds (None means none), asked at the loop head and again before every batch, so a method that enumerates is cut at its next trial rather than at the iteration's end. The question comes before the batch is served, so a single long call can still take the run past the deadline by one batch.

  • budget_check (Callable[[Work], bool] | None, default: None ) –

    an extra gate for a budget the engine cannot see, asked at the loop head every iteration and again before each served batch. Both are per batch, not per iteration: the value-only batches a step fires through its trial hook are asked like any other, so an enumeration that turns ten times is asked ten times, and a refusal there ends the run. It receives the run's Work, so it gates on the engine's own counts rather than on a parallel tally. Before a batch it is handed the ledger that batch would leave, and a batch it refuses is never charged, so <= is the idiom on any count: work.n_f_points <= ceiling stops within one batch width of the ceiling instead of crossing it. At the loop head, with no batch pending, it is handed the ledger as it stands. Additional, not a horizon (None means none).

  • restart_stalled (bool, default: True ) –

    whether a path the engine marks stalled (its method gave up, or its point was not usable) is re-drawn from the global model. False keeps a stalled path that holds a point frozen; a path holding no point is still re-drawn. A fully stalled flock then ends the run with status="all_stalled".

  • global_model (GlobalModel | None, default: None ) –

    the restart-point source and the run's evidence sink. None builds a SampleGlobalModel, which fits nothing and draws from domain.

  • local_solver (LocalSolver | None, default: None ) –

    the local method (None binds DiagonalPreconditioner).

  • key (ndarray | None, default: None ) –

    the PRNG seed of the default model's draws; None uses the fixed default, so unseeded runs are deterministic. Ignored when global_model is supplied (that model owns its key).

Raises:
  • ValueError –

    At the entry, once per run: if both max_iters and time_limit are missing, if max_iters is negative or time_limit is not positive, if n_paths is below one, or if x0 is not a (n_paths, d) finite batch inside domain (a start the caller authored raises rather than being clipped). An injected piece can raise the same way later, at the batch that serves it: a feasibility mask holding anything but 0/1, or a coordinate a seam hands the run - a restart ask of the wrong shape, a trial row, a step winner, a start - that is not finite or lands outside domain. A served f or g that is not finite is no error of that kind: nothing is committed and the path stalls, which the run carries on from.

Returns:
  • NPathResult –

    The run's end state and work report, an NPathResult.

Example

Minimize f(x) = ‖x - 3‖² by handing the engine a batched objective:

>>> import jax
>>> import jax.numpy as jnp
>>> from soar_lite import Domain, n_path_schedule

>>> def eval_f_g(x):
...     g = 2.0 * (x - 3.0)
...     return (jnp.sum((x - 3.0) ** 2, axis=1), g, None)

>>> box = Domain([(-5.0, 5.0), (-5.0, 5.0)])
>>> result = n_path_schedule(
...     eval_f_g,
...     n_paths=4,
...     domain=box,
...     # the flock the caller hands in; iteration 0 places it
...     x0=jnp.array(
...         [[-1.0, -1.0], [1.0, 1.0], [-4.0, 4.0], [4.0, -4.0]],
...     ),
...     max_iters=30,
... )

>>> result.x          # ≈ [3., 3.]
Array([3., 3.], dtype=float32)

>>> result.f           # 0.0: this quadratic is solvable exactly
0.0

A per-point scalar can be wrapped into this shape with pointwise.

pointwise

pointwise(
    objective: Callable[[ndarray], ndarray],
    *,
    feasible: Callable[[ndarray], ndarray] | None = None,
) -> tuple[EvalFG, EvalF]

Build both eval seams from one per-point objective.

objective is a scalar function of a single point, (d,) -> () - the shape jax.value_and_grad differentiates - and feasible is the per-point predicate that marks a point viable, (d,) -> () of a boolean. Both are vmapped here, so the caller writes neither jax.vmap nor jax.value_and_grad. The fused gradient is the per-row one, vmap(value_and_grad(objective)), not value_and_grad of a summed batch, which would make each row's gradient pass through the sum and so depend on every other row.

Feasibility is vmapped on its own because it cannot ride inside value_and_grad: that transformer differentiates a scalar output, so a function returning (f, feas) would be differentiated as a pair. Keeping feasible a separate point predicate leaves both halves scalar.

The pair comes back fused-first, matching n_path_schedule's two evaluation seams: eval_f_g= takes the first, eval_f= the second. Both are lazy closures, so building them runs nothing, and a caller who wants only the fused seam discards the other with eval_f_g, _ = pointwise(objective).

Both are ordinary functions, so either can be wrapped in jax.jit before it is handed over. What that buys is the objective's own ops fused into one kernel per batch instead of compiled one apiece, and what it costs is that jax caches a trace per argument shape: the engine serves only the paths that owe something in a round, so the batch length moves run to run and each new length compiles again. A traced seam is fine on the engine's side of the call - the batch is read on the host (its values, its feasibility flags, the box check), all of it after the seam has returned.

The value-only half is the fused objective's own forward pass, vmap(objective) - the same forward computation, so returning it costs nothing and buys the engine's cheap-trial path. That does not make this the evaluation seam for a value-only objective: a function JAX cannot differentiate cannot be objective here at all, so a caller holding values and no gradient needs a value-only adapter of its own.

Parameters:
  • objective (Callable[[ndarray], ndarray]) –

    the per-point objective, (d,) -> (); a function jax.value_and_grad can differentiate, which is what makes the fused half exist.

  • feasible (Callable[[ndarray], ndarray] | None, default: None ) –

    the per-point feasibility predicate, (d,) -> () of a boolean; None (the default) marks every point viable, the same None both evaluation seams accept.

Returns:
  • tuple[EvalFG, EvalF] –

    The two evaluation seam shapes n_path_schedule takes, as a pair. eval_f_g a fused (f, g, feas) batch, eval_f its value-only (f, feas) sibling.

Example

Both seams for an objective restricted to the half-plane x[0] >= 0:

>>> import jax.numpy as jnp
>>> from soar_lite import pointwise

>>> eval_f_g, eval_f = pointwise(
...     lambda x: jnp.sum((x - 2.0) ** 2),
...     feasible=lambda x: x[0] >= 0.0,
... )

>>> x = jnp.array([[1.0, 1.0], [-3.0, 1.0]])
>>> f, g, mask = eval_f_g(x)

>>> print(f, mask)          # the second row is infeasible
[ 2. 26.] [ True False]
>>> print(g[0])             # per row, 2*(x - 2)
[-2. -2.]
>>> print(eval_f(x)[1])     # the value-only mask agrees
[ True False]

The mask is a boolean because feasible returns one; 0/1 is the other spelling both seams accept. Nothing here drops the infeasible row - it was evaluated, and its value is what priced it - so the run reads the mask when it decides what to report.

Results

One run's end state — the result, the work it billed, and the status that names why it ended — and the two point types the plugins exchange: a PathPoint is a committed point, a ValuePoint is one whose value is read and whose gradient is still owed, and a bare Point is one nothing has been read from yet. Construct them as Point(x), ValuePoint(x, f), PathPoint(x, f, g).

NPathResult dataclass

End state of one n_path_schedule run.

The answer is spelled the way a point is: x and f are the best feasible evaluation the run recorded, which need not be a PathPoint the run committed: a value-only trial counts, and so does a served point whose gradient never passed the commit gate. The flock pair prefixes those same two names with flock_. It is n_iters, not scipy's nit, to sit beside the four work counts: one iteration may serve several batches (a restart's starts plus the method's trials), so an iteration is not a batch.

The work the run billed lives in work (Work), which is what those four counts are; they also read flat on the result, as its aliases.

Two deliberate departures from scipy.optimize.OptimizeResult, whose fields these otherwise resemble: success/message are absent, because the engine has no convergence criterion of its own - apart from the caller's own gates (max_iters, time_limit, budget_check), it stops early on its own initiative only for an objective with no floor or for a flock in which every path stalled with restarts off - and f is the best over feasible points only.

Example

Reading a finished run - the answer, then the flock, then why it stopped:

>>> import jax.numpy as jnp
>>> from soar_lite import Domain, n_path_schedule

>>> result = n_path_schedule(
...     lambda x: (jnp.sum(x**2, axis=1), 2.0 * x, None),
...     n_paths=3,
...     domain=Domain([(-4.0, 4.0), (-4.0, 4.0)]),
...     x0=jnp.full((3, 2), 2.0),
...     max_iters=20,
... )

>>> result.status              # why it stopped
'max_iters'
>>> float(result.f)            # the answer
0.0
>>> result.flock_x.shape, result.flock_f.shape
((3, 2), (3,))
>>> int(result.n_iters)        # iterations, not batches
20

x and f are the best recorded feasible point, which is not necessarily a row of flock_x: the path that found it may have been restarted afterwards. Read flock_* for "where did each path end up" and x/f for the answer. The cost side is work, which counts points and batches per seam; the four flat counts on the result are its aliases.

x instance-attribute

x: ndarray

The argmin in the coordinates the engine was handed, shape (d,).

Not necessarily a row of flock_x, and not necessarily a PathPoint: the best point may come from a path that was restarted afterwards, or from a value-only trial no path ever held. All nan when no feasible point with a finite value was ever served - the nan reading of f. A feasible -inf names its point instead: x is that point and f is -inf. So x is nan only when no feasible point carried a finite value and none priced the objective at -inf.

f instance-attribute

f: float

x's objective value, the minimum over finite feasible recorded evals.

nan when no feasible point carried a finite value and none evaluated to -inf; -inf when a feasible point evaluated to it.

flock_x instance-attribute

flock_x: ndarray

Each path's held coordinates as the run ended, shape (n_paths, d).

The coordinates each path actually holds; rows are neither filtered nor sorted. A path that never held a usable point has an all-nan row.

flock_f instance-attribute

flock_f: ndarray

Each path's held value as the run ended, shape (n_paths,).

nan for a path that never held a usable point.

work instance-attribute

work: Work

The work the run billed, per seam and per axis; see Work.

The single home of the four counts: the n_f_g_batches, n_f_g_points, n_f_batches and n_f_points attributes below are read-only aliases for its fields.

n_iters instance-attribute

n_iters: int

Completed engine iterations; iteration 0 is the flock's placement.

A half-finished iteration is not counted: neither one a closed gate cut short at a batch, nor the one that ended the run (unbounded, all_stalled).

status instance-attribute

status: NPathStatus

Why the run stopped; see NPathStatus.

n_f_g_batches property

n_f_g_batches: int

Fused batches served; Work.n_f_g_batches, read flat.

n_f_g_points property

n_f_g_points: int

Fused points served; Work.n_f_g_points, read flat.

n_f_batches property

n_f_batches: int

Value-only batches served; Work.n_f_batches, read flat.

n_f_points property

n_f_points: int

Value-only points served; Work.n_f_points, read flat.

Work dataclass

What one run billed, on two axes that never mix.

Four counts instead of scipy's single nfev. Which evaluation seam served the work decides the pair: n_f_g_batches and n_f_g_points for the fused one, n_f_batches and n_f_points for the value-only seam. Batches are the parallel wall-clock cost and points the serial one. Which axis a comparison reads is the caller's business; a run that never serves a value-only batch - no eval_f seam, or one no method reads - reports zero on both f counts.

These are reports, not caps: no count stops a run on its own, only the run's stop predicates decide. A caller's budget_check gate is handed one of these: it reads the ledger and cannot write it. Frozen, and replaced rather than mutated as the run charges it, so a reference to one is the snapshot of the moment it was handed over.

At a serve site the gate is handed the ledger the pending batch would leave, which is why a points ceiling holds: a batch is charged only if the gate allows it, and the count a refusal was decided on never enters the ledger. What the report carries is therefore exactly the ledger the last allowed batch left - never one a gate refused. At the loop head, where no batch is pending, the gate is handed the ledger as it stands.

The iteration count is not here: max_iters bounds it, and one iteration may serve several batches (a restart's starts plus the method's trials), so an iteration is not a batch.

n_f_g_batches instance-attribute

n_f_g_batches: int

Fused batches served: the parallel wall-clock count.

n_f_g_points instance-attribute

n_f_g_points: int

Fused points served: the serial-cost count.

n_f_batches instance-attribute

n_f_batches: int

Value-only batches served (the eval_f seam).

n_f_points instance-attribute

n_f_points: int

Value-only points served (the eval_f seam).

NPathStatus module-attribute

NPathStatus = Literal[
    "max_iters",
    "time_limit",
    "budget_exhausted",
    "unbounded",
    "all_stalled",
]

Why a run ended: five names for five ways to end one.

The three gates, in the order they are checked: "max_iters" (the iteration horizon), "time_limit" (the wall-clock deadline), "budget_exhausted" (the caller's extra batch gate). The first one that holds is the one reported, so a last iteration that reaches the horizon as the deadline passes reports "max_iters". Then the two early endings: "unbounded" (a feasible point evaluated to -inf) and "all_stalled" (no path can move and restart_stalled is off).

Point dataclass

A point the run has located, with nothing of it read yet.

Three kinds of point say how much of one the run has read, and each is the next one's base class: coordinates alone here, the value in ValuePoint, the gradient as well in PathPoint. What has been read is therefore the point's type rather than a field that may hold None - a half still owed cannot be asked for at all, and no caller has to check whether it may.

Everything the run produces starts as one of these, because producing a point and reading it are two decisions: a restart start arrives from a model that read nothing, and a method may name a winner by its own rule instead of by its value.

x instance-attribute

x: ndarray

Coordinates, shape (d,), in the run's coordinates.

ValuePoint dataclass

Bases: Point

A point whose value has been read; its gradient is still owed.

A value-only trial row is one of these, and stays one until settle buys the gradient and it becomes a PathPoint. It is also what a method holds for a winner it named unread and then had read: the read is the only thing this class says about a point, whoever asked for it.

The interesting half of the definition is the missing one. There is no gradient-only point, and no eval_g seam that would serve one: a caller hands in a single objective whose value and gradient come back from one call, so a gradient is only ever bought as the pair, and the value that rides free with it is kept rather than thrown away.

f instance-attribute

f: float

The objective's value there.

PathPoint dataclass

Bases: ValuePoint

One path's point: coords x, value f, gradient g = ∂f/∂x.

The engine builds these and the local method receives them; a caller normally reads the run's outcome through NPathResult instead of constructing one. A point is a candidate until is_usable passes, so a non-finite half is allowed on a point that has not been committed.

x instance-attribute

x: ndarray

Coordinates, shape (d,), in the run's coordinates.

f instance-attribute

f: float

The objective's value there. Finite for any point a path actually holds (is_usable gates the commit); a point still being considered may carry a non-finite value.

g instance-attribute

g: ndarray

The gradient there, shape (d,); finite under the same is_usable gate as f - held points are finite, candidates need not be yet.

is_usable property

is_usable: bool

Return whether this point may be committed as a path's point.

Both halves must be finite, because both are carried forward: a non-finite f cannot be reported, re-started from or finished on, and a non-finite g is proposed from and blended into the secant, so one NaN there poisons that coordinate's magnitude EMAs for the rest of the run. f is asked first, so a dead value skips g's finite scan.

The domain

The box, its per-dimension scales and its draws: everything a restart model may read, and the object a projection is built on. Bounds is the box in scipy's spelling, which Domain normalizes; DrawFn is one dimension's draw, the sampler a caller injects.

Domain

The coordinates a restart model may read, and how a start is drawn.

A domain carries the box, the per-dimension scales and the per-dimension draws, and validates all three once at construction: a NaN side, a lower side above its upper, a scale that is not a (d,) vector of finite positive values, or a sampler count that is not d are refused here rather than deep inside a clip or a draw. It is concrete - a caller sampling with no surrogate needs nothing more - and Projection wraps one to add the feature map a fitted model reads.

A side may be unbounded. The box then declares only the dimension and which sides are unbounded; scale is what carries a length there, because no width exists to read one off. Not even a bounded side's width is a natural unit: scale is in coordinate units, so a caller changing a variable from meters to millimeters changes scale, never the box.

draw is the one contract: (key, n) -> (n, d) starts drawn one dimension at a time.

Example

Sample starts with no engine and no surrogate, the case a domain alone covers:

>>> import jax
>>> from soar_lite import Domain

>>> domain = Domain([(0.0, 1.0), (None, None)], scale=[1.0, 2.0])
>>> domain.draw(jax.random.PRNGKey(0), 3).shape
(3, 2)

The first column is uniform inside its bounded side, the second draws N(0, 2^2) because nothing there is declared.

d instance-attribute

d: int

The dimension: the number of pairs bounds declares.

Every shape in the engine is read off it - x0 is (n_paths, d), a proposal is (d,) - so a caller never states the dimension twice.

lo instance-attribute

lo: ndarray

The lower side per dimension, (d,); -inf where that side is free.

hi instance-attribute

hi: ndarray

The upper side per dimension, (d,); +inf where that side is free.

bounds instance-attribute

bounds: Bounds

The box as the caller declared it, unbounded sides included.

scale instance-attribute

scale: ndarray

The prior width per dimension, (d,), in coordinate units.

It is the length the default draw is measured in on an unbounded side, and what SphereProjection normalizes by; a dimension whose spread is far from a unit scale needs its own entry here rather than a different box.

center instance-attribute

center: ndarray

The box's midpoint per dimension, (d,); zero outside bounded_dims.

width instance-attribute

width: ndarray

The box's width per dimension, (d,); zero outside bounded_dims.

bounded_dims instance-attribute

bounded_dims: ndarray

The dimensions with both sides finite, (d,).

width and center read off it, so a dimension outside it is zero in both.

free_dims instance-attribute

free_dims: ndarray

The dimensions with neither side finite, (d,).

A dimension in neither mask is the half-bounded one, whose default draw alone has a boundary to respect.

__init__

__init__(
    bounds: Bounds,
    *,
    scale: ndarray | Sequence[float] | None = None,
    samplers: Sequence[DrawFn | None] | None = None,
) -> None

Validate and carry the declared box, the scales and the samplers.

Parameters:
  • bounds (Bounds) –

    the box, scipy-style pairs or a (d, 2) array. A side may be None or +-inf for an unbounded domain; a NaN side, or a lower side above its upper bound, is refused. There is no box for a domain to default to: the dimension and the unbounded sides are what the box declares.

  • scale (ndarray | Sequence[float] | None, default: None ) –

    per-dimension prior width in coordinate units, a (d,) vector or None for every dimension at one. A projection that normalizes compares the entries to each other. The common magnitude is not free either: scale is the length the default draw is measured in, so a dimension whose coordinates span far more or far less than a unit scale should carry its own entry.

  • samplers (Sequence[DrawFn | None] | None, default: None ) –

    one optional draw per dimension, d entries; a None entry keeps the default for that dimension - uniform inside a bounded dimension, N(0, scale_i^2) inside a free one, and that same normal restricted to the domain inside a half-bounded one (exactly one finite side), where drawing the unrestricted normal would step over the side the caller did declare. Dimensions are drawn independently, so a prior that couples them needs its own GlobalModel, not a domain.

Raises:
  • ValueError –

    If the box is malformed, or scale is not a (d,) vector of finite positive values, or samplers is not d entries long.

draw

draw(key: ndarray, n_points: int) -> jnp.ndarray

Return (n_points, d) restart starts, one dimension at a time.

A dimension with an injected DrawFn takes its column from that, else from that dimension's default: uniform inside a bounded side, N(0, scale_i^2) inside a free one, and the same normal truncated to the domain inside a half-bounded one - the default never steps over the side the caller declared. An injected sampler is the caller's own statement about the dimension's spread, so nothing checks the drawn values against scale: an arbitrary distribution publishes no spread to check them against.

Raises:
  • ValueError –

    If n_points is below one, or a column does not come back (n_points,) long.

Bounds module-attribute

Bounds = (
    Sequence[tuple[float | None, float | None]]
    | jnp.ndarray
)

The search box in scipy's spelling, which Domain normalizes.

One (lb, ub) pair per dimension, where either side of the pair - the lower or the upper bound - may be None or +-inf, meaning unbounded there. A (d, 2) array is the same data row-wise, for callers that already hold one.

DrawFn module-attribute

DrawFn = Callable[[jnp.ndarray, int], jnp.ndarray]

One dimension's draw, injected per dimension.

sampler(key, n) returns n coordinates for that one dimension, shape (n,). Injected per dimension so a restart model can sample where a bounded box does not reach; None leaves the domain's own default in place - uniform inside a bounded side, N(0, scale_i**2) where the domain is free, and that normal restricted to the declared side where it is half-bounded.

Evaluation seams

The objective at the seam, in three shapes: the fused pass a run uses by default, the value-only half a caller may add, and the trial hook the engine hands a step in place of the caller's own function.

EvalFG module-attribute

EvalFG = Callable[
    [jnp.ndarray],
    tuple[jnp.ndarray, jnp.ndarray, jnp.ndarray | None],
]

The objective as one fused pass: the one seam a run must supply.

Takes x rows (M, d) in the run's coordinates and returns (f: (M,), grad_x: (M, d), feas: (M,) | None). Value and gradient come back together on purpose - the caller's fused value_and_grad is one AD pass, and the step's call sites want both at once: the batched equivalent of scipy's jac=True convention.

feas is optional: None means every point is feasible, otherwise 0 marks a point infeasible and 1 marks it feasible; any other value is refused rather than read as truthiness.

EvalF module-attribute

EvalF = Callable[
    [jnp.ndarray], tuple[jnp.ndarray, jnp.ndarray | None]
]

The objective's value half alone, for a caller that also holds one.

Same x rows in, (f: (M,), feas: (M,) | None) out. Feasibility is included because it decides the value the run reports and whether a -inf ends the run, neither of which f alone can tell. Opting in lets a step that enumerates serve its trials for their values alone and buy the winners' gradients afterwards, together in one fused batch.

ServeTrials module-attribute

ServeTrials = Callable[
    [Mapping[int, Point]], Mapping[int, ValuePoint]
]

The trial hook a step is handed: one point per path in, one read point back.

Each call is one round over the paths it names - path -> Point in, the same paths out with their values - and a method calls it as many times as its enumeration needs: one round, ten rounds, or none. One point per path per call rather than a batch of many is what keeps a round's memory at n_paths * d however long the enumeration runs; multiplicity lives in the number of calls, so a line search that returns the best of its rounds holds one round at a time and the run's peak never grows with how far a method looks.

What each answer carries follows the run's seams - the value alone when eval_f is connected, both halves when it is not - so an answer is a ValuePoint, and a PathPoint on the fused seam. It is what LocalSolver.propose receives in place of the caller's own function. Keys are paths the step was asked about: the engine refuses a round naming any other, and refuses a point outside the box, naming the path. A path the round leaves out is simply not served - nothing requires a round to cover the cohort.

Local solvers

LocalSolver is the engine's local seam: the engine calls it, never the reverse. DiagonalPreconditioner is the solver the engine runs when the caller names no other.

LocalSolver

Bases: Protocol

The search method the n-path engine drives (its first plugin point).

The engine owns the schedule - batch composition, the box test, the shared horizon, the n-path state machine (restart/step/stall), the best f⋆, and the gradient purchase - and the method owns the search: direction, step size, acceptance, and how many points a step looks at. A step is one propose call, so a method that wants a trial grid or a line search runs it inside that call: the engine hands propose the run's trial hook (serve_trials) and serves whatever the method asks for. Runs end on the caller's horizon, not on the method. All state is per path, lives inside the instance, and is opaque to the engine - implementers index it by path i.

A path's point reaches the method in exactly two places: restart(points), which places it, and step(points), which moves it. Both are the engine's own commit points, so a method that keeps the point it was handed holds the one the engine holds. Both carry one row per path for every path that landed this iteration, keyed by path and in one call, so a method that keeps per-path state updates it in one place. A path that did not land - the method declined it, or its point arrived unusable - is in neither call: it stalls where it stands. A method that steps from a point must keep it, because no later call hands it back: propose reads the current point off the method's own state and answers from it. step is the only place a landed point is announced, so it is also the only place the method may advance its model - a secant is a step that was taken, and only the step callback is told one was.

The split between the two evaluation halves is the method's cost lever. A step's value is what its enumeration compares, so the method reads it: serve_trials serves a batch of candidate points for their values alone - or the fused pair, when the caller connected no eval_f - and may be called as often as the enumeration needs. A step's gradient is wanted only for the winner, so the engine buys it afterwards, in the iteration's one fused batch (settle): whatever is still owed, which is every read winner's gradient and both halves of every unread winner and restart start. step then hands the result back. A point therefore leaves propose as whatever it has read: a bare Point when the method never read it, a ValuePoint when it read it through serve_trials, and a PathPoint when the caller supplied no eval_f seam and the hook served the pair.

domain is handed to propose rather than stored, because the solver carries no search space of its own; a start is placed by restart. A step and every trial row must already lie inside that box: the engine checks both and refuses what misses, so clipping is the method's own defence against the roundoff in its own arithmetic, not something the engine does for it.

These methods are called by the engine on its own schedule - restart and step once per iteration with the paths that landed, propose once per iteration for the paths that step - so they trust their arguments: this Protocol is the whole contract.

Example

A whole method - fixed-step gradient descent, one point per path, no trials read - which is enough to converge, because the engine pays for the gradient this method never asks for:

>>> import jax.numpy as jnp
>>> from soar_lite import Domain, Point, n_path_schedule

>>> class FixedStep:
...     def __init__(self, rate=0.25):
...         self.rate, self._point = rate, {}
...     def restart(self, points):
...         self._point.update(points)
...     def step(self, points):
...         self._point.update(points)
...     def propose(self, paths, domain, serve_trials):
...         del serve_trials          # this method reads no trials
...         return {
...             i: Point(
...                 jnp.clip(
...                     self._point[i].x - self.rate * self._point[i].g,
...                     domain.lo,
...                     domain.hi,
...                 )
...             )
...             for i in paths
...         }

>>> result = n_path_schedule(
...     lambda x: (jnp.sum((x - 3.0) ** 2, axis=1), 2.0 * (x - 3.0), None),
...     n_paths=2,
...     domain=Domain([(-5.0, 5.0), (-5.0, 5.0)]),
...     x0=jnp.array([[-1.0, -1.0], [1.0, 1.0]]),
...     max_iters=40,
...     local_solver=FixedStep(),
... )
>>> bool(jnp.allclose(result.x, 3.0, atol=1e-2))
True

Nothing is read yet, so the winner is a bare Point and the gradient reaches step through the engine's settle batch. A method that reads its candidates through serve_trials hands each winner back as the ValuePoint it read instead, and the same batch settles only the gradient.

restart

restart(points: Mapping[int, PathPoint]) -> None

Seed each path's state from a fresh start point (its one cold start).

Called by the engine each time it places paths on points: once at initialization, and again on every redraw — of a stalled path with restart_stalled on, or of a path that holds no point, which is re-drawn either way. Every path that landed a start this iteration is in the one call; the engine has one way to place a path, so a method need not tell "first" from "again" - both drop that path's state to the cold one. A restarting path does not also step, so this call and step never name the same path in one iteration. One of the two calls that hand a point over, so a method that steps from a point keeps this one.

step

step(points: Mapping[int, PathPoint]) -> None

Take the steps the engine just committed: each path stands at its point.

The engine's only call site is the commit of the usable winners, with each point the settled one it committed, so every recorded step was taken and can never disagree with the path. No path the engine refused (not is_usable) and no path whose stopping test held is in the call. Each point means what it means in restart: the point that path now stands at. The point it stepped from is the method's own record, not an argument - the same rule that makes propose read its point instead of being handed it.

propose

propose(
    paths: Sequence[int],
    domain: Domain,
    serve_trials: ServeTrials,
) -> dict[int, Point | None]

Answer one step for each path in paths: its winner, or None.

One call covers every path that steps this iteration, so a method that wants a trial grid proposes the cohort's samples in one round rather than once per path. The answer is keyed by the paths asked, and None means the method declines to name a winner: its stopping test holds, or the trials it read left it nothing usable to pick. Either way the engine stalls the path where it stands, serving nothing further and committing nothing.

A non-None entry is the step's winner, held as the kind of point the method has read it to: a bare Point it never read, or a ValuePoint it read through serve_trials (a PathPoint on the fused seam). The engine buys whatever is still owed, then commits it as the path's next point and calls step - unless it is not is_usable, in which case the path stalls and step is never called.

serve_trials is the run's trial hook. Every call serves one round and reports it to the run's best and to the global model, exactly as a fused batch is reported, so a method may call it as freely as its enumeration needs - a round is one point per path, so a long enumeration costs more rounds, never more memory. With no eval_f seam the same call serves the fused pair, and the answers are PathPoints. Every point it is handed must lie inside domain: the engine checks the round and refuses one that misses, naming the path, so a method enumerates over the box it was handed rather than leaving the hook to repair its grid.

The winner must already lie inside domain for the same reason: the method is handed the box, and the engine refuses a step that leaves it instead of sliding it back onto a wall.

DiagonalPreconditioner

Bases: LocalSolver

Per-coordinate secant magnitude ratio with a gradient-norm floor.

Each coordinate carries its own effective inverse curvature precon_i, of dimension [x]²/[f], estimated from the magnitude ratio of one secant (s = x_k - x_{k-1}, y = g_k - g_{k-1}), and the step is Δx_i = -precon_i·m_i. Every step takes the full proposal at alpha0 along its own direction, and step records the committed step. The two phases differ only in the direction: the warm-up - the first step after a restart, with no secant pair yet - descends along -g, and every later step along -precon⊙m.

A path whose stopping test holds describes no step: propose answers None for it and the engine stalls it, so a converged path is not stepped off its stationary point. The test is on the projected gradient, ‖P g‖ ≤ τ_rel·‖g_0‖, with the components whose descent direction points out of the box dropped at a wall - which is how a constrained minimum sitting on a wall reports done rather than stationary.

Why the ratio is a per-coordinate magnitude rather than a matrix, why the two moment spellings agree, what the floor is anchored to, and what beta and mu buy: the explanation page's local-step section (how it works).

References
  • Conn et al. (2000), Trust region methods (SIAM) — the textbook account of the secant equation and the SR1 update, whose diagonal degeneration is this ratio.

__init__

__init__(
    *,
    moment: Literal["abs", "rms"] = "rms",
    beta: float = 0.63,
    mu: float = 0.0,
    theta: float = 0.001,
    alpha0: float = 1.0,
    tau_rel: float = 1e-06,
) -> None

Store the knobs; per-path state is seeded by restart.

alpha0 multiplies the step's direction, and the two phases give that multiplier different units. In the steady state -precon⊙m is already a displacement, so alpha0 reads as a fraction of the natural step. In the warm-up the direction is -g, a gradient-like [f]/[x] quantity, so alpha0 carries [x]²/[f] there and no unit invariance holds - at the default alpha0 = 1 the warm-up step is literally x - g. One knob covers both phases. A numeric knob outside its range raises ValueError here, once per object; nothing downstream re-checks it. moment is the one knob whose whole range is its annotation's (a Literal), so it is left to the type checker: at run time any value but "abs" takes the "rms" branch.

Parameters:
  • moment (Literal['abs', 'rms'], default: 'rms' ) –

    which magnitude ratio to smooth, "abs" (mean of |s|, |y|) or "rms" (mean of s², y²).

  • beta (float, default: 0.63 ) –

    EMA decay for the secant-magnitude smooth (window ≈ 1/(1-β) steps), in [0, 1); 0 keeps no history, so precon reads the newest accepted secant.

  • mu (float, default: 0.0 ) –

    EMA decay of the gradient history blended into the direction, (1 - mu)·g + mu·m_prev; 0 (the default) leaves the bare gradient, in [0, 1).

  • theta (float, default: 0.001 ) –

    gradient-norm floor coefficient (λ = θ·|g_i| for "abs", θ·g_i² for "rms"), >= 0.

  • alpha0 (float, default: 1.0 ) –

    direction multiplier every path is armed at, > 0; one knob, two units - a fraction of the natural step in steady state, and [x]²/[f] in the warm-up, where the direction is -g.

  • tau_rel (float, default: 1e-06 ) –

    relative gradient-norm stopping threshold, tested against ‖g_0‖, in (0, 1).

Raises:
  • ValueError –

    If a numeric knob is outside its range: beta and mu in [0, 1), theta >= 0, alpha0 > 0, tau_rel in (0, 1).

restart

restart(points: Mapping[int, PathPoint]) -> None

Seed each path at its point: warm-up armed at alpha0, g0 kept, no estimate.

The engine's only cold start, so this runs at initialization and after every restart - the secant history never carries across one. The momentum history is re-seeded at this start's own gradient for the same reason: a restart is where a path's history begins again. The point itself is kept, because no later call hands it back: it is the first of the contract's two arrivals.

step

step(points: Mapping[int, PathPoint]) -> None

Take the steps the engine just committed, one path at a time.

Each point means what it means in restart: the point that path now stands at, handed over once. The point it stepped from is the record's own, so the pair the step observed is read entirely off (record, point).

Only the winners are taken in, never a trial the method's own enumeration rejected: a secant from a point the path never stood on would smear the magnitude EMAs. The engine calls this with the exact points it just committed, so both histories see what each step observed: the pair (Δx, Δg) for the curvature, and the gradient at the point arrived at for the momentum. The first call after a restart is the warm-up pair and seeds the secant EMAs outright; later calls blend at beta - the record's is_warmup is that same first-step marker, cleared here. This is also where a step is re-armed: a winner the engine refuses never reaches here, so the method is left untouched rather than half-reset.

propose

propose(
    paths: Sequence[int],
    domain: Domain,
    serve_trials: ServeTrials,
) -> dict[int, Point | None]

Propose one step for every path in paths, or None if it is done.

A Point here carries the clipped proposal alone, nothing read, so the engine's settle can buy its f and g in one fused batch together with everything else the iteration produced. None means the path's stopping test holds: the engine stalls it where it stands and takes no step.

The proposal is clipped into domain here because the engine refuses a step that lands outside the box rather than clipping it: a step is the method's own, so holding it inside the box is the method's own job too.

serve_trials is the value-only evaluation hook, for a method that rules its own trial grid; this one takes a single full step, so it leaves the hook unused and lets settle buy the gradient. That is also why every proposal comes back unread: nothing was.

Warm-up: x + alpha0·(-g). Afterwards: x + alpha0·(-precon⊙m), since each commit and each restart re-arms the path at the knob's own multiplier. Steps from the point the record holds - restart placed it and step moved it - so the step's start is not passed in a second time. m is the history step left behind: the EMA over the gradients at committed points, which includes the gradient of the point this step starts from. At mu = 0 the last step stored that gradient outright, so the direction is the bare gradient.

Global models

GlobalModel is the engine's restart seam, called by the engine and never calling back. SampleGlobalModel draws from the domain; BLRGlobalModel fits a posterior over the features its Projection hands it and descends its acquisition with a MinimizeFn, defaulting to descent_minimize. AcquisitionFn is what that minimizer minimizes, MinimizeFn the callable's shape, and descent_minimize the one the package ships.

GlobalModel

Bases: Protocol

The engine's restart-point source (its second plugin point).

The model answers the two questions the engine cannot: where a restart lands (propose) and what the run has learned (observe). The engine feeds it every batch it serves and asks for points on a restart, or for iteration 0's placement when no x0 was handed in, so propose is the only place it is ever asked: a model that wants more evidence than it has can answer with a plain draw and the engine has no opinion.

A model carries no search space of its own. The run has one box, the engine owns it, and propose is handed that Domain at every ask - so a model must not remember one. That is what keeps a fitted geometry and a fallback draw in the same coordinate unit as the box test, with no second box to reconcile.

One instance serves the whole run (like LocalSolver), so whatever it accumulates lives inside it and the engine never reads it. The methods are called by the engine on its own schedule - observe once per served batch, propose once per cohort of restarting paths (all the paths that restart in one iteration, in one call) - so they trust their arguments: this Protocol is the whole contract.

The flock is not this contract's: a caller's own starts go to n_path_schedule as x0, and the engine places them without asking any model.

Implementing this pair is the whole extension point; a projection is a utility a propose may read, not part of the contract.

The smallest implementation is SampleGlobalModel below - observe keeps nothing, propose answers with the domain's own draw - so a model that fits something is that shape with a fit added: BLRGlobalModel keeps what it was handed and answers from its posterior once it has enough.

observe

observe(served: Mapping[int, ValuePoint]) -> None

Fold one served round into the model's evidence.

Called right after a batch is served, in the engine's coordinates and before anything is decided on it: served maps each path in the batch to the point it was served there, so the model knows whose point it holds rather than only how many rows arrived. The values are Python floats - the same values the run compares, and one host transfer per batch rather than a device sync per row - and a point served for its value alone carries no gradient: a fused batch arrives as PathPoints, which are also ValuePoints, so a model that wants gradients reads them off the type instead of a second nullable argument.

The mapping's iteration order carries no promise - nothing downstream is entitled to it - so a model that needs a particular row order arranges one itself. Keys are unique within one call; a point may arrive twice across calls - a step's trial is served for its value first and for its gradient later if it wins - so a model keyed on coordinates sees the same design with more evidence.

Nothing is filtered for feasibility: the model fits the raw objective everywhere, and only the value the run reports is filtered. Batches the run never decides on arrive too (a trial that lost its step, the batch that ended an unbounded run), because the work was served.

propose

propose(
    paths: Sequence[int], domain: Domain
) -> dict[int, Point | None]

Answer one fresh start per path asked about, keyed by that path.

paths is every path that restarts this iteration - on iteration 0, every path when the caller handed no x0 - in ascending order, and domain is the box the answers must land in and the one statement of the dimension. Each answer is a bare Point - a place the model read nothing of, which is what a start is - and that type is where the shape and the coordinates' frame are stated, so no model restates them. None says this path gets no start from this model, and the engine leaves the path where it stands. Holding no point, it is asked again next iteration, so a decline is not a stopping rule and does not end the run - unlike None from a method's propose, which stalls that path: it is asked again only when restart_stalled is on, which is the default.

The answer crossing the other way is a ValuePoint: what a model is handed is always at least read, and what it hands back never is. Those are the two directions of one hierarchy, so a model that wants to read a candidate it is about to place asks the run for the value rather than guessing one - only a method holds a serve_trials seam, though, and a model's answer is read by the engine's own settle batch.

The engine checks every answer it is given at the batch boundary - a (d,) point, finite and inside the box - and raises ValueError naming the path and the dimension on a miss: an answer outside the box is a model disagreeing with the box it was handed, which the engine names rather than repairing. The box test allows the few ulps a start computed on a boundary can round by.

The model owns its randomness - an instance holds its key - so a seeded model answers the same way twice. The engine builds paths in ascending order every time it asks, which is what lets a model draw one row per path and zip it in the order asked: the row a path gets is fixed by the path, not by when the request was made. The engine is the only caller of this hook, and it validates what comes back rather than the model validating what it was handed.

SampleGlobalModel

Bases: GlobalModel

The model-free default: draws restart points straight from the Domain.

Fits nothing - observe is a no-op - because with no surrogate the domain's own draw is the only distribution the run can synthesize. Whatever the domain admits, this draws: uniform inside a bounded side, N(0, scale^2) inside a free one, that same normal truncated inside a half-bounded one, and an injected per-dimension sampler where the caller said so.

__init__

__init__(*, key: ndarray) -> None

Bind the key the draws are split from.

Parameters:
  • key (ndarray) –

    the PRNG key the draws are split from.

observe

observe(served: Mapping[int, ValuePoint]) -> None

Ignore the evidence: a model-free sampler fits nothing.

propose

propose(
    paths: Sequence[int], domain: Domain
) -> dict[int, Point | None]

Draw one point per path, in the order the paths were asked.

BLRGlobalModel

Bases: GlobalModel

Restart points from a Bayesian linear posterior's log improvement.

observe accumulates the run's served batches (values only - the gradient is not fitted), and propose fits the closed-form weight posterior over those points and returns the minimizers of -log EI the injected minimize finds. Below two observations, or with every value equal, there is no spread to standardize by, so it answers with the domain's own draw.

Every knob is a fixed hyperparameter, not a fitted one. The geometry lives in the Projection this model builds for each ask - SphereProjection for the center-biased bend, IdentityProjection for no prior on where the optimum sits - and it is built from the domain that ask hands in. So the model carries the recipe and not a box: one instance asked inside a different box has no stale geometry and no second normalization drifting behind it. What this class adds on top is the value fit and the acquisition the injected minimize descends; the feature width is read off features, so any projection width fits.

The projection is optional. Left unset, the bent arm is the default, because that is the reference model - the one whose geometry cures the corner-seeking pathology. IdentityProjection stays the explicit alternate arm, for a task whose optimum lives on a boundary; it is a different prior, not a stand-in for "no projection".

References
  • Doumont et al. (2026), AISTATS — the spherical-linear model this class ports.

__init__

__init__(
    projection_factory: ProjectionFactory | None = None,
    *,
    minimize: MinimizeFn | None = None,
    var_prior: float = 1.0,
    noise: float = 0.01,
    key: ndarray,
) -> None

Bind the geometry recipe, the injected minimizer and the value fits.

Parameters:
  • projection_factory (ProjectionFactory | None, default: None ) –

    builds the Projection a given Domain is read through - partial(SphereProjection, mask=..., kappa=...) for a custom bend, IdentityProjection itself for the unbent arm. None (the default) is SphereProjection with its own defaults, the reference model's center-biased bend. Called once per propose, so the geometry is always the box that ask was handed, and the domain was already validated by Domain's own constructor.

  • minimize (MinimizeFn | None, default: None ) –

    the acquisition's inner optimizer, shape MinimizeFn. None (the default) is descent_minimize, the package's own restart-free n-path descent; a caller that wants another search, or another inner horizon (partial it), passes its own. The model holds the acquisition and hands it over, never descending it itself.

  • var_prior (float, default: 1.0 ) –

    weight-prior variance (the ridge scale paired with noise).

  • noise (float, default: 0.01 ) –

    observation-noise variance added to the posterior mean's self-covariance.

  • key (ndarray) –

    the PRNG key propose splits every ask from.

Raises:
  • ValueError –

    If var_prior or noise is not a finite positive value.

observe

observe(served: Mapping[int, ValuePoint]) -> None

Fold one served round into the model's value-only evidence.

A value-only round and a fused one contribute the same, since the surrogate fits values over coordinates. The round arrives keyed by path and is stacked as it arrives, so the fit depends on the points, not on how many paths a round happened to carry. The values arrive as host floats, one per point, so the finite check below costs no device sync per row. A non-finite value is dropped, not fitted: the engine observes the objective bottoming out at -inf before it stops, and one such row would drag the standardization with it. A point served twice is kept twice - under the tiny observation noise that is a slight double weight, which is what a second look at the same coordinate is worth.

Raises:
  • ValueError –

    If the round is wider or narrower than the first round folded in.

propose

propose(
    paths: Sequence[int], domain: Domain
) -> dict[int, Point | None]

Return one restart point per path: a draw until a fit is possible.

The box is the caller's, handed in per ask: the geometry is rebuilt from it here, and nothing about it is remembered between calls. Until the fit has a spread to standardize - below two observations, or with every value equal - the answers are the domain's own draw: uniform on a bounded side, its prior normal on a free or half-bounded one. Afterwards they are the injected minimize's local minimizers of -log EI over the box; the log form keeps the acquisition's gradient alive where the raw improvement has decayed to zero. It hands minimize the paths it was asked about and a fresh subkey, split from the model's key, and answers with what it returns: a start per path, or None for a path the minimizer could not place.

Raises:
  • ValueError –

    If no path was asked about, if minimize answers for a path this ask did not name, or if an answer is not a (d,) point.

AcquisitionFn module-attribute

AcquisitionFn = Callable[
    [jnp.ndarray], tuple[jnp.ndarray, jnp.ndarray]
]

What the injected MinimizeFn minimizes for BLRGlobalModel.propose: -log EI and its per-row gradient.

Takes (M, d) rows and returns (value: (M,), grad: (M, d)). Lower is better, the sign already carried in the value, so a minimizer needs no special case. Batched, so a minimizer that works off values reads a whole grid in one call, and one that follows the gradient gets it alongside.

MinimizeFn module-attribute

MinimizeFn = Callable[
    [AcquisitionFn, Domain, Sequence[int], jnp.ndarray],
    dict[int, Point | None],
]

The inner minimizer propose hands its acquisition to.

minimize(acquisition, domain, paths, key) returns one local minimizer of the acquisition inside domain for each path it was named, a Point, or None for a path it could not place. Keyed by path for the same reason the model's own answer is: a minimizer that runs an engine inside, or that enumerates per path, keeps its answers paired with the paths they belong to instead of with row positions, and reports the one path it could not place without inventing a coordinate for it. The domain is the one the ask was handed, not a box re-derived from it: a caller that declared a scale or a sampler meant it for every draw inside that box, including the inner minimizer's own starts. The paths come before the seed: what to ask for is the caller's question, the key only supplies the randomness. The model checks that no other path was answered and that each answer is one Point of the ask's width, and raises ValueError on a miss; a None answer is carried out as the model's own decline, so the engine leaves that path where it stands instead of restarting it from a point nobody chose.

Injected by the composition root and defaulting to descent_minimize, imported at construction rather than at module load: the model never descends the acquisition itself, it borrows the engine's own recipe, so there is one answer to how to descend rather than two, and this module still never reaches back into the engine's scheduler on import.

descent_minimize

descent_minimize(
    acquisition: AcquisitionFn,
    domain: Domain,
    paths: Sequence[int],
    key: ndarray,
    *,
    inner_iters: int = 40,
) -> dict[int, Point | None]

Descend an acquisition with one restart-free n-path run.

The engine inside the engine, in one direction only: the outer model hands over its acquisition, this driver runs the library's own descent and answers one minimizer per named path.

The inner run is a pure descent, not a restarting search:

  • restart_stalled=False - each path has one job, reach a local minimum from its draw; replacing it with a fresh draw is the outer run's business.
  • n_paths=len(paths) - the acquisition is batched, so one run of width len(paths) serves the whole cohort one row per path per batch, instead of len(paths) serial runs buying the same points with len(paths) times the batches.
  • no feasibility column - the acquisition is finite everywhere, so the fused seam carries None as its third slot.

The inner run draws its starts from domain - the object the ask was handed, so its scale and samplers reach the inner draws - and bills its own Work, none of which is added to the outer run's ledger.

A minimizer it could not place is answered None, never a coordinate: an inner path whose acquisition is not finite at its draw holds no point and its flock_x row is all-nan, so None is how the outer run is told to leave that path where it stands rather than restart it from a point the acquisition never ranked.

Parameters:
  • acquisition (AcquisitionFn) –

    the acquisition to descend, (M, d) -> ((M,), (M, d)): values and per-row gradients. Lower is better, the sign riding in the value.

  • domain (Domain) –

    the search box, as the ask declared it - the same object the outer run checks its answers against, scale and samplers included.

  • paths (Sequence[int]) –

    the paths to answer for, one local minimizer each.

  • key (ndarray) –

    the PRNG key the inner run's starts are drawn from. The model hands a fresh subkey split for this ask alone.

  • inner_iters (int, default: 40 ) –

    the inner run's horizon - an upper bound, not a convergence test; a path that settles stops earlier, so a run that settles early ends on all_stalled before reaching it. Default 40.

Returns:
  • dict[int, Point | None] –

    One Point inside domain per named path, or None for a path the inner run could not place.

Raises:
  • ValueError –

    If paths is empty.

Projections

The geometry a global model reads its features through: the model's own extension point, not an engine seam. SphereProjection bends the coordinates toward the pole, IdentityProjection reads them as they are, and a ProjectionFactory is the recipe a caller hands the model to pick one per ask.

Projection

Bases: ABC

The feature map a restart model reads domain coordinates through.

A projection wraps a Domain and adds one map: features turns every (M, d) batch of coordinates into an (M, w) batch of feature rows, which a model fits its own posterior over - w is this projection's width, read off features by the model rather than assumed d + 1.

The domain stays the domain's: a projection reads its box, scales and draws; it is not one. That keeps the two jobs apart at the type level - a caller who only samples builds a Domain and never meets a projection, and a projection held where a Domain is expected is a wiring error instead of a silently accepted one - and keeps scale and samplers out of this constructor, where every fitted model would otherwise have restated them.

features is the one contract: a pure query of the coordinates, the same (M, d) input mapping to the same (M, w) rows, with w stable across calls for one projection. It is also the one method a surrogate of another family reads - nothing in a projection is specific to BLRGlobalModel's posterior, since it carries geometry, not fit state.

__init__

__init__(domain: Domain) -> None

Bind the domain the geometry reads.

Parameters:
  • domain (Domain) –

    the box, per-dimension scale and draws the projection reads its geometry off - center, width and which sides are unbounded. Holding one domain rather than being one keeps the geometry and the fallback draw in the same coordinate unit with no second knob to keep in step. Validated by Domain's own constructor.

features abstractmethod

features(x: ndarray) -> jnp.ndarray

Return the (M, w) feature rows for (M, d) coordinates.

w is this projection's feature width: the model reads it off the returned shape, never off d, so a projection is free to widen or narrow the representation however its geometry needs.

ProjectionFactory module-attribute

ProjectionFactory = Callable[[Domain], 'Projection']

Build the Projection a model reads one domain through.

Geometry is a pure function of the domain - a center, a width, one lengthscale - so the model carries the recipe rather than one projection bound to one box: partial(SphereProjection, kappa=..., mask=...) for the bent arm, IdentityProjection itself for the straight one. Called once per ask with the box that ask was handed, so the geometry is always the caller's box and never a projection bound to an older one.

SphereProjection

Bases: Projection

Inverse-stereographic projection of a chosen subset of the dimensions.

The restart models read the domain in whatever coordinates the objective takes. This maps them onto the unit sphere, [2z; |z|^2 - 1] / (|z|^2 + 1) with |·| the Euclidean norm, where z holds only the projected dimensions' coordinates, centered, divided by the per-dimension scale and by one global lengthscale. Two properties matter downstream.

Every projected row has its bent part at norm one - the stereographic coordinates plus the closing bowl coordinate - so a linear head read on those features has a constant self inner product: its posterior variance stays bounded far from data instead of climbing back to the prior. That climb is the corner-seeking pathology the projection exists to cure - variance growing with distance reads as unexplored room, and an acquisition spends its asks on the box corners. The last coordinate, (|z|^2 - 1)/(|z|^2 + 1), is then a radially symmetric, saturating feature of the input - the one extra degree of freedom a linear head gets, an isotropic bowl whose center the weights place.

mask keeps that bowl off dimensions whose natural prior is uniform - an angle, say, wants no attraction to the center. A left-out dimension keeps its own centered, scaled coordinate and enters a linear head as a plain trend, so the feature vector is d + 1 wide however many dimensions the projection bends - and only its bent part is unit-norm.

A dimension may be unbounded: inverse stereography takes all of R, so the same map bends a line, and its far end returns to the pole - the variance goes back to the prior instead of growing with |x|, which is what an unbent coordinate does.

References
  • Doumont et al. (2026), AISTATS — the spherical-linear model this projection comes from.
  • Tripp (2026), github.com/AustinT/2026-07-high-dim-bo — the study that isolates what the bend contributes: a prior that the optimum is interior, strong enough that sliding the optimum to a corner reverses the ranking. Use this projection where that prior holds and IdentityProjection where it does not.

__init__

__init__(
    domain: Domain,
    *,
    kappa: float = 0.5,
    mask: ndarray | Sequence[bool] | None = None,
) -> None

Bind the domain and the projected subset.

Parameters:
  • domain (Domain) –

    the Domain the projection normalizes; its scale is each dimension's prior width in coordinate units. Only the ratios between the bent dimensions' entries move the features - the projection derives one global lengthscale from scale and kappa and divides it back out - but the common magnitude is what the fallback draw and the radius of a dimension outside bounded_dims are measured in.

  • kappa (float, default: 0.5 ) –

    the tie between the projection's radius and the domain - a bent dimension's far end lands at |z|^2 = 1/kappa whatever d is. Must lie in (0, 1); without such a tie a high-dimensional box pushes every corner past the pole and the posterior collapses there.

  • mask (ndarray | Sequence[bool] | None, default: None ) –

    which dimensions the projection bends, a (d,) boolean selector; None bends all of them.

Raises:
  • ValueError –

    If kappa is out of range, or mask is not a (d,) boolean selector selecting at least one dimension. The domain is validated by its own constructor.

features

features(x: ndarray) -> jnp.ndarray

Return the (M, d + 1) feature rows for (M, d) coordinates.

Every dimension is first read in its own coordinate unit, (x - center) / scale, so no column inherits a box width as its unit. The bent dimensions become their stereographic image on the unit sphere, divided by the global lengthscale; the rest keep that centered, scaled coordinate, so a linear head reads them as a plain linear trend.

IdentityProjection

Bases: Projection

The no-geometry projection: coordinates are their own features.

features returns the coordinates unchanged - width d, no center bowl, no normalization to the unit box. Where SphereProjection bends the corners toward the pole and seats the center at the south pole (a prior that the optimum lives near the middle), this one keeps every coordinate's own scale and range and puts the center nowhere special: a prior that the optimum may well sit on a boundary or a corner.

The cost of no geometry is no bound. The posterior variance is a quadratic form in these unbent features, so it grows toward the corners and expected improvement on this arm is extrapolation-dominated, pointing at corners - exactly the behavior wanted when the truth lives there, and the one SphereProjection exists to cure when it does not.

features ignores the domain's scale outright: the coordinates arrive as they are, and only the domain's draw reads it, to place the fallback starts.

features

features(x: ndarray) -> jnp.ndarray

Return the coordinates unchanged: the identity feature map.