CosmoPower-JAX: Differentiable Cosmology Emulator
- CosmoPower-JAX is a fully differentiable, GPU-accelerated emulator framework for cosmological power spectra that employs PCA-based compression and neural emulation for fast parameter inference.
- It integrates principal component analysis with a multi-layer perceptron, trained on extensive simulations, achieving sub-percent accuracy compared to traditional Boltzmann solvers.
- The framework leverages JAX’s jit compilation, vectorized batch processing, and automatic differentiation to support ultra-fast, high-dimensional gradient-based sampling.
CosmoPower-JAX is a fully differentiable, GPU-accelerated emulator framework for cosmological power spectra, implemented in JAX and designed to facilitate ultra-fast gradient-based parameter inference for current and next-generation cosmological surveys. It extends the CosmoPower methodology to a pure JAX environment, combining principal-component compression and neural emulation with just-in-time compilation, vectorized batch prediction, and automatic differentiation to yield rapid and scalable predictions of (CMB angular power spectra) and (3D matter power spectra). This enables precise, high-dimensional Bayesian inference with efficiency and scalability suitable for analyses involving up to hundreds of free parameters while achieving sub-percent accuracy with respect to traditional Boltzmann solvers such as CLASS or CAMB (Piras et al., 2023, Bolliet et al., 10 Jul 2025).
1. Theoretical Framework and Neural Emulation
CosmoPower-JAX is built upon a two-stage emulation strategy. The first stage compresses output from Boltzmann solvers (CLASS) into a reduced set of basis weights using principal-component analysis (PCA) or singular-value decomposition (SVD). The training data comprise calculated spectra across a grid of cosmologies , producing matrices for and . Decomposition yields basis sets and and corresponding mode amplitudes , such that: In the second stage, a multi-layer perceptron (MLP) or Gaussian process (GP) regresses these mode weights as smooth functions of cosmological parameters. For new parameter vectors 0, the emulator predicts new weights and reconstructs the spectra: 1 or directly 2, where 3 is the smooth interpolation and 4 a residual noise GP (Bolliet et al., 10 Jul 2025).
The neural network architecture in CosmoPower-JAX consists of four fully connected layers of 512 units each, employing a “swish-like” activation function. The network is trained with mean squared error loss over large datasets: 5 matter-power spectra and 6 CMB spectra. Overfitting is mitigated by early stopping on a validation set, and the Adam optimizer is used with decaying learning rates (Piras et al., 2023).
2. Training Data Construction and Compression
Training cosmologies 7 are sampled via Latin-Hypercube or Sobol sequences covering the target region of parameter space, typically for Stage IV survey forecasts. Parameters include 8. For each sampled 9, the full CLASS Boltzmann solver provides high-accuracy spectra (e.g., 0 up to 1, 2 on a 2D 3 grid). The resultant output matrices are subjected to PCA/SVD, with 10–20 dominant modes retained—accounting for 4 of the variance—which compresses the emulation to interpolation of a small number (5) of amplitude functions. This compression increases smoothness in parameter dependency and dramatically reduces the computational complexity of the regression problem (Bolliet et al., 10 Jul 2025).
3. JAX Implementation and Computational Techniques
CosmoPower-JAX leverages JAX features to achieve high throughput and differentiability:
- jit compilation: The main emulation and likelihood routines are decorated with
@jax.jit, compiling Python code into efficient XLA kernels. - vmap and batch evaluation:
jax.vmapenables batch processing of parameter sets, enabling predictions across tens to hundreds of cosmologies in a single kernel call, without explicit loops. - automatic differentiation: The entire emulator is written as a pure JAX function, allowing gradients with respect to any 6 via
jax.gradorjax.jacobian, which is critical for Hamiltonian Monte Carlo (HMC) and Fisher forecasting. - multi-GPU scaling: Combining JAX's
pmapand NumPyro's chain vectorization, CosmoPower-JAX distributes MCMC chains across multiple GPUs achieving near-perfect scaling (Piras et al., 2023).
The constant pre-computed basis vectors 7 and 8 ensure that the runtime cost per parameter point is dominated by small dense-matrix multiplications and lightweight MLP passes, yielding exceptional evaluation speeds.
4. Performance Benchmarks and Accuracy
CosmoPower-JAX delivers significant speed-outs versus traditional Boltzmann solvers:
- P(k): On a laptop CPU, 9 at 50 0-points and 10 redshifts evaluates in 10.4 ms (jitted), compared to 21 ms for Fortran/GPU CosmoPower and 31000 ms for CLASS halofit (Bolliet et al., 10 Jul 2025).
- 4: 5 evaluations (6) require 70.8 ms with CosmoPower-JAX, 80.03 s for CLASS_SZ fast mode, and 9 s for full CLASS.
- Batch throughput: For 64 cosmologies in parallel, per-point evaluation is 0100 1s/cosmology for 2 and 200 3s/cosmology for 4.
- Total speedup: 5 over CLASS for 6; 7 for 8.
Accuracy metrics include:
- Maximum emulation error: 9 for 0 in 1 h/Mpc, 2; 3 for 4 in 5 (TT/TE/EE/lensing).
- Derivative fidelity: JAX autodiff gradients agree with classic finite-difference derivatives at sub-percent differences (Piras et al., 2023, Bolliet et al., 10 Jul 2025).
- Posterior reliability: KL divergence between emulator-generated and CAMB-based posterior marginals 6; Fisher ellipses agree at 7.
5. Inference, Gradient-Based Sampling, and Scalability
Gradient-based samplers are natively supported, leveraging the differentiable emulator:
- Hamiltonian Monte Carlo (HMC) and No-U-Turn Sampler (NUTS) pipelines execute on CPU or GPU, with HMC trajectory parameters and parameter reparametrization optimized for efficiency and geometry.
- Example scalability: Stage IV cosmic shear (37 parameters) with NUTS + CosmoPower-JAX on three A100 GPUs completes in 81 day (compared to 94 months for PolyChord + CAMB + CCL on CPU); a triple survey 302pt (157 parameters) analysis runs in 13 days (vs. 26 years for CAMB-based pipeline) (Piras et al., 2023).
- Vectorized MCMC: Chain parallelism across multiple GPUs via
pmapenables O(100–1000) effective chains, improving convergence and statistical power. - Integrability: Any JAX-based likelihood or observable (e.g., jax-cosmo) can be employed within the framework, enabling fast forward modeling and uncertainty quantification for non-Gaussian or field-level likelihoods.
6. Limitations and Domain of Validity
- Training domain boundaries: The emulator is strictly valid within the convex hull of training parameters; extrapolation leads to uncontrolled error growth. Retraining is needed for new physical extensions (e.g., massive neutrino, 3CDM, varied 4) and for cross-model combinations.
- Resolution limits: Small-scale or rapid-oscillation spectral features (from e.g. reionization or neutrino-induced phase shifts) may be inadequately captured in a low-mode PCA truncation, necessitating careful mode-count selection for explorations beyond 5 regions (Bolliet et al., 10 Jul 2025).
- High-resolution regime: Ultra-high 6 (7) or 8 (9/Mpc) are beyond validated emulator range and require fallback to full Boltzmann evaluation or specialized fitting functions.
- Sampling limitations: Efficacy of NUTS/HMC may degrade for multi-modal or highly anisotropic posteriors; emulators are at risk of introducing bias if the target likelihood explores extreme parameter ranges (Piras et al., 2023).
- Posterior exploration: Extreme extrapolation may bias results, and appropriate coverage diagnostics should be employed.
7. Practical Implications and Future Prospects
CosmoPower-JAX enables high-dimensional, fast, and accurate likelihood evaluation for next-generation cosmological analyses. By making all spectral calculations differentiable, it unlocks the possibility of field-level or non-Gaussian inference via automatic differentiation, robust Fisher forecasting, and order-of-magnitude improvements in sampling efficiency. The public availability and swift retrainability of the emulator make it straightforward to incorporate additional cosmology, baryonic, or nuisance parameters. Linear GPU scaling is achievable, with demonstrated analyses reaching 0–1 parameter posteriors in hours to days on moderate hardware (Piras et al., 2023, Bolliet et al., 10 Jul 2025).
Planned extensions include wider adoption within jax-cosmo, expansion to cross-spectra emulation, generalized gradient samplers (e.g., Microcanonical or tempered HMC), JAX/Pyro-based variational inference, and emulation of higher-order statistics (including bispectra). The extension to hardware accelerators such as TPUs is under consideration to further expand computational accessibility and throughput.
Overall, CosmoPower-JAX establishes a computational paradigm for cosmological parameter inference—fully differentiable, massively parallel, and demonstrably capable of supporting the accuracy and complexity requirements posed by forthcoming Stage IV and next-generation survey projects.