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 a theory code (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 code, which computes 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.
_cosmo
(info_theory, modules=None, timing=None)¶ 
needs
(**requirements)¶ Specifies the quantities that each likelihood needs from the Cosmology code.
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"], [...]]}
.H={'z': [z_1, ...], 'units': '1/Mpc' or 'km/s/Mpc'}
: Hubble rate at the redshifts requested, in the given units. Get it withget_H()
.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()
.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 cosmological products and parameters requested by the likelihoods.

get_param
(p)¶ Interface function for likelihoods to get sampled and derived parameters.
Always use this one; don’t try to access theory code attributes directly!

get_Cl
(ell_factor=False, units='muK2')¶ Returns a dictionary of lensed CMB power spectra and the lensing potential
pp
power spectrum.Set the units with the keyword
units='1''muK2''K2'
(default: ‘muK2’, except for the lensing potential power spectrum, which is always unitless).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_H
(z, units='km/s/Mpc')¶ Returns the Hubble rate at the given redshifts.
The redshifts must be a subset of those requested when
needs()
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.
The redshifts must be a subset of those requested when
needs()
was called.

get_Pk_interpolator
(z)¶ Returns a (dict of) power spectrum interpolator(s)
PowerSpectrumInterpolator
.

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_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
needs()
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, logk=False, logP=False)¶ 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).
 logk – if True (default: False), assumes that k’s are logspaced.
 logP – if True (default: False), log of power spectrum are given and used for the underlying interpolator.
 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).