Capse.jl is a Julia package for ultra-fast emulation of Cosmic Microwave Background (CMB) Angular Power Spectra. Capse.jl delivers cosmological computations 1,000,000× faster than traditional Boltzmann codes while maintaining research-grade accuracy.
- ⚡ Lightning Fast: ~45 microseconds per evaluation (vs ~ seconds for CAMB/CLASS)
- 🔧 Flexible Backends: CPU-optimized (
SimpleChains.jl) and GPU-ready (Lux.jl) - ♻️ Auto-Differentiable: Full gradient support for modern inference pipelines
- 🐍 Python Compatible: Seamless integration via
jaxcapse
using Pkg
Pkg.add(url="https://github.com/CosmologicalEmulators/Capse.jl")using Capse
# Load pre-trained emulator (weights available on Zenodo)
Cℓ_emu = Capse.load_emulator("path/to/weights/")
# Set cosmological parameters
# [ωb, ωc, h, ns, τ, As] - check ordering with get_emulator_description()
params = [0.02237, 0.1200, 0.6736, 0.9649, 0.0544, 2.042e-9]
# Compute power spectrum in microseconds!
Cℓ = Capse.get_Cℓ(params, Cℓ_emu)
# Get the ℓ-grid
ℓ_values = Capse.get_ℓgrid(Cℓ_emu)| Method | Time per Evaluation | Speedup |
|---|---|---|
CAMB (high accuracy) |
~60 seconds | 1× |
Capse.jl |
~45 μs | ~1,300,000× |
Benchmarks on Intel Core i7-13700H (single core)
# Process 100 cosmologies simultaneously
params_batch = rand(6, 100)
Cℓ_batch = Capse.get_Cℓ(params_batch, Cℓ_emu)using CUDA, Adapt
# Load and move to GPU
Cℓ_emu = Capse.load_emulator("weights/", emu=Capse.LuxEmulator)
Cℓ_emu_gpu = adapt(CuArray, Cℓ_emu)using Zygote
function loss(params)
Cℓ_theory = Capse.get_Cℓ(params, Cℓ_emu)
return sum((Cℓ_theory - Cℓ_observed).^2)
end
grad = gradient(loss, params)[1]Use Capse.jl seamlessly from Python:
import jaxcapse
# Load and use just like in Julia
emu = jaxcapse.load_emulator("path/to/weights/")
cl = jaxcapse.get_cl(params, emu)- Stable Documentation - Latest release
- Development Documentation - Current development branch
- API Reference - Detailed function documentation
If you use Capse.jl in your research, please cite our release paper:
@article{Bonici2024Capse,
author = {Bonici, Marco and Bianchini, Federico and Ruiz-Zapatero, Jaime},
journal = {The Open Journal of Astrophysics},
doi = {10.21105/astro.2307.14339},
year = {2024},
month = {jan 30},
publisher = {Maynooth Academic Publishing},
title = {Capse.jl: efficient and auto-differentiable {CMB} power spectra emulation},
volume = {7},
}We welcome contributions! Please follow the BlueStyle coding standards and see ColPrac for collaboration guidelines.
using Pkg
Pkg.develop(url="https://github.com/CosmologicalEmulators/Capse.jl")
Pkg.test("Capse")- Marco Bonici - Waterloo Center for Astrophysics
- Federico Bianchini - Kavli Institute for Particle Physics and Cosmology
- Jaime Ruiz-Zapatero - Advanced Research Computing Centre, UCL
- Marius Millea - UC Davis & Berkeley Center for Cosmological Physics
MIT License - see LICENSE for details.
Made with ❤️ by the Cosmological Emulators Team
