Navigation: README · Architecture · Preprocessing · JAX Training · Checkpointing · Inference · Examples · Tutorials
The repository is designed to be a practical guide for those wanting to build simple JAX emulators from 21-cm cosmology simulations and other associated multi-wavelength probes for use within JAX-accelerated Bayesian inference frameworks, for example BlackJAX.
The model design follows the architecture ideas used by AstroEmu and GlobalEmu (arXiv:2104.04336): combine physical parameters with independent coordinates to allow the network to predict scalar observable values, then reconstruct spectra or grids after inference.
21cmspace-emulators/
README.md
docs/ (detailed guides to emulator training)
Tutorials/ (notebook walkthroughs using the reusable package)
jax_emu/ (reusable JAX emulator infrastructure)
analysis/ (training-history and diagnostic plotting helpers)
architectures/ (shared MLP definitions)
data_preprocessing/ (specs, parameter prep, transforms, scaling, tiling)
inference/ (priors, likelihoods, nested sampling)
training/ (training and evaluation loops)
utils/ (configs, checkpoints, metrics)
examples_21cmspace/ (21cmSPACE-specific training and inference workflows)
data/ (small example observation tables and data products)
t21/ (global 21-cm signal emulator)
delta21/ (21-cm power-spectrum emulator)
twentyonecmspace.py (shared 21cmSPACE constants/helpers)
The repository is designed to support a wide range of reionisation probes, so emulators can be used in multi-wavelength joint analyses such as arXiv:2503.21687, arXiv:2312.08095, and arXiv:2508.13761. Emulator targets in this style include:
- 21-cm global brightness temperature,
T21(z) - 21-cm power spectra,
Delta21(z, k) - UV luminosity functions,
UVLF - cosmic X-ray and radio backgrounds (
CXB/CRB) - star-formation-rate density,
SFRD(z) - ionisation and thermal histories, including
xHI(z),TK(z),TS(z), andTrad(z)
The model is a simple JAX/Flax implementation of the GlobalEmu/AstroEmu idea:
a neural network maps cosmological and astrophysical parameters plus independent
coordinates, such as redshift z and/or wavenumber k, to scalar observable
values. Vectorized inference over the coordinate axes then reconstructs the
requested spectrum, surface, or grid.
Start here, then move into the stage-specific docs:
- Architecture: tiled scalar-output networks and DenseMLP configuration.
- Preprocessing: parameter preparation, target transforms, scaling, and tiling.
- JAX training: model initialization, batching, optimization, and validation.
- Checkpointing: saving model weights, losses, and preprocessing metadata.
- Inference: priors, likelihoods, upper limits, and nested sampling.
- Examples: worked global 21-cm and power-spectrum workflows.
- Tutorials: notebook walkthroughs starting from plain NumPy arrays.
We recommend using uv for the fastest setup, but standard pip is also
supported.
The network architectures use JAX, which requires a backend matched to your hardware (CPU or NVIDIA GPU).
Identify which machine:
cpu: laptops or CPU clusters.cuda12/cuda13: GPU systems with NVIDIA Accelerators.
uv will manage the virtual environment and lock dependencies.
For CPU development:
uv sync --extra cpu --extra dev
source .venv/bin/activateFor GPU systems, choose the command that matches your driver stack:
# CUDA 12 (older systems)
uv sync --extra cuda12 --extra dev
# CUDA 13 (latest)
uv sync --extra cuda13 --extra dev
source .venv/bin/activateIf you prefer not to use uv, install the package manually into your own
virtual environment.
# 1. Create and enter the environment
python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip
# 2. Install based on your hardware
# Replace [cpu] with [cuda12] or [cuda13] if using a GPU
python -m pip install -e ".[cpu,dev]"Navigation: README · Architecture · Preprocessing · JAX Training · Checkpointing · Inference · Examples · Tutorials