init_ns_sharded

jaxrens.sampling.nested_sampling.init_ns_sharded(init_fn, positions, types, energies, cells, rng_key, *, n_gpu, step_sizes=None, ensemble_params=None, restart_state=None, max_neighbors=0, max_neighbor_counts=None)[source]

Build an NSState for one population sharded across n_gpu GPUs.

Accepts inputs in either layout:

  • Flat (K, ...) — the typical “single-run” shape; the helper reshapes to (G, K // G, ...) and shards.

  • Pre-sharded (G, K // G, ...) — left as-is, just shard.

Builds a single-replica NSState via init_ns(), then reshapes every population-axis leaf to (G, K // G, ...) and broadcasts every scalar / static leaf to (G,) so that ShardedSingleRun.wrap_step can shard_map the resulting state across G devices.

ns_state.n_walkers is set to the global walker count K (not K // G). ns_step_sharded uses this value for the global log_weight denominator and the global random-survivor sampling.

Parameters:
  • n_gpu (int) – Number of devices to shard across. Must be <= len(jax.local_devices()) and must divide K evenly.

  • positions (Array) – Same as init_ns().

  • types (Array) – Same as init_ns().

  • energies (Array) – Same as init_ns().

  • cells (Array | None) – Same as init_ns().

  • rng_key (Array) – Same as init_ns().

  • ... – Same as init_ns().

  • init_fn (Callable)

  • step_sizes (Array | None)

  • ensemble_params (dict | None)

  • max_neighbors (int)

  • max_neighbor_counts (Array | None)

Returns:

NSState with population leaves of shape (G, K // G, ...), scalar leaves of shape (G,), and n_walkers == K.

Raises:

ValueError – If n_gpu > len(jax.local_devices()) or K % n_gpu != 0.

Return type:

NSState