Skip to main content

Fast, differentiable cosmology in pure JAX. CMB Cls, matter Pk (linear and nonlinear), distances, derived parameters, and halo-model tSZ Cl^yy via high-accuracy ede-v2 CosmoPower emulators.

Project description

classy_szlite

tests codecov PyPI version Python versions Documentation Status License: MIT

Fast, differentiable cosmology in pure JAX.

classy_szlite provides JIT-compiled, jax.grad-friendly access to:

  • CMB angular power spectra — TT, TE, EE
  • Linear and nonlinear matter Pk — P(k, z), Pnl(k, z)
  • Distances — H(z), comoving χ(z), angular-diameter D_A(z)
  • Derived parameters — σ8, Ω_m, S8
  • Halo-model tSZ Cl^yy — Arnaud 2010 GNFW pressure profile

Backed by the high-accuracy ede-v2 CosmoPower emulators. LCDM-equivalent cosmology is the default — fEDE = 0.001 (the package's default) reproduces standard ΛCDM to emulator precision, and the same emulator covers the full early-dark-energy parameter space if you want to explore it.

Runtime dependencies: jax, numpy, mcfit.

Install

pip install classy_szlite

Or from source:

git clone https://github.com/CLASS-SZ/classy_szlite
cd classy_szlite
pip install -e .

You also need the CosmoPower emulator .npz files at ~/class_sz_data/ (or the path in $CLASSY_SZLITE_DATA_DIR). See Installation.

Quick start

import jax.numpy as jnp
import classy_szlite as csl

cosmo = csl.CosmoParams()                      # Planck-18 + ede-v2 LCDM-equivalent defaults

# Derived parameters
csl.derived(cosmo)
# → {'sigma_8': 0.812, 'Omega_m': 0.311, 'S8': 0.827, 'der_full': ...}

# CMB Cls (dimensionless D_ℓ; × Tcmb² for μK²)
csl.cl_TTTEEE(cosmo)
# → {'ell', 'tt', 'te', 'ee'}

# Matter Pk at multiple z
k, pk  = csl.Pk(cosmo,  [0., 0.5, 1., 2.])
k, pnl = csl.Pnl(cosmo, [0., 0.5, 1., 2.])

# Distances
Hz, chi, Da = csl.distances(cosmo, [0.1, 0.5, 1.0])

# Halo-model tSZ Cl^yy
profile = csl.ProfileParamsA10(P0=8.13, beta=5.48, B=1.25)
ell = jnp.geomspace(2, 9000, 80)
cl_1h, cl_2h = csl.cl_yy(cosmo, profile, ell)

# MCMC fast path: precompute cosmology + halo grids once → ~5 ms/call
ev = csl.cl_yy_factory(cosmo, ell)
cl_1h, cl_2h = ev(profile)

Throughput

Warm-call timing, n = 100 calls per benchmark, freshly randomised inputs:

Function mean ± std (ms) calls/s
derived 0.54 ± 0.04 1850 ± 150
cl_TTTEEE 2.52 ± 0.14 400 ± 25
Pk 1.49 ± 0.12 670 ± 55
distances 1.29 ± 0.09 770 ± 60
cl_yy (full pipeline) 17.84 ± 0.58 56 ± 2
cl_yy_factory (fixed-cosmo) 5.38 ± 0.42 185 ± 15
cl_yy_factory + jax.grad 17.12 ± 1.01 58 ± 3

Reference platform: macOS arm64 (M-series CPU), single-thread JAX. See Throughput for a more detailed table + reproduction script.

JAX gradients

All public functions are JAX-traceable. The factory closure is the recommended path for gradient-based inference at fixed cosmology:

import jax
ev = csl.cl_yy_factory(cosmo, ell)

def loss(P0, beta):
    cl_1h, cl_2h = ev(csl.ProfileParamsA10(P0=P0, beta=beta, B=1.25))
    return jnp.sum(cl_1h + cl_2h)

d_loss = jax.grad(loss, argnums=(0, 1))(8.13, 5.48)

Gradients also work through the full pipeline (cosmology + profile) and w.r.t. the whole CosmoParams pytree — see Gradients.

Documentation

Full docs at https://classy-szlite.readthedocs.io.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

classy_szlite-0.2.2.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

classy_szlite-0.2.2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file classy_szlite-0.2.2.tar.gz.

File metadata

  • Download URL: classy_szlite-0.2.2.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for classy_szlite-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7edbc595212753263fe09e186068b1e6b5e8b82b84484264c2be61499b993259
MD5 479a05048b13bbde3a34c3478ca440d9
BLAKE2b-256 de41a1e86eb4dc57124ecaebb592a62457d318937f04bcfeca894d433512227d

See more details on using hashes here.

Provenance

The following attestation bundles were made for classy_szlite-0.2.2.tar.gz:

Publisher: publish.yml on CLASS-SZ/classy_szlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file classy_szlite-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: classy_szlite-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for classy_szlite-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c8f39d369054ac0568072639f241a408f79b2aa1209b935ceb4d91cb428913e
MD5 cd96e1ca48280560e0530a4f45513b57
BLAKE2b-256 0126ab83464cfd1b8ba7c5831c18018dfff86ce1638938dd0f6f59db8ec58307

See more details on using hashes here.

Provenance

The following attestation bundles were made for classy_szlite-0.2.2-py3-none-any.whl:

Publisher: publish.yml on CLASS-SZ/classy_szlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page