InterREManager¶
- class jaxrens.sampling.inter_re_manager.InterREManager(swap_kernel, batcher, backend, re_interval=1, n_swap_cycles=1)[source]¶
Bases:
objectManages inter-replica-exchange swap passes in the NS outer loop.
Constructed once before the loop starts.
_run_loopcallsfires(i)to decide whether to fire on iterationi, then callsapply(ns_state, rng_key)to run the swap pass.- Parameters:
swap_kernel (SwapKernel) –
SwapKernelinstance, typically frommake_swap_kernel().batcher (BatchDescriptor) –
BatchDescriptorcontrolling the execution mode.backend (Any) – Energy backend, passed to kernels that re-evaluate energies (
XRENSSwap).re_interval (int) – Fire a swap pass every this many NS iterations. 0 → never fire.
n_swap_cycles (int) – Number of even+odd swap phases per fire.
- fires(iteration)[source]¶
Return True iff a swap pass should fire on this iteration.
Rules: re_interval > 0 AND iteration > 0 AND iteration % re_interval == 0. Iteration 0 is skipped to match the adapt-step firing convention.
- property is_active: bool¶
True iff this manager will actually do work.
SingleRundescriptors return False (no batched population to swap).VmapRuns/PmapVmapRunsreturn True whenre_interval > 0.
- apply(ns_state, rng_key)[source]¶
Run one inter-RE swap pass.
For
SingleRun: returns state unchanged with zero stats. ForVmapRuns: operates on(n_runs, K, ...)population directly. ForPmapVmapRuns: all_gathers across the pmap axis, swaps, re-shards.The swap-acceptance constraint is read off
ns_state.emax— the per-replica NS contour the most recentns_stepculled at. This is algorithm state set byns_step, not a value re-derived frompop.energy: recomputing here would be strictly tighter post-MCMC and would reject otherwise-legal swaps.- Parameters:
ns_state (NSState) – Current
NSState(single, vmapped, or pmap-vmapped).rng_key (Key[jaxlib._jax.Array, '']) – Scalar PRNG key for swap randomness.
- Returns:
new_ns_state: UpdatedNSStateafter swaps.swap_stats: Dict with keys{"n_swap_pairs_attempted": int, "n_swap_pairs_accepted": int, "acceptance_rate": float, "n_energy_evals": int, "n_grad_evals": int}. All zeros forSingleRun(no-op).new_rng_key: Advanced PRNG key carry (scalar).
- Return type:
Tuple
(new_ns_state, swap_stats, new_rng_key)where