ggah_mod
Galaxies, gas, AGN and halos: a layered, differentiable halo-model forward model.
ggah_mod predicts the power spectrum of any pair of tracers, and its
projections, from one set of cosmological and astrophysical parameters.
It is written in JAX, so every prediction can be differentiated with respect to
every parameter, exactly.
Documentation: https://ggah-mod.readthedocs.io
Install
ggah_mod needs Python ≥ 3.11:
pip install ggah_mod
or, to work on it, from a clone:
git clone https://github.com/JohanComparat/ggah_mod.git
cd ggah_mod
pip install -e .
That is the differentiable path, and it needs no compiler: numpy, scipy, JAX, and
the two emulators it reads, emu_pk
for the linear power spectrum and
emu_hmf for the mass function, both
also from PyPI. Check it with
python -c "import ggah_mod; print(ggah_mod.__version__)"
Optional extras add the rest, e.g. pip install "ggah_mod[reference]":
| extra | installs | for |
|---|---|---|
reference |
classy |
CLASS, the linear spectrum of the ACCURATE flavour; pip compiles it, so a C compiler is needed |
backends |
camb |
CAMB, the alternative Boltzmann backend |
cobaya |
cobaya |
ggah_mod.interfaces.cobaya, a cobaya Theory |
tables |
soxs |
regenerating the shipped APEC cooling table |
dev |
pytest, pytest-cov, pytest-xdist, astropy, colossus, camb |
the test suite |
docs |
sphinx, furo, myst-nb, sphinx-copybutton, sphinxcontrib-bibtex |
building the documentation |
With conda or mamba,
environment.yml
creates an environment with ggah_mod, the CPU build of jaxlib, and
matplotlib and a Jupyter kernel for the documentation notebooks:
mamba env create -f environment.yml
mamba activate ggah_mod
JAX installs its CPU build by default; for a GPU, install the matching jax
build first, following the JAX installation guide.
Quickstart
import jax
jax.config.update("jax_enable_x64", True) # before the first ggah_mod import
import numpy as np
from ggah_mod import DIFFERENTIABLE
from ggah_mod.cosmology import PLANCK18, comoving_distance, make_pk, sigma8
from ggah_mod.halos.field import make_field
# Layer 1: the linear power spectrum, and what is read off it.
pk = make_pk("emu_pk") # "class" needs the [reference] extra
k = np.logspace(-4, np.log10(200.0), 512) # h/Mpc
print(sigma8(pk.pk(k, 0.0, PLANCK18), k)) # an output, never an input
print(comoving_distance(np.array([0.5, 1.0]), PLANCK18)) # h^-1 Mpc
# Layer 2: mass function, bias, concentration and profiles on one mass grid.
field = make_field(PLANCK18, DIFFERENTIABLE, pk, z=0.5)
print(field.m[::64]) # h^-1 Msun
print(field.dndm[::64], field.bias[::64]) # dn/dM, b(M)
# Everything is differentiable: d sigma_8 / d Omega_m through the emulator.
d_sigma8 = jax.grad(lambda om: sigma8(pk.pk(k, 0.0, PLANCK18.replace(Omega_m=om)), k))
print(d_sigma8(0.31))
The six layers
Each layer depends only on the ones above it.
| layer | subpackage | computes | documentation |
|---|---|---|---|
| 1 | ggah_mod.cosmology |
parameters and density budget, background and distances, linear P(k), amplitude and growth |
layer 1 |
| 2 | ggah_mod.halos |
variance and peak height, mass function, bias, concentration, profiles, the halo field | layer 2 |
| 3 | ggah_mod.sectors |
the tracers | ⚠️ work in progress |
| 4 | ggah_mod.spectra |
power spectra of pairs of tracers | ⚠️ work in progress |
| 5 | ggah_mod.observables |
projected observables | ⚠️ work in progress |
| 6 | ggah_mod.covariance |
covariances of data vectors | ⚠️ work in progress |
| — | ggah_mod.interfaces |
adapters that let other packages drive this one | ⚠️ work in progress |
Beside them, ggah_mod.backend holds the flavours below, ggah_mod.numerics the
numerical helpers several layers share, and ggah_mod/data the distilled tables
the package ships.
Layers 3 to 6 and the interfaces are work in progress: released as tested
code ahead of their verification and documentation, so their interface and
results may change. Importing any of them emits a ggah_mod.WorkInProgressWarning
once; warnings.filterwarnings("ignore", category=ggah_mod.WorkInProgressWarning)
silences it.
Two flavours of one model
The same code runs in two flavours, selected by a Backend:
ACCURATE: a Boltzmann solver (CLASS by default, CAMB as the alternative), fine grids, exact quadrature. For fitting.DIFFERENTIABLE: theemu_pkemulator, coarser grids. Differentiable end to end. For forecasting.DIFFERENTIABLE_COARSEis the same flavour on smaller grids.
They are not two implementations: only the linear power spectrum forks. The
disagreement between them is measured, row by row, in the parity budget
(tests/test_parity_budget.py), never assumed.
Decisions fixed once
- One amplitude.
ln10A_s.sigma8andS8are outputs, computed from the spectrum. Passing either as an input raises. Omega_mcontains the neutrinos. The budgetOmega_b + Omega_cdm + Omega_nu == Omega_mcloses exactly, withOmega_nuthe neutrinos' rest mass.- One neutrino convention, CLASS's. Three massive states at
T_ncdm = 0.71611 T_CMBplus a massless remainder ofN_eff = 3.044, on the exact energy integral over their relic spectrum: the rest mass isSigma m/(93.143 eV h^2), and at 0.06 eV in the degenerate ordering the neutrino density today exceeds it by 5.0e-4, which is their kinetic energy and the remainder.CambPkis handed the same neutrinos, spelt in CAMB's interface. - Cold and total densities are separately named. Halos form from
rho_cold; lensing seesrho_matter. Neither ever stands in for the other. - One growth route, with no silent fallback to an approximation.
- Nothing is fixed by hard-coding. A constant a user might want to vary is a parameter with a prior and a bound.
Status
Version 1.0 is the first public release. Layers 1 and 2 are verified and documented. Layers 3 to 6 are work in progress: implemented and tested, with their verification ongoing and their documentation to follow it. Calibrated values of the astrophysical parameters are not yet released.
Contributing and the development environment are described in
CONTRIBUTING.md; changes are listed in
CHANGELOG.md.
Citing
Please cite the technical paper (Comparat, in prep.) and the software, whose
metadata is in CITATION.cff.
License
MIT; see LICENSE.
Metadata
Release files for ggah-mod 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ggah_mod-1.0.0.tar.gz | 1.3 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ggah_mod-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.2 MB
Release files / ggah_mod-1.0.0.tar.gz
| Download URL | ggah_mod-1.0.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86b49567c1a1a7e48409fbba3b4f6ca362c2c3d6a043883fce29e788be6b20ba
|
|
BLAKE2b-256 checksum How to use checksums |
47b215e638a5cb1b67d8d44914d0bca355e5beb0c37a1d2ee1e152051956840a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / ggah_mod-1.0.0-py3-none-any.whl
| Download URL | ggah_mod-1.0.0-py3-none-any.whl |
|---|---|
| Size | 932.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
685e0097708e23e557b5be4ecb97a09719af28288e27ce74fb33435c14270158
|
|
BLAKE2b-256 checksum How to use checksums |
be3771822f5ce2cda6ebed76652ff942eae993d6ae7e98003fcb9a7732cd7626
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency log