This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Jupyter Book repository containing educational notebooks demonstrating nested sampling algorithms from the BlackJAX library. The book focuses on physics-motivated use cases and provides pedagogical examples of nested sampling implementations.
The repository uses the nested sampling fork of BlackJAX from: https://github.com/handley-lab/blackjax (tag: v0.1.0-beta). This tag is for continuity while the merge into the main blackjax repository is in progress.
# Install dependencies
pip install -r requirements.txt
# Build the book locally
jupyter-book build .
# or shorthand
jb build .
# The built HTML will be in _build/html/# Install the nested sampling fork of BlackJAX
pip install git+https://github.com/handley-lab/blackjax.git@v0.1.0-beta
# Install visualization dependencies (for examples)
pip install anesthetic-
Create a notebook in the appropriate directory:
basic/- Simple introductory examplesadvanced/- Complex implementations (GP, Random Walk NS)physics/- Physics-specific applications (supernovae, cosmology)scripts/- Python scripts for standalone examples
-
Add your notebook to
_toc.ymlunder the appropriate section -
Add yourself to
contributors.md -
Include citations in
references.biband use{cite}citation_key`` in markdown -
Test the build locally with
jb build .
-
Notebooks: Interactive examples demonstrating nested sampling usage
- Examples are pre-executed (notebooks run statically due to
execute_notebooks: 'off') - Visual state is preserved in notebooks for display in the book
- Examples are pre-executed (notebooks run statically due to
-
Scripts: Standalone Python implementations for specific physics problems
supernovae.py- SALT model fitting for supernovaeCMB.py,GW.py- Cosmological and gravitational wave examplesBF.py- Bayes factor computation
-
Configuration:
_config.yml- Jupyter Book configuration_toc.yml- Table of contents structure- GitHub Actions workflow in
.github/workflows/build_deploy.yamlfor automatic deployment
Standard workflow for nested sampling:
import blackjax
from blackjax.ns.utils import finalise
# Define likelihood and prior
loglikelihood_fn = lambda x: ...
logprior_fn = lambda x: ...
# Initialize algorithm
algo = blackjax.nss(
logprior_fn=logprior_fn,
loglikelihood_fn=loglikelihood_fn,
num_delete=50,
num_inner_steps=20,
)
# Run sampling loop
state = algo.init(initial_particles)
while not converged:
state, dead_point = algo.step(rng_key, state)
# collect dead points
# Finalize results
final_state = finalise(state, dead_points)Convert results to anesthetic format for plotting:
import anesthetic
nested_samples = anesthetic.NestedSamples(
data=final_state.particles,
logL=final_state.loglikelihood,
logL_birth=final_state.loglikelihood_birth,
)Core dependencies (from requirements.txt):
jupyter-book- For building the bookmatplotlib- For plottingnumpy- For numerical operations
Example notebooks may require additional packages:
blackjax(nested sampling fork)anesthetic- For nested sampling visualizationjax,jax.numpy- JAX framework- Physics-specific packages (e.g.,
jax_supernovaefor supernovae examples)
- The book is deployed automatically to GitHub Pages via GitHub Actions on push to main branch
- Notebooks are NOT re-executed during build (static display mode) to avoid dependency management issues
- Examples focus on JAX-based implementations for hardware acceleration
- Citations follow standard academic format using BibTeX references