disco-eb 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: disco-eb
3
+ Version: 1.0.1
4
+ Summary: A differentiable linear Einstein-Boltzmann solver for cosmology, on the GPU
5
+ Author: Florian List, Natalia Porqueres, Lawrence Berry
6
+ Author-email: Oliver Hahn <oliver.hahn@univie.ac.at>
7
+ License-Expression: MIT
8
+ Project-URL: Documentation, https://cosmo-sims.github.io/DISCO-EB/
9
+ Project-URL: Source, https://github.com/cosmo-sims/DISCO-EB
10
+ Project-URL: Issues, https://github.com/cosmo-sims/DISCO-EB/issues
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: GPU :: NVIDIA CUDA
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
20
+ Classifier: Topic :: Scientific/Engineering :: Physics
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: jax>=0.6.2
25
+ Requires-Dist: numpy>=2.2.6
26
+ Requires-Dist: modax-solvers>=0.2.2
27
+ Requires-Dist: numba-enzyme-cuda>=0.3.0
28
+ Provides-Extra: cuda12
29
+ Requires-Dist: jax[cuda12]>=0.6.2; extra == "cuda12"
30
+ Provides-Extra: cuda13
31
+ Requires-Dist: jax[cuda13]>=0.9.1; python_version >= "3.11" and extra == "cuda13"
32
+ Dynamic: license-file
33
+
34
+ <h1 align="center">DISCO-EB</h1>
35
+
36
+ <!--
37
+ The coverage badge reads a gist that the `tests` workflow rewrites on every
38
+ push to main. The id below is the repository variable COVERAGE_GIST_ID.
39
+ These badges sit above the `overview` snippet marker, so the documentation
40
+ site does not repeat them.
41
+ -->
42
+ <p align="center">
43
+ <a href="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/tests.yml"><img alt="tests" src="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/tests.yml/badge.svg?branch=main"></a>
44
+ <a href="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/tests.yml"><img alt="coverage" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Flawrenceberry%2Fb451e14a9620fabb0d49c345f13b5414%2Fraw%2Fdiscoeb-coverage.json"></a>
45
+ <a href="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/lint.yml"><img alt="lint" src="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/lint.yml/badge.svg?branch=main"></a>
46
+ <a href="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/types.yml"><img alt="types" src="https://github.com/cosmo-sims/DISCO-EB/actions/workflows/types.yml/badge.svg?branch=main"></a>
47
+ <a href="https://pypi.org/project/disco-eb/"><img alt="PyPI" src="https://img.shields.io/pypi/v/disco-eb"></a>
48
+ <a href="https://pypi.org/project/disco-eb/"><img alt="Downloads" src="https://img.shields.io/pypi/dm/disco-eb"></a>
49
+ <a href="https://pypi.org/project/disco-eb/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/disco-eb"></a>
50
+ <a href="https://docs.jax.dev/"><img alt="JAX" src="https://img.shields.io/badge/JAX-compatible-3f51b5"></a>
51
+ <a href="https://arxiv.org/abs/2311.03291"><img alt="arXiv" src="https://img.shields.io/badge/arXiv-2311.03291-b31b1b.svg"></a>
52
+ <a href="https://www.conventionalcommits.org/en/v1.0.0/"><img alt="Conventional Commits" src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white"></a>
53
+ <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg"></a>
54
+ </p>
55
+
56
+ <p align="center">
57
+ <a href="#installation">Installation</a> •
58
+ <a href="#quickstart">Quickstart</a> •
59
+ <a href="https://cosmo-sims.github.io/DISCO-EB/">Documentation</a> •
60
+ <a href="https://arxiv.org/abs/2311.03291">Paper</a> •
61
+ <a href="#citation">Citation</a>
62
+ </p>
63
+
64
+ <!-- start:overview -->
65
+
66
+ DISCO-EB is a **differentiable linear Einstein-Boltzmann solver** for cosmology, and the Einstein-Boltzmann module of the DISCO-DJ framework (DIfferentiable Simulations for COsmology, Done with Jax). It evolves the background, the recombination history and the linear perturbations of every wave mode of a **batch of cosmologies in one GPU launch**.
67
+
68
+ The solve runs as a [modax](https://github.com/lawrenceberry/modax) Rodas5P kernel. RECFAST and the optical depth step alongside the perturbation hierarchy in the same kernel, so the solve needs no tables. You choose which quantities to keep at which times, and the kernel evaluates them as it goes. The results are JAX arrays, differentiable in the cosmological parameters by forward sensitivities. DISCO-EB supports flat or curved ΛCDM, a CPL dark-energy fluid $(w_0, w_a)$, massive neutrinos and reionization.
69
+
70
+ <!-- end:overview -->
71
+
72
+ The [documentation](https://cosmo-sims.github.io/DISCO-EB/) covers the API and how to use it. The [paper](https://arxiv.org/abs/2311.03291) describes the method and its accuracy against CLASS.
73
+
74
+ ## Installation
75
+
76
+ <!-- start:install -->
77
+
78
+ ```bash
79
+ pip install "disco-eb[cuda13]" # or [cuda12], which Python 3.10 needs
80
+ ```
81
+
82
+ You need a GPU to run a solve, but not to import the package. modax brings the CUDA compiler stack with it. The CMB spectra live in a separate package, [DISCO-CMB](https://github.com/lawrenceberry/DISCO-CMB), which builds on this one.
83
+
84
+ <!-- end:install -->
85
+
86
+ ## Quickstart
87
+
88
+ <!-- start:quickstart -->
89
+
90
+ This example keeps the comoving curvature perturbation $\mathcal{R}$ and the CDM density contrast of 64 wave modes at 100 conformal times:
91
+
92
+ ```python
93
+ import jax
94
+
95
+ jax.config.update("jax_enable_x64", True)
96
+
97
+ import numpy as np
98
+ from discoeb import solve_eb
99
+
100
+ h = 0.6732
101
+ cosmology = {
102
+ "Omegam": 0.1424 / h**2, "Omegab": 0.02238 / h**2, "H0": 100 * h,
103
+ "w_DE_0": -1.0, "w_DE_a": 0.0, "cs2_DE": 1.0, "Omegak": 0.0,
104
+ "A_s": 2.1e-9, "n_s": 0.966, "k_p": 0.05,
105
+ "Tcmb": 2.7255, "YHe": 0.2454, "Neff": 3.046, "Nmnu": 0.0, "mnu": 0.0,
106
+ }
107
+ k = np.geomspace(1e-4, 1.0, 64) # 1/Mpc
108
+ tau = np.geomspace(1.0, 2e4, 100) # Mpc, the last times past today
109
+
110
+ solution = solve_eb(cosmology, k, tau, keep=("R", "clxc"))
111
+ R = solution["R"] # (1, 64, 100): cosmologies, wave modes, times
112
+ ```
113
+
114
+ <!-- end:quickstart -->
115
+
116
+ ## Development
117
+
118
+ <!-- start:development -->
119
+
120
+ The repository uses [uv](https://docs.astral.sh/uv/):
121
+
122
+ ```bash
123
+ git clone https://github.com/cosmo-sims/DISCO-EB.git && cd DISCO-EB
124
+ uv sync --extra cuda13 # or --extra cuda12
125
+
126
+ uv run pytest tests -rs # needs a GPU, and -rs shows skipped CLASS comparisons
127
+ uv run ruff format && uv run ruff check --fix
128
+ uv run ty check
129
+ uv run pre-commit install # the checks above, and a commit-message check
130
+ ```
131
+
132
+ The documentation (Sphinx with MyST and autodoc) builds in an environment of
133
+ its own, the package's CPU install plus the docs group:
134
+
135
+ ```bash
136
+ export UV_PROJECT_ENVIRONMENT=.venv-docs
137
+ uv sync --no-default-groups --group docs
138
+ uv run --no-sync sphinx-autobuild docs docs/_build/html # live preview
139
+ uv run --no-sync sphinx-build -W docs docs/_build/html # what CI runs
140
+ ```
141
+
142
+ <!-- end:development -->
143
+
144
+ ## Citation
145
+
146
+ <!-- start:citation -->
147
+
148
+ If you use DISCO-EB in your research, please cite the
149
+ [JCAP article](https://doi.org/10.1088/1475-7516/2024/06/063):
150
+
151
+ ```bibtex
152
+ @article{DISCO-EB:2024,
153
+ author = "Hahn, Oliver and List, Florian and Porqueres, Natalia",
154
+ title = "{DISCO-DJ I: a differentiable Einstein-Boltzmann solver for cosmology}",
155
+ eprint = "2311.03291",
156
+ archivePrefix = "arXiv",
157
+ primaryClass = "astro-ph.CO",
158
+ doi = "10.1088/1475-7516/2024/06/063",
159
+ journal = "JCAP",
160
+ volume = "06",
161
+ pages = "063",
162
+ year = "2024"
163
+ }
164
+ ```
165
+
166
+ <!-- end:citation -->
167
+
168
+ ## License
169
+
170
+ <!-- start:license -->
171
+
172
+ DISCO-EB uses the
173
+ [MIT License](https://github.com/cosmo-sims/DISCO-EB/blob/main/LICENSE). The
174
+ recombination module adapts code from
175
+ [Recfast](https://www.astro.ubc.ca/people/scott/recfast.html), whose UBC
176
+ license its file header reproduces.
177
+
178
+ <!-- end:license -->
@@ -0,0 +1,12 @@
1
+ disco_eb-1.0.1.dist-info/licenses/LICENSE,sha256=mJVm-1igGT7a9zg2Z9minrQczT_8jkQDjNp3W3K6LwI,1125
2
+ discoeb/__init__.py,sha256=oPN2uLjo1r2wTNDo-NP-aKl3bgCE_vP_JBD4-98eZhU,3524
3
+ discoeb/component.py,sha256=_nBLK6gVwxmSprLdeMymp7iZSXS-Vn-BXthTxmdzEHo,53723
4
+ discoeb/eb_model.py,sha256=5FSMsvJ45HaALb8cAIQNCPzL9YI0_r9WC0egO3QjFBw,36638
5
+ discoeb/perturbations.py,sha256=jN0K_5rX51oSqXlZTAg-QGGyEPGNEMcQ7xESJ98pD54,60148
6
+ discoeb/recombination.py,sha256=MP_vP9SCdN82wVn_LuWPd7xiRPv8DriZYi5YW-qlTzY,27234
7
+ discoeb/spline_interpolation.py,sha256=lv2NST_8COkXY3-1Lu4RLTZdFxSqjvnygfwPytA6WuI,8927
8
+ discoeb/util.py,sha256=7KKf8Vswt3kYwQrMn753SJhtj37joAvEjzQ6ws7xHso,1508
9
+ disco_eb-1.0.1.dist-info/METADATA,sha256=Fn-r0P8O6_cHVVcEcJKxVMn1LjhGw_kASkRczBetnVA,7827
10
+ disco_eb-1.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
11
+ disco_eb-1.0.1.dist-info/top_level.txt,sha256=4O3aR-FoF7U-FCR143Ev0aHmnBQk--AD0DjSyOxL38g,8
12
+ disco_eb-1.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2026 Oliver Hahn, Florian List, Natalia Porqueres and Lawrence Berry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ discoeb
discoeb/__init__.py ADDED
@@ -0,0 +1,87 @@
1
+ """DISCO-EB, and its interface: what the CMB code -- DISCO-CMB -- may use.
2
+
3
+ DISCO-EB solves the background, the thermal history (RECFAST with
4
+ reionization) and the linear perturbation hierarchy of each wave mode on the
5
+ GPU: :mod:`discoeb.component` (the component model), :mod:`discoeb.eb_model`
6
+ (the species and their equations), :mod:`discoeb.recombination` (the
7
+ thermal history) and :mod:`discoeb.perturbations` (layouts, batching, the modax launches). The CMB
8
+ code, the separate package ``discocmb`` (DISCO-CMB), turns its output into
9
+ angular power spectra -- line-of-sight sources, grids, transfer functions,
10
+ projection and lensing. It imports from the package itself alone (and the generic
11
+ numerics of :mod:`discoeb.spline_interpolation`); DISCO-EB does not depend
12
+ on it.
13
+
14
+ **The contract.** A caller asks for *named quantities at chosen conformal
15
+ times* of a batch of cosmologies and wave modes, and gets them back
16
+ evaluated inside the kernel launch from the solver's dense output -- never the
17
+ state history:
18
+
19
+ * :func:`solve_eb` ``(cosmologies, k, tau, keep=names, extra=components)``
20
+ returns an :class:`EBSolution` whose ``values`` are ``(n_cosmologies,
21
+ len(keep), n_k, n_tau)``, with each cosmology's conformal age ``tau0``;
22
+ past its own ``tau0`` a cosmology's trajectories hold their state today.
23
+ * A name is a state element (:func:`state_names`; the thermal block's
24
+ ``lna``, ``thermo_0..2`` and the optical depth ``kappa``) or any quantity
25
+ the model provides (``adotoa``, ``opacity``, ``sigma``, ``dgrho``,
26
+ ``clxg``, ``polter``, ``R`` ...). A caller extends the vocabulary with
27
+ ``extra``: stateless :class:`Component` subclasses whose providers read the
28
+ model's quantities by name and add their own, compiled into the same
29
+ kernel -- this is how the CMB's line-of-sight sources are defined, so the
30
+ equations of both parts live in one component model and nothing of the
31
+ CMB enters the hierarchy's right-hand side.
32
+ * Error weights are given by state name (``{"theta_2": f(k)}``), so the
33
+ caller needs neither the state's index order nor the launch order.
34
+ * Differentiation: :data:`DIFFERENTIABLE_PARAMETERS` given as JAX values, or
35
+ the nine :data:`DIRECTED_NAMES` inputs (:func:`directed_inputs`) passed as
36
+ ``inputs``, make ``values`` differentiable by forward sensitivities formed
37
+ in the kernel (``jax.jvp``, ``jax.grad``), at fixed ``tau0`` and
38
+ reionization redshift.
39
+
40
+ The background for building grids comes from :func:`background_history`,
41
+ :func:`density_coefficients` and :func:`conformal_ages`; cosmologies are
42
+ parameter dictionaries or the objects :func:`as_cosmology` returns.
43
+ """
44
+
45
+ from .component import Component
46
+ from .perturbations import (
47
+ DIFFERENTIABLE_PARAMETERS,
48
+ DIRECTED_NAMES,
49
+ PERTURB_ATOL,
50
+ PERTURB_FIRST_STEP,
51
+ PERTURB_MAX_STEPS,
52
+ PERTURB_RTOL,
53
+ TAU_START,
54
+ EBSolution,
55
+ PerturbationLayout,
56
+ as_cosmology,
57
+ background_history,
58
+ conformal_ages,
59
+ density_coefficients,
60
+ directed_inputs,
61
+ joint_model,
62
+ solve_eb,
63
+ state_names,
64
+ )
65
+ from .recombination import THERMO_ERROR_WEIGHT
66
+
67
+ __all__ = [
68
+ "Component",
69
+ "DIFFERENTIABLE_PARAMETERS",
70
+ "DIRECTED_NAMES",
71
+ "EBSolution",
72
+ "PERTURB_ATOL",
73
+ "PERTURB_FIRST_STEP",
74
+ "PERTURB_MAX_STEPS",
75
+ "PERTURB_RTOL",
76
+ "PerturbationLayout",
77
+ "TAU_START",
78
+ "THERMO_ERROR_WEIGHT",
79
+ "as_cosmology",
80
+ "background_history",
81
+ "conformal_ages",
82
+ "density_coefficients",
83
+ "directed_inputs",
84
+ "joint_model",
85
+ "solve_eb",
86
+ "state_names",
87
+ ]