VmapRuns

class jaxrens.sampling.batch_descriptor.VmapRuns(n_runs, shape_prefix=())[source]

Bases: _UniformBatcher

Descriptor for n_runs independent NS runs batched via jax.vmap.

Used by run_ns_parallel.

Variables:
  • n_runs (int) – Number of independent NS runs.

  • shape_prefix (tuple[int, ]) – (n_runs,) — leading dimension of all batched arrays.

Parameters:
property is_batched: bool

Always True — multiple NS runs are stacked along axis 0.

wrap_step(ns_step_fn, step_fn, n_mcmc_steps, n_extra)[source]

Return a JIT-compiled vmapped NS step.

The closure captures step_fn, n_mcmc_steps, and n_extra as Python-level static values so vmap sees no dynamic static args. A single move_key (from replica 0’s key, outside the vmap) is passed to every run so the MWG move index stays unbatched — see _wrap_batched_step().

The returned function has signature:

jit_step(ns_states)  ->  (ns_states, infos)

which matches the current run_ns_parallel inner step pattern.

Parameters:
  • n_mcmc_steps (int)

  • n_extra (int)

split_keys(rng_key, n_sub_keys)[source]

Vmap jax.random.split over the (n_runs,) key array.

Parameters:
  • rng_key (jax.Array) – Shape (n_runs,) — one key per run.

  • n_sub_keys (int) – Number of sub-keys to produce per run.

Returns:

Shape (n_runs, n_sub_keys) with typed-key dtype.

Return type:

jax.Array

reduce_for_termination(log_evidence, hmax)[source]

Worst-of reduction across all runs.

Matches the current run_ns_parallel termination logic:

worst_evidence = float(jnp.min(ns_states.log_evidence))
worst_hmax     = float(jnp.max(infos["hmax"]))
Return type:

(float(jnp.min(log_evidence)), float(jnp.max(hmax)))

Parameters: