jaxrens.io.checkpoint

Checkpoint save/load for NS run resumption.

HDF5-based checkpointing of full NS state.

Shape conventions

save_checkpoint and load_checkpoint are shape-agnostic. The state dict produced by run_ns (single run) has scalar log_evidence, n_dead, iteration. The dict produced by run_ns_parallel has 1-D (n_runs,) shapes for those fields. The dict produced by run_ns_multi_gpu has 2-D (G, P) shapes.

All these shapes round-trip correctly:

  • Save: arrays are stored as HDF5 datasets (any shape); scalars are stored as HDF5 attrs. A field is treated as a scalar only when np.asarray(value).ndim == 0. float(...) / int(...) casts are avoided for fields that may be batched.

  • Load: datasets are read back with their stored shape. iteration, n_dead, and n_walkers are returned as plain Python ints (they are always stored as scalars — only log_evidence can be batched).

  • Dead-point padding (load_checkpoint): works for 1-D dead arrays (n_dead is a scalar). For multi-run checkpoints, the caller is expected to save only the live-walker NSState; use save_ns_state / load_ns_state (future) for batched restarts, or save per-run slices.

Batch-shape inference

After loading, the caller can inspect state["log_evidence"].shape to determine the batch shape: * () → SingleRun * (n_runs,) → VmapRuns * (G, P) → PmapVmapRuns

Functions

auto_detect_restart

Find the newest valid checkpoint in a directory.

load_checkpoint

Load NS state from HDF5 checkpoint.

save_checkpoint

Save NS state to HDF5 checkpoint.