Cosmological theory codes and likelihoods¶
Models in Cosmology are usually split in two: \(\mathcal{M}=\mathcal{T}+\mathcal{E}\), where
 \(\mathcal{T}\), the theoretical model, is used to compute observable quantities \(\mathcal{O}\)
 \(\mathcal{E}\), the experimental model, accounts for instrumental errors, foregrounds… when comparing the theoretical observable with some data \(\mathcal{D}\).
In practice the theoretical model is encapsulated in one or more theory codes (CLASS, CAMB…) and the experimental model in a likelihood, which gives the probability of the data being a realization of the given observable in the context of the experiment:
Each iteration of a sampler reproduces the model using the following steps:
 A new set of theory+experimental parameters is proposed by the sampler.
 The theory parameters are passed to the theory codes, which compute one or more observables.
 The experimental parameters are passed to each of the likelihoods, which in turn ask the theory code for the current value of the observables they need, and use all of that to compute a logprobability of the data.
cobaya wraps the most popular cosmological codes under a single interface, documented below. The codes themselves are documented in the next sections, followed by the internal likelihoods included in cobaya.
Cosmological theory code¶

class
theories._cosmo.
BoltzmannBase
(info=mappingproxy({}), name=None, timing=None, packages_path=None, initialize=True, standalone=True)¶ 
initialize
()¶ Initializes the class (called from __init__, before other initializations).

initialize_with_params
()¶ Additional initialization after requirements called and input_params and output_params have been assigned (but provider and assigned requirements not yet set).

get_allow_agnostic
()¶ Whether it is allowed to pass all unassigned input parameters to this component (True) or whether parameters must be explicitly specified (False).
Returns: True or False

get_param
(p)¶ Interface function for likelihoods and other theory components to get derived parameters.

must_provide
(**requirements)¶ Specifies the quantities that this Boltzmann code is requested to compute.
Typical requisites in Cosmology (as keywords, case insensitive):
Cl={...}
: CMB lensed power spectra, as a dictionary{spectrum:l_max}
, where the possible spectra are combinations of “t”, “e”, “b” and “p” (lensing potential). Get withget_Cl()
. [BETA: CAMB only; notation may change!]
source_Cl={...}
: \(C_\ell\) of given sources with given windows, e.g.:source_name: {"function": "spline""gaussian", [source_args]
; for now,[source_args]
follow the notation ofCAMBSources
. If can also takelmax: [int]
,limber: True
if Limber approximation desired, andnon_linear: True
if nonlinear contributions requested. Get withget_source_Cl()
. Pk_interpolator={...}
: Matter power spectrum interpolator in \((z, k)\). Takes"z": [list_of_evaluated_redshifts]
,"k_max": [k_max]
,"extrap_kmax": [max_k_max_extrapolated]
,"nonlinear": [TrueFalse]
,"vars_pairs": [["delta_tot", "delta_tot"], ["Weyl", "Weyl"], [...]]}
. Nonlinear contributions are included by default. Note that the nonlinear setting determines whether nonlinear corrections are calculated; the get_Pk_interpolator function also has a nonlinear argument to specify if you want the linear or nonlinear spectrum returned (to have both linear and nonlinear spectra available request a tuple (False,True) for the nonlinear argument). Allk
values should be in units of1/Mpc
.Pk_grid={...}
: similar to Pk_interpolator except that rather than returning a bicubic spline object it returns the raw power spectrum grid as a (k, z, PK) set of arrays.sigma_R{...}
: RMS linear fluctuation in spheres of radius R at redshifts z. Takes"z": [list_of_evaluated_redshifts]
,"k_max": [k_max]
,"vars_pairs": [["delta_tot", "delta_tot"], [...]]}
,"R": [list_of_evaluated_R]
. Note that R is in Mpc, not h^{1} Mpc.Hubble={'z': [z_1, ...]}
: Hubble rate at the requested redshifts. Get it withget_Hubble()
.angular_diameter_distance={'z': [z_1, ...]}
: Physical angular diameter distance to the redshifts requested. Get it withget_angular_diameter_distance()
.comoving_radial_distance={'z': [z_1, ...]}
: Comoving radial distance from us to the redshifts requested. Get it withget_comoving_radial_distance()
.sigma8_z={'z': [z_1, ...]}
: Amplitude of rms fluctuations \(\sigma_8\) at the redshifts requested. Get it withget_sigma8()
.fsigma8={'z': [z_1, ...]}
: Structure growth rate \(f\sigma_8\) at the redshifts requested. Get it withget_fsigma8()
.k_max=[...]
: Fixes the maximum comoving wavenumber considered. Other derived parameters that are not included in the input but whose value the likelihood may need.

requested
()¶ Returns the full set of requested cosmological products and parameters.

check_no_repeated_input_extra
()¶ Checks that there are no repeated parameters between input and extra.
Should be called at initialisation, and at the end of every call to must_provide()

get_Cl
(ell_factor=False, units='FIRASmuK2')¶ Returns a dictionary of lensed CMB power spectra and the lensing potential
pp
power spectrum.Set the units with the keyword
units=number'muK2''K2''FIRASmuK2''FIRASK2'
(default: ‘FIRASmuK2’ gives FIRAScalibrated microKelvin^2, except for the lensing potential power spectrum, which is always unitless). Note the muK2 and K2 options use the model’s CMB temperature; experimental data are usually calibrated to the FIRAS measurement which is a fixed temperature. The default FIRASmuK2 takes CMB C_l scaled by 2.7255e6^2 (to get result in muK^2).If
ell_factor=True
(default: False), multiplies the spectra by \(\ell(\ell+1)/(2\pi)\) (or by \(\ell^2(\ell+1)^2/(2\pi)\) in the case of the lensing potentialpp
spectrum).

get_Hubble
(z, units='km/s/Mpc')¶ Returns the Hubble rate at the given redshifts.
The redshifts must be a subset of those requested when
must_provide()
was called.The available units are
km/s/Mpc
(i.e.c*H(Mpc^1)
) and1/Mpc
.

get_angular_diameter_distance
(z)¶ Returns the physical angular diameter distance to the given redshifts in Mpc.
The redshifts must be a subset of those requested when
must_provide()
was called.

get_comoving_radial_distance
(z)¶ Returns the comoving radial distance to the given redshifts in Mpc.
The redshifts must be a subset of those requested when
must_provide()
was called.

get_Pk_grid
(var_pair=('delta_tot', 'delta_tot'), nonlinear=True)¶ Get matter power spectrum, e.g. suitable for splining. Returned arrays may be bigger or more densely sampled than requested, but will include required values. Neither k nor PK are in h^{1} units. z and k are in ascending order.
Parameters:  nonlinear – whether the linear or nonlinear spectrum
 var_pair – which power spectrum
Returns: k, z, PK, where k and z are arrays, and PK[i,j] is the value at z[i], k[j]

get_Pk_interpolator
(var_pair=('delta_tot', 'delta_tot'), nonlinear=True, extrap_kmax=None)¶ Get P(z,k) bicubic interpolation object (
PowerSpectrumInterpolator
). Neither k nor PK are in h^{1} units.Parameters:  var_pair – variable pair for power spectrum
 nonlinear – nonlinear spectrum (default True)
 extrap_kmax – use log linear extrapolation beyond max k computed up to extrap_kmax
Returns: PowerSpectrumInterpolator
instance.

get_sigma_R
(var_pair=('delta_tot', 'delta_tot'))¶ Get sigma(R), the RMS power in an sphere of radius R Note R is in Mpc not h^{1}Mpc units and z and R are returned in ascending order.
You may get back more values than originally requested, but requested R and z should in the returned arrays.
Parameters: var_pair – which two fields to use for the RMS power Returns: R, z, sigma_R, where R and z are arrays of computed values, and sigma_R[i,j] is the value for z[i], R[j]

get_source_Cl
()¶ Returns a dict of power spectra of for the computed sources, with keys a tuple of sources
([source1], [source2])
, and an additional keyell
containing the multipoles.

get_sigma8_z
(z)¶ Present day linear theory rootmeansquare amplitude of the matter fluctuation spectrum averaged in spheres of radius 8 h^{−1} Mpc.
The redshifts must be a subset of those requested when
must_provide()
was called.

get_fsigma8
(z)¶ Structure growth rate \(f\sigma_8\), as defined in eq. 33 of Planck 2015 results. XIII. Cosmological parameters, at the given redshifts.
The redshifts must be a subset of those requested when
must_provide()
was called.

get_auto_covmat
(params_info, likes_info)¶ Tries to get match to a database of existing covariance matrix files for the current model and data.
params_info
should contain preferably the slow parameters only.


class
theories._cosmo.
PowerSpectrumInterpolator
(z, k, P_or_logP, extrap_kmax=None, logP=False, logsign=1)¶ 2D spline interpolation object (scipy.interpolate.RectBivariateSpline) to evaluate matter power spectrum as function of z and k.
This class is adapted from CAMB’s own P(k) interpolator, by Antony Lewis; it’s mostly interfacecompatible with the original.
Parameters:  z – values of z for which the power spectrum was evaluated.
 k – values of k for which the power spectrum was evaluated.
 P_or_logP – Values of the power spectrum (or logvalues, if logP=True).
 logP – if True (default: False), log of power spectrum are given and used for the underlying interpolator.
 logsign – if logP is True, P_or_logP is log(logsign*Pk)
 extrap_kmax – if set, use power law extrapolation beyond kmax up to extrap_kmax; useful for tails of integrals.

P
(z, k, grid=None)¶ Get the power spectrum at (z,k).

logP
(z, k, grid=None)¶ Get the log power spectrum at (z,k). (or minus log power spectrum if islog and logsign=1)