adjust_step_size¶
- jaxrens.sampling.adaptation.stepsize_handler.adjust_step_size(population, move_fn, step_size, emax, rng_key, n_samples, min_rate, max_rate, adjust_factor, max_step_size, max_rounds, *, trial_batch_size=None, axis_name=None)[source]¶
Adjust step size for one move type until acceptance rate is in window.
Pure JAX function. JIT-compilable. Vmappable over runs.
Iterates a bisection-like loop: sample walkers → run trial moves → measure acceptance rate → scale step size up/down. Stops when the rate falls within
[min_rate, max_rate]or brackets are detected. Under vmap-over-runs,lax.while_loopruns until all replicas converge ormax_roundsis hit; per-replica convergence is masked by the loop’s any-active semantics combined with the per-replicaconvergedcarry.- Parameters:
population (Any) – Batched MCState, shape (n_walkers, …) on every field.
move_fn (Callable) – Single-move step function (static under JIT). Signature: move_fn(state, key, constraint) -> (state, MoveInfo).
step_size (Float[jaxlib._jax.Array, '']) – Current step size (scalar under each replica).
emax (Float[jaxlib._jax.Array, '']) – Likelihood constraint — max energy in population (scalar).
rng_key (Key[jaxlib._jax.Array, '']) – PRNG key.
n_samples (int) – Walkers to sample per trial round (static).
min_rate (float) – Target acceptance window (static).
max_rate (float) – Target acceptance window (static).
adjust_factor (float) – Multiplicative step-size factor (static).
max_step_size (float) – Upper bound on step size (static).
max_rounds (int) – Maximum bisection rounds (static).
trial_batch_size (int | None) – Optional chunk size for the trial vmap (kwarg-only, static).
None(default) →jax.vmap(trial_one)over alln_sampleswalkers. When set to an int, the trial vmap is replaced byjax.lax.map(..., batch_size=trial_batch_size)so peak memory scales with the chunk rather thann_samples— needed when the move’s backward tape exceeds device memory. Ifn_samplesis not a multiple oftrial_batch_sizethe trial population is padded with copies of the last sample and the pad is sliced off before rate/count aggregation.axis_name (str | None) – Mesh axis name to run under, when this function is called inside a
jax.shard_map(PmapVmapRuns’s"gpu"-axis wrap; seejaxrens.sampling.mesh).None(default) for SingleRun/VmapRuns, which never run inside a mapped context. When set, everywhile_loopcarry entry downstream ofrate/reasons/the per-round eval counts (rate_prev,converged,counts,cap_hits,floor_hits,saw_too_high,saw_too_low, cumulative eval counters) is pre-cast to thevaryingVMA type viajax.lax.pcastbefore the loop, so its input/ output carry types match undershard_map’s stricter checking — nothing in this function ever collective-reduces those, unlikeadjust_step_size_sharded(). Cast broadly rather than cherry-picked: an earlier, narrower version (only the entries one toy harmonic+random_walk test happened to surface as mismatched) passed that test but still failed on a real LJ/NPT pipeline run, wherecounts(not in the narrower list) also turned out to need it.jax.lax.pcasterrors outside a mapped context, which is why this can’t be applied unconditionally.
- Returns:
(new_step_size, final_rate, final_counts, n_rounds, converged, cap_hits, floor_hits, bracket_detected, trial_n_evaluations, trial_n_grad_evaluations).- Return type:
tuple[Float[jaxlib._jax.Array, ’’], Float[jaxlib._jax.Array, ’’], Int[jaxlib._jax.Array, ’4’], Int[jaxlib._jax.Array, ’’], Bool[jaxlib._jax.Array, ’’], Int[jaxlib._jax.Array, ’’], Int[jaxlib._jax.Array, ’’], Bool[jaxlib._jax.Array, ’’], Int[jaxlib._jax.Array, ’’], Int[jaxlib._jax.Array, ’’]]