Intialize

[1]:
from classy_sz import Class as Class_sz

Baseline parameterization

[2]:
# the baseline parameterization is:

cosmo_params = {
'omega_b': 0.02242,
'omega_cdm':  0.11933,
'H0': 67.66, # use H0 because this is what is used by the emulators and to avoid any ambiguity when comparing with camb.
'tau_reio': 0.0561,
'ln10^{10}A_s': 3.047,
'n_s': 0.9665
}
[3]:
%%time
classy_sz = Class_sz()
classy_sz.set(cosmo_params)
classy_sz.set({
'output':'tCl,lCl,pCl',
})
classy_sz.compute_class_szfast()
CPU times: user 855 ms, sys: 173 ms, total: 1.03 s
Wall time: 173 ms

collect derived parameters

Here are some examples. More parameters are available.

[4]:
classy_sz.sigma8()
[4]:
0.8118792418260571
[5]:
classy_sz.Neff()
[5]:
3.044172067466906
[6]:
classy_sz.get_current_derived_parameters(['A_s'])
[6]:
{'A_s': 2.105209331337507e-09}
[7]:
classy_sz.get_current_derived_parameters(['logA'])
[7]:
{'logA': 3.047}
[8]:
classy_sz.get_current_derived_parameters(['ln10^{10}A_s'])
[8]:
{'ln10^{10}A_s': 3.047}
[9]:
classy_sz.get_current_derived_parameters(['Neff'])
[9]:
{'Neff': 3.044172067466906}
[10]:
classy_sz.get_current_derived_parameters(['Omega_m'])
[10]:
{'Omega_m': 0.30964144154550644}

Note that to access some neutrinos parameters, you may need to run the background solver (always skipped by default in the fast mode).

This is done by setting skip_background_and_thermo: 0 (i.e., do not skip background and thermo modules)

[11]:
%%time
classy_sz = Class_sz()
classy_sz.set(cosmo_params)
classy_sz.set({
'output':'tCl,lCl,pCl',
'skip_background_and_thermo': 0,

# tell class what neutrino model you are working with (be careful, make sure it is consistent with your emulator choice!)
'N_ncdm': 1,
'm_ncdm': 0.02,
'deg_ncdm': 3,
})
classy_sz.compute_class_szfast()
CPU times: user 749 ms, sys: 190 ms, total: 939 ms
Wall time: 174 ms
[12]:
classy_sz.get_current_derived_parameters(['m_ncdm_tot'])
[12]:
{'m_ncdm_tot': 0.060025303775261975}
[13]:
classy_sz.Omega_nu, 3.*0.02/93.14/classy_sz.h()**2
[13]:
(0.0014077779095836118, 0.0014071844582622115)

Matter and total densities

In class_sz, we follow the same conventions as class.

The budget equation is:

\[\Omega_{tot} = 1 = \Omega_{m} + \Omega_{r} + \Omega_{\lambda}\]

With

\[\Omega_{m} = \Omega_{c} + \Omega_{b} + \Omega_{ncdm}^{nr}\]

with \(\Omega_{ncdm}^{nr} = (\rho_{ncdm} - 3p_{ncdm})/\rho_{tot}\) the non-relativistic contribution of other species (like massive neutrinos).

and

\[\Omega_{r} = \Omega_{g} + 3p_{ncdm}/\rho_{tot} + \Omega_{ur}\]

with

\[\Omega_{ur} = N_{ur}\frac{7}{8} \left(\frac{4}{11}\right)^{4/3}\Omega_{g}\]

We also denote

\[\Omega_{ncdm,0} = \frac{\rho_{ncdm,0}}{\rho_{tot,0}} = \frac{M_{ncdm,tot}}{93.14h^2\,[\mathrm{eV}]}\]

Accessing the list of set params

[14]:
# the baseline parameterization is:

cosmo_params = {
'omega_b': 0.02242,
'omega_cdm':  0.11933,
'H0': 67.66, # use H0 because this is what is used by the emulators and to avoid any ambiguity when comparing with camb.
'tau_reio': 0.0561,
'ln10^{10}A_s': 3.047,
'n_s': 0.9665
}
[15]:
%%time
classy_sz = Class_sz()
classy_sz.set(cosmo_params)
classy_sz.set({
'output':'tCl,lCl,pCl',
})
classy_sz.compute_class_szfast()
CPU times: user 371 ms, sys: 87.1 ms, total: 458 ms
Wall time: 73.3 ms
[16]:
classy_sz.pars
[16]:
{'output': 'tCl,lCl,pCl',
 'skip_input': 1,
 'skip_background_and_thermo': 1,
 'skip_pknl': 1,
 'skip_pkl': 1,
 'skip_chi': 1,
 'skip_hubble': 1,
 'skip_class_sz': 1,
 'skip_sigma8_at_z': 1,
 'skip_sigma8_and_der': 0,
 'skip_cmb': 0,
 'cosmo_model': 6,
 'jax': 0,
 'classy_sz_verbose': 'none',
 'ndim_masses': 500,
 'ndim_redshifts': 100,
 'sBBN file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//bbn/PRIMAT21_class_format.dat',
 'A10_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/class_sz_lnIgnfw-and-d2lnIgnfw-vs-lnell-over-ell500_A10.txt',
 'P13_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/class_sz_lnIgnfw-and-d2lnIgnfw-vs-lnell-over-ell500_P13.txt',
 'Tinker_et_al_10_alpha_consistency_msyriac_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/Tinker_et_al_10_alpha_consistency_msyriac.txt',
 'full_path_to_dndz_gal': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/WISC_bin3_ngal_example1.txt',
 'full_path_and_prefix_to_dndz_ngal': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/WISC_bin3_ngal_example',
 'full_path_to_source_dndz_gal': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/WISC_bin3.txt',
 'cib_Snu_file_snu': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/filtered_snu_planck_fine.txt',
 'cib_Snu_file_z': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/filtered_snu_planck_z_fine.txt',
 'cib_Snu_file_nu': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/filtered_snu_planck_nu_fine.txt',
 'SZ_cat_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/SZ_cat.txt',
 'sz_selection_function_thetas_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/SZ_thetas.txt',
 'sz_selection_function_skyfracs_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/SZ_skyfracs.txt',
 'sz_selection_function_ylims_file': '/Users/boris/class_sz_data_directory/class_sz/class-sz//class_sz_auxiliary_files/includes/SZ_ylims.txt',
 'omega_b': 0.02242,
 'omega_cdm': 0.11933,
 'H0': 67.66,
 'tau_reio': 0.0561,
 'ln10^{10}A_s': 3.047,
 'n_s': 0.9665}

Using different names

[27]:
# the baseline parameterization is:

cosmo_params = {
'omega_b': 0.02242, # here we can use ombh2 rather than omega_b
'omch2':  0.10933, # here we can use omch2 rather than omega_cdm
'H_0': 67.66, # use H0 or H_0 because this is what is used by the emulators and to avoid any ambiguity when comparing with camb.
'tau_reio': 0.0561,
'logA': 3.047, # here we can use logA rather than ln10^{10}A_s
'ns': 0.9665  # here we can use ns rather than ns
}
[28]:
%%time
classy_sz = Class_sz()
classy_sz.set(cosmo_params)
classy_sz.set({
'output':'tCl,lCl,pCl',
})
classy_sz.compute_class_szfast()

print('sigma8:',classy_sz.sigma8())
sigma8: 0.7670913521238548
CPU times: user 702 ms, sys: 124 ms, total: 826 ms
Wall time: 124 ms

Passing \(\sigma_8\) instead of \(A_s\)

classy_sz can have \(\sigma_8\) as an input parameter.

In this case the calculation takes a bit longer because it requires a root finding step to get the adequate value of \(A_s\).

[29]:
cosmo_params_with_sigma_8 = {
'omega_b': 0.02242,
'omega_cdm':  0.11933,
'H0': 67.66, # use H0 because this is what is used by the emulators and to avoid any ambiguity when comparing with camb.
'tau_reio': 0.0561,
'sigma8': 0.8119,
'n_s': 0.9665

}
[30]:
%%time
classy_sz = Class_sz()
classy_sz.set(cosmo_params_with_sigma_8)
classy_sz.set({
'output':'tCl,lCl,pCl',
})
classy_sz.compute_class_szfast()
CPU times: user 1.61 s, sys: 234 ms, total: 1.84 s
Wall time: 281 ms
[31]:
classy_sz.get_current_derived_parameters(['A_s'])
[31]:
{'A_s': 2.1053170341400974e-09}
[32]:
classy_sz.get_current_derived_parameters(['logA'])
[32]:
{'logA': 3.047051158830638}
[33]:
classy_sz.get_current_derived_parameters(['Neff'])
[33]:
{'Neff': 3.0441720915141284}

Compute with Jax

[1]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
from classy_sz import Class as Class_sz
import jax.numpy as jnp
from jax import jacfwd
[2]:
%%time
cosmo_params = {
'omega_b': 0.02242,
'omega_cdm':  0.11933,
'H0': 67.66, # use H0 because this is what is used by the emulators.
'tau_reio': 0.0561,
'ln10^{10}A_s': 3.047,
'n_s': 0.9665,
}

# initialize computation
classy_sz = Class_sz()
classy_sz.set(cosmo_params)
classy_sz.set({
'output':' ',
'jax': 1,
})
classy_sz.compute_class_szfast()
CPU times: user 823 ms, sys: 182 ms, total: 1.01 s
Wall time: 1.4 s
[3]:
classy_sz.get_sigma8_and_der(params_values_dict=cosmo_params)
[3]:
Array([1.04148978e+00, 8.11879242e-01, 2.45858174e-01, 7.84135042e+00,
       3.04417207e+00, 2.80969597e+02, 1.08869035e+03, 1.44643192e+02,
       1.38876674e+04, 2.81716002e+02, 1.08487887e+03, 1.44977738e+02,
       1.38867784e+04, 1.47204456e+02, 1.37886580e+01, 2.73113427e+01,
       2.56297550e+01], dtype=float64)

ordering:

cosmopower_derived_params_names = ['100*theta_s',
                                   'sigma8',
                                   'YHe',
                                   'z_reio',
                                   'Neff',
                                   'tau_rec',
                                   'z_rec',
                                   'rs_rec',
                                   'ra_rec',
                                   'tau_star',
                                   'z_star',
                                   'rs_star',
                                   'ra_star',
                                   'rs_drag']
[4]:
Omega_c = 0.26

def z_CMB(Omega_c):
    omega_cdm = Omega_c*(cosmo_params['H0']/100.)**2
    cosmo_params.update({'omega_cdm':omega_cdm})
    z_CMB = classy_sz.get_sigma8_and_der(params_values_dict=cosmo_params)[6]
    return z_CMB
[5]:
z_CMB(Omega_c)
[5]:
Array(1088.66830151, dtype=float64)
[6]:
dz_CMB = jacfwd(z_CMB)
[7]:
%%time
dz_CMB(Omega_c)
CPU times: user 1.03 s, sys: 20.5 ms, total: 1.05 s
Wall time: 1 s
[7]:
Array(33.08539939, dtype=float64)
[8]:
def D_CMB(Omega_c):
    omega_cdm = Omega_c*(cosmo_params['H0']/100.)**2
    cosmo_params.update({'omega_cdm':omega_cdm})
    ra_rec = classy_sz.get_sigma8_and_der(params_values_dict=cosmo_params)[8]
    return ra_rec/(1.+z_CMB(Omega_c))
[9]:
dD_CMB = jacfwd(D_CMB)
[10]:
dD_CMB(Omega_c)
[10]:
Array(-16.7666128, dtype=float64)