build_adapt_step

jaxrens.sampling.adaptation.manager.build_adapt_step(move_descriptors, per_move_fns, batcher, adjust_n_samples, adjust_factor, adjust_max_rounds, adjust_interval, trial_batch_size=None)[source]

Build the per-iteration adapt step.

Returns None when adaptation is inactive — when per_move_fns or move_descriptors is empty, or adjust_interval <= 0. Callers detect inactivity via if adapt_step is None.

Otherwise returns adapt_step(ns_state, emax, rng_key) which:

  1. Extracts current step sizes from ns_state.population.

  2. Iterates over moves: per-move bisection on a fresh trial sample, with early exit per-replica once every replica has converged.

  3. Writes the new step sizes back into the population and returns the full (new_ns_state, diag, new_rng_key) tuple.

rng_key MUST already match batcher.shape_prefix: scalar for SingleRun, (R,) for VmapRuns(R), (G, P) for PmapVmapRuns(G, P), and (n_gpu,) (broadcast — same key on every shard, required for lax.psum bisection coherence) for ShardedSingleRun. Callers that carry a scalar key (e.g. burn-in) must promote it themselves before calling.

Parameters:
  • move_descriptors (Sequence[MoveKernel]) – One MoveKernel per move type.

  • per_move_fns (Sequence[Callable] | None) – One step function per move type. None / empty → inactive.

  • batcher (SingleRun | VmapRuns | PmapVmapRuns | ShardedSingleRun) – BatchDescriptor (SingleRun / VmapRuns / PmapVmapRuns / ShardedSingleRun).

  • adjust_n_samples (int) – Walkers per bisection trial round (static).

  • adjust_factor (float) – Multiplicative step-size factor (static).

  • adjust_max_rounds (int) – Max bisection rounds (static).

  • adjust_interval (int) – Iterations between fires. <= 0 → inactive.

  • trial_batch_size (int | None) – Optional chunk for the per-round trial vmap (jax.lax.map(batch_size=...)). Bounds peak memory at trial_batch_size * per-walker tape. None → full vmap.

Returns:

adapt_step closure (signature above), or None when inactive.

Return type:

Callable[[Any, Float[jaxlib._jax.Array, ’*B’], Key[jaxlib._jax.Array, ’*B’]], tuple[Any, dict, Key[jaxlib._jax.Array, ’*B’]]] | None

The diag dict it returns has keys rate/counts/n_rounds/converged/cap_hits/ floor_hits/bracket_detected/trial_n_evaluations/ trial_n_grad_evaluations. Stacked over moves along the axis right after the batch prefix: shape (n_moves, ...) for SingleRun, (n_runs, n_moves, ...) for VmapRuns, (G, P, n_moves, ...) for PmapVmapRuns.