Grids#

discocmb.grids provides helpers for building the wave-number, time and multipole grids over which the E-B integration is performed, and the Bessel and Wigner tables on those grids.

The sources vary most at recombination and on the sound-horizon scale in tau, and at the acoustic and Silk damping scales in k. tau_grid() and k_grid() put their points there. One trajectory of the source kernel supplies these scales and the fiducial’s conformal time as a function of the scale factor (_summary._kernel_thermal_history), so building the grid compiles nothing new and integrates nothing beside the solve.

Grid.from_fiducial() adds everything else that depends on the fiducial only: the Bessel tables of the projection (projection_tables(), in chunks of spans()), the lensing potential’s exact and Limber operators, the Wigner tables of the lensing sums (lensing_tables()) and the spline matrices onto every multipole. Every batch of an inference loop shares them.

DISCO-EB integrates in the scale factor, so the solve saves at a_save, the scale factors at which the fiducial has the conformal times tau_save. Another cosmology reaches other times there, which the projection resamples onto the shared grid (resample_stencil()).

class discocmb.Grid(layout: Layout, operators: Operators)[source]#

The grid of a CMB computation and the operators on it, shaped by a fiducial cosmology.

from_fiducial() builds them. discoeb.solve_eb() solves the modes k_values at the scale factors a_save, and transfer_functions() projects the sources onto the multipoles ells with the operators, gigabytes of Bessel and Wigner tables. Spectra come out at every multipole to lmax = ells[-1].

A grid is a JAX pytree whose leaves are the operators and whose NumPy arrays are static. A jitted function that takes it as an argument reads the tables in place as device buffers. One that closed over them would carry them as constants of its program.

classmethod Grid.from_fiducial(cosmology, *, k_values=None, ells=None, n_k: int = 128, n_save: int = 600, k_fine_step: float = 0.00019, extrapolate_above: float | None = None, dtype=<class 'jax.numpy.float32'>, cache_dir: str | None = None) → Grid[source]#

Return the grid and operators appropriate for the given cosmology.

Nearby cosmologies share where their sources vary, so one fiducial’s grid serves a batch, and every batch of an inference loop.

k_values are the wave modes (1/Mpc) of the temperature and polarization, up to K_MAX_CMB, and the grid adds LENSING_MODES past the last one for the lensing potential. Without them the modes are k_grid()’s n_k with uniform steps at low k (solve_modes()). The C_l quadrature runs on quadrature_modes() of step k_fine_step, and the solve saves at n_save scale factors (tau_grid()). ells are the multipoles to project, ELL_NODES by default, and the spectra come out at every multipole to ells[-1]. extrapolate_above leaves the modes past it unsolved and continues the last two solved ones in the lensing potential (5e-5 at 1.2 / Mpc).

dtype is the precision of the tables, of the spline onto every multipole and of the Limber tilt. Single precision costs 2.6e-4 in D_l, too much for a derivative, which needs jnp.float64 and a short list of ells: the tables grow with the multipoles.

The building takes about 13 s, mostly the Bessel tables on the host. cache_dir keeps the result on disk under a digest of the arguments, the fiducial and the installed sources of DISCO-CMB, DISCO-EB and modax.

property Grid.k_values: ndarray#

The wave modes (1/Mpc) to solve, ascending.

property Grid.a_save: ndarray#

The scale factors at which to save, from discoeb.A_START to 1.

property Grid.lmax: int#

The last multipole of the spectra.