ns_step_sharded

jaxrens.sampling.nested_sampling.ns_step_sharded(ns_state, step_fn, n_mcmc_steps=20, n_extra=0, n_cull=1, move_key=None)[source]

One NS iteration with the population sharded across n_gpu GPUs.

Shape contract: every leaf of ns_state.population has shape (K_per_gpu, ...) on the local device; the global population is (K_total = G * K_per_gpu, ...) reconstructable via lax.all_gather. ns_state.n_walkers carries the global walker count.

Must be called inside a jax.shard_map over the "shard" mesh axis (see ShardedSingleRun.wrap_step()). Uses lax.all_gather to materialise the full population on every device for the worst-walker selection and the chain seed broadcast; then writes new walkers via a global scatter that is sliced back to the local shard before return.

Body mirrors ns_step() with five substitutions:

  1. Worst-walker selection runs on the globally gathered potentials (same RNG → same global index on every shard).

  2. Random-survivor cloning indexes globally — the chain seed is identical on every shard.

  3. The MCMC chains are DISTRIBUTED across shards: each device walks only its ceil(n_walk / G) slice of the (clone + n_extra) chains, then the small final walker states + per-move counters are lax.all_gather-ed back. This divides the model-eval work (the dominant per-step cost) G ways, so a sharded run is both a memory win (population storage is split) and a walk speedup of up to G× when n_walk >= G. Chain i always consumes chain_keys[i] regardless of which shard runs it, so the walk is bit-identical to the single-device result.

  4. Writing the new walkers happens via a global .at[].set(...) on the gathered population, then reshape-and-slice back to the local shard.

  5. Per-move counters are produced identically on every shard, so no lax.psum is needed for correctness — they’re already coherent. The returned info dict has the same shapes as ns_step() (per-shard view).

Returns:

new_ns_state.population has the same per-shard (K_per_gpu, ...) layout; info keys match ns_step().

Return type:

(new_ns_state, info_dict)

Parameters: