Skip to content

jaxace

JAX/Flax implementation of cosmological emulators with automatic JIT compilation.

For the analytic neutrino model, its hybrid, temperature and radiation prescriptions and the jaxace-only comparison against CLASS, see Neutrino thermal prescriptions.

Key Features

  • ⚡ Automatic JIT compilation for optimal performance
  • 🔢 Full JAX integration with grad, vmap, and jit
  • 🌌 Cosmological functions for growth, distances, and Hubble parameter
  • 🧠 Neural network emulators with automatic batch detection

Installation

pip install -e .
poetry install

Quick Start

import jaxace
import jax.numpy as jnp
import numpy as np

# Define cosmology
cosmo = jaxace.w0waCDMCosmology(
    ln10As=3.044, ns=0.9649, h=0.6736,
    omega_b=0.02237, omega_c=0.1200,
    m_nu=(0.02, 0.02, 0.02), w0=-1.0, wa=0.0
)

# Compute background quantities
z = jnp.array([0.0, 0.5, 1.0])
growth = cosmo.D_z(z)
distance = cosmo.r_z(z)

# Neural network emulator
nn_dict = {...}  # Your network specification
weights = np.load('weights.npy')
emulator = jaxace.init_emulator(nn_dict, weights, jaxace.FlaxEmulator)

# Run with automatic JIT
output = emulator(input_data)

Included Trained Generic Emulators

The registry contains 16 scalar emulators. See the migration guide before replacing either retired model. Keys have the form <cosmology>_<neutrinos>[_freeYHe]_<amplitude>: mnuw0waCDM or mnuOkLCDM, onemassiveneutrino or threedegenerateneutrinos, and ln10As or sigma8 (total matter at redshift zero). Omit _freeYHe for CLASS-default helium. The thermal prescription is in the emulator description, not its key. These models predict 11 outputs, not the retired pair's seven; consult schema.json for the ordered features and labels. Internal validation is not an independent accuracy test; some fits predict nonpositive distances.

import numpy as np
import jaxace
models = jaxace.trained_emulators
names = sorted(models.keys())  # loaded models
emu = models["mnuw0waCDM_onemassiveneutrino_sigma8"]
# z, sigma8_m_0, ns, H0, omega_b, omega_c, w0, wa, Neff
output = emu.run_emulator(np.array([0.5, 0.8, 0.96, 67.0, 0.022, 0.12, -1.0, 0.0, 3.044]))

Set JAXACE_NO_AUTO_DOWNLOAD=1 before import to skip automatic loading. jaxace.list_emulators() still lists all available models; jaxace.get_emulator(name) loads one on demand and caches it in the same dictionary.

Postprocessing API

Since version 0.6.0, custom GenericEmulator postprocessing follows the same signature as AbstractCosmologicalEmulators.jl:

def postprocessing(input_params, output, emulator):
    return output

load_trained_emulator expects postprocessing.py to define a function with that signature. Older four-argument postprocessing functions with auxiliary_params are still accepted for compatibility, but the three-argument form is the supported API.

Performance

With automatic JIT compilation, jaxace achieves:

  • Single evaluation: ~7 μs
  • Batch processing: >20M samples/sec
  • Automatic optimization: No manual tuning required