Skip to content

CosmologicalEmulators/Capse.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Capse.jl

Capse

Documentation Documentation Build Status codecov arXiv

Code Style: Blue ColPrac Size

🚀 High-Performance CMB Power Spectrum Emulation

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.

✨ Key Features

  • ⚡ 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

📦 Installation

using Pkg
Pkg.add(url="https://github.com/CosmologicalEmulators/Capse.jl")

🎮 Quick Start

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)

📊 Performance Benchmarks

Method Time per Evaluation Speedup
CAMB (high accuracy) ~60 seconds
Capse.jl ~45 μs ~1,300,000×

Benchmarks on Intel Core i7-13700H (single core)

🔥 Advanced Features

Batch Processing

# Process 100 cosmologies simultaneously
params_batch = rand(6, 100)
Cℓ_batch = Capse.get_Cℓ(params_batch, Cℓ_emu)

GPU Acceleration

using CUDA, Adapt

# Load and move to GPU
Cℓ_emu = Capse.load_emulator("weights/", emu=Capse.LuxEmulator)
Cℓ_emu_gpu = adapt(CuArray, Cℓ_emu)

Gradient-Based Optimization

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]

🐍 Python Integration

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)

📚 Documentation

🎓 Citation

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},
}

🤝 Contributing

We welcome contributions! Please follow the BlueStyle coding standards and see ColPrac for collaboration guidelines.

Development Setup

using Pkg
Pkg.develop(url="https://github.com/CosmologicalEmulators/Capse.jl")
Pkg.test("Capse")

👥 Authors

  • 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

📄 License

MIT License - see LICENSE for details.


Made with ❤️ by the Cosmological Emulators Team

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages