BucketManager¶
- class jaxrens.sampling.bucket_manager.BucketManager(ladder, offset, shrink_dwell=0)[source]¶
Bases:
objectOuter-loop helper that owns
low_countand the picker calls.A single instance is used by
_run_loop(one per NS run) and byinitial_walk(one per burn-in invocation). The class is not JIT-traced — it is pure-Python control-flow glue that decides whether to grow / shrink / keep themax_neighborsstatic field on the population pytree.low_countis the only mutable state: the count of consecutive successful iterations satisfying the hysteresis gap condition. It is reset to zero on (a) a gap violation, (b) any successful shrink, and (c) any overflow growth.- grow_if_overflow(ns_state, new_ns_state, *, label, iteration)[source]¶
Detect and handle a neighbor-bucket overflow.
- Parameters:
ns_state (Any) – Pre-step state (the rollback target if overflow fired).
new_ns_state (Any) – Post-step state, which may carry
population.overflow=Truefrom the JIT kernel.label (str) – Short tag used in the warning log, e.g.
"iter"or"burn-in walk". Helps disambiguate the two call sites.iteration (int) – Counter value (NS iteration or burn-in walk index).
- Returns:
(state_to_use_next, retry_needed). Whenretry_neededis True, the caller must NOT advance its outer counter and should re-run the JIT kernel againststate_to_use_next(which has a larger bucket). When False,state_to_use_nextis justnew_ns_stateunchanged.- Return type:
- maybe_shrink(ns_state, *, iteration)[source]¶
Step the bucket down one entry when the dwell window is satisfied.
Reads
ns_state.population.max_neighbor_count(the per-walker peak observed during the last successful step) and compares the next- smaller ladder entry againstobserved + offset. Incrementslow_counton a qualifying iteration, resets to zero on a violation, and shrinks when the counter reachesshrink_dwell.shrink_dwell == 0(default) bypasses the entire check so the method becomes a cheap no-op for users who never opted in.Returns the (possibly updated) state. The caller assigns the result back to its working
ns_state.