Skip to main content

cosmograd

Differentiable cosmology in JAX, with interchangeable background and perturbation models.

Installation

uv add cosmograd
uv add 'cosmograd[cosmopower]'  # CosmoPower-JAX backend
uv add 'cosmograd[bacco]'       # bacco emulator backend

Usage

import jax
from cosmograd import EisensteinHu, FlatLCDM

cosmo = FlatLCDM(H0=67.36, omega_m=0.3153)
cosmo.luminosity_distance(1.0)  # Mpc
jax.grad(lambda c: c.comoving_distance(1.0))(cosmo)
EisensteinHu(cosmo).matter_power_spectrum(0.1, 0.5)  # Mpc^3

Or wrap your own parameter pytree and Hubble rate with GenericBackground:

import jax
import jax.numpy as jnp
from cosmograd import GenericBackground


def hubble(p, z):
    e2 = p["omega_m"] * (1 + z) ** 3 + 1 - p["omega_m"]
    return p["h"] / 2997.92458 * jnp.sqrt(e2)


bg = GenericBackground({"h": 0.6736, "omega_m": 0.3153}, hubble, lambda p: p["omega_m"])
jax.grad(lambda b: b.luminosity_distance(1.0))(bg).params

See the API docstrings for parameter conventions, units and valid ranges.

Features

  • Background expansion and distances for curved and flat cosmologies.
  • Linear growth and Eisenstein–Hu matter power spectra.
  • Optional CosmoPower and bacco emulator backends.
  • JAX differentiation through cosmological parameters.

Caveats

Perturbation backends assume a flat universe. Set the cosmological parameters explicitly when computing spectra; otherwise their defaults are used. The growth solver's initial conditions require matter domination; see its docstring for radiation and redshift constraints. Emulator weights may download on first use.

References

License

MIT

Metadata

Release files for cosmograd 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cosmograd 0.2.0
File Size Uploaded Provenance Actions
cosmograd-0.2.0.tar.gz 36.4 kB With provenance Details for cosmograd-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cosmograd 0.2.0
File Interpreter ABI Platform Actions
cosmograd-0.2.0-py3-none-any.whl Python 3 none any Details for cosmograd-0.2.0-py3-none-any.whl

Total release size: 87.5 kB

Release files / cosmograd-0.2.0.tar.gz

Download URL cosmograd-0.2.0.tar.gz
Size 36.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1670c11dcd55b0000a343bb02ec73ff0893e1e56aff37aeebe344451e22c8d7a
BLAKE2b-256 checksum
How to use checksums
7e29206bdf0b9523a76ca118acac0bc87c1150f1301dafcd9f71e159ba9bca92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / cosmograd-0.2.0-py3-none-any.whl

Download URL cosmograd-0.2.0-py3-none-any.whl
Size 51.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fb19637ff86a5f69ff93d8afce99735d0b755d08578b02c4b6e8c3c9008425b
BLAKE2b-256 checksum
How to use checksums
f1bba48fabebbd11daefc49e9f229f1817edab694f3fd364450de71d156bd38c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for cosmograd 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cosmograd-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page