Skip to content

CosmologicalEmulators/Capse.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

144 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

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 1ร—
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

 
 
 

Contributors

Languages