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
NSStatefor one population sharded acrossn_gpuGPUs.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
NSStateviainit_ns(), then reshapes every population-axis leaf to(G, K // G, ...)and broadcasts every scalar / static leaf to(G,)so thatShardedSingleRun.wrap_stepcanshard_mapthe resulting state across G devices.ns_state.n_walkersis set to the global walker countK(notK // G).ns_step_shardeduses this value for the globallog_weightdenominator and the global random-survivor sampling.- Parameters:
n_gpu (int) – Number of devices to shard across. Must be
<= len(jax.local_devices())and must divideKevenly.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:
NSStatewith population leaves of shape(G, K // G, ...), scalar leaves of shape(G,), andn_walkers == K.- Raises:
ValueError – If
n_gpu > len(jax.local_devices())orK % n_gpu != 0.- Return type: