CAMB: issue calculating H0 with set_w_a_table()

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Rance Solomon
Posts: 10
Joined: April 21 2020
Affiliation: University at Buffalo

CAMB: issue calculating H0 with set_w_a_table()

Post by Rance Solomon » January 21 2021

I seem to be having some issue using the set_w_a_table() function in the dark energy models. For example, if I use the DarkEnergyPPF model with thetastar fixed then I am able to obtain an H0 value different from that in the LCDM base model. But when I reproduce the DarkEnergyPPF model using the set_w_a_table() function and keeping thetastar fixed I am not able to reproduce the same H0 value. Instead, the H0 value is that of the LCDM model.

Here is the python3 code demonstrating the problem. It is written using CAMB 1.3.0.

Code: Select all

import sys, platform, os
import matplotlib
from matplotlib import pyplot as plt
import numpy as np

camb_path = os.path.realpath(os.path.join(os.getcwd(),'..'))
sys.path.insert(0,camb_path)
import camb

from camb import model, initialpower
from camb.dark_energy import DarkEnergyPPF


zs = np.logspace(-5, 5, 1000)
thetastar = 0.01044341764253


# LCDM base model
params = camb.set_params(ombh2=0.022, omch2=0.122, thetastar=thetastar)
results_LCDM = camb.get_results(params)
cl_LCDM = results_LCDM.get_lensed_scalar_cls(CMB_unit = 'muK')

# DarkEnergyPPF
params = camb.set_params(ombh2=0.022, omch2=0.122, w=-0.5, wa=0.4,
        dark_energy_model='DarkEnergyPPF', thetastar=thetastar)
results_PPF = camb.get_results(params)
cl_PPF = results_PPF.get_lensed_scalar_cls(CMB_unit = 'muK')

# DarkEnergyPPF using w(a) table
a = np.logspace(-5, 0, 1000)
w = -0.5 + 0.4*(1-a)
params = camb.set_params(ombh2=0.022, omch2=0.122, thetastar=thetastar)
params.DarkEnergy = DarkEnergyPPF()
params.DarkEnergy.set_w_a_table(a, w)
results_PPFtabulated = camb.get_background(params)
results_PPFtabulated.calc_power_spectra(params)
cl_PPFtabulated = results_PPFtabulated.get_lensed_scalar_cls(CMB_unit='muK')


print('LCDM:                H0 = ', results_LCDM.Params.H0)
print('PPF DE:              H0 = ', results_PPF.Params.H0)
print('tabulated PPF DE:    H0 = ', results_PPFtabulated.Params.H0)

fig, axs = plt.subplots(2, 1, figsize=(10,8))
axs[0].semilogx(zs, results_LCDM.get_Omega('de', z=zs), c='C0')
axs[0].semilogx(zs, results_PPF.get_Omega('de', z=zs), c='C1')
axs[0].semilogx(zs, results_PPFtabulated.get_Omega('de', z=zs), c='C2')
axs[0].set_xlim([1e1,1e5])
axs[0].set_xlabel(r'$z$')
axs[0].set_ylabel(r'$\Omega_{\rm de}$')

axs[1].plot(cl_LCDM[2:,0], c='C0')
axs[1].plot(cl_PPF[2:,0], c='C1')
axs[1].plot(cl_PPFtabulated[2:,0], c='C2')
axs[1].set_xlabel(r'$\ell$')
axs[1].set_ylabel(r'$D_l [\mu {\rm D}^2]$')
axs[1].legend(['$\Lambda$CDM','PPF','tabulated PPF'])
plt.show()

Values for [math] and [math] were chosen to highlight the issue, but the problem persists still at more reasonable values. The resulting H0 values for each model are

Code: Select all

LCDM:                H0 =  67.42062819302447
PPF DE:              H0 =  49.53005264854277
tabulated PPF DE:    H0 =  67.42062819302447
while the resulting dark energy densities and power spectrum are
set_w_a_table_Issue.png
set_w_a_table_Issue.png (58.11 KiB) Viewed 149 times
The tabulated PPF dark energy model does not seem to reproduce the results of the built in DarkEnergyPPF model. If anyone familiar with the process could spot an error that may fix this problem, do please let me know.

Rance Solomon
Posts: 10
Joined: April 21 2020
Affiliation: University at Buffalo

Re: CAMB: issue calculating H0 with set_w_a_table()

Post by Rance Solomon » January 21 2021

Problem solved to the extent currently needed. The error was somewhere in the initialization of the parameters for the tabulated dark energy case. The corrected python code is below.

Code: Select all

camb_path = os.path.realpath(os.path.join(os.getcwd(),'..'))
sys.path.insert(0,camb_path)
import camb

from camb import model, initialpower
from camb.dark_energy import DarkEnergyPPF


zs = np.logspace(-5, 5, 1000)
thetastar = 0.01044341764253


# LCDM base model
params = camb.set_params(ombh2=0.022, omch2=0.122, thetastar=thetastar)
results_LCDM = camb.get_results(params)
cl_LCDM = results_LCDM.get_lensed_scalar_cls(CMB_unit = 'muK')

# DarkEnergyPPF
params = camb.set_params(ombh2=0.022, omch2=0.122, w=-0.8, wa=0.2,
        dark_energy_model='DarkEnergyPPF', thetastar=thetastar)
results_PPF = camb.get_results(params)
cl_PPF = results_PPF.get_lensed_scalar_cls(CMB_unit = 'muK')

# DarkEnergyPPF using w(a) table
a = np.logspace(-5, 0, 1000)
w = -0.8 + 0.2*(1-a)
params = model.CAMBparams()						<==================
params.DarkEnergy = DarkEnergyPPF()					<== THESE  LINES ==
params.DarkEnergy.set_w_a_table(a, w)					<== WERE CHANGED ==
params.set_cosmology(thetastar=thetastar, ombh2=0.022, omch2=0.122)	<==================
results_PPFtabulated = camb.get_background(params)
results_PPFtabulated.calc_power_spectra(params)
cl_PPFtabulated = results_PPFtabulated.get_lensed_scalar_cls(CMB_unit='muK')


print('LCDM:                H0 = ', results_LCDM.Params.H0)
print('PPF DE:              H0 = ', results_PPF.Params.H0)
print('tabulated PPF DE:    H0 = ', results_PPFtabulated.Params.H0)

fig, axs = plt.subplots(2, 1, figsize=(10,8))
axs[0].loglog(zs, results_LCDM.get_Omega('de', z=zs), c='C0')
axs[0].loglog(zs, results_PPF.get_Omega('de', z=zs), c='C1')
axs[0].loglog(zs, results_PPFtabulated.get_Omega('de', z=zs), linestyle='--', c='C2')
axs[0].set_xlim([1e1,1e5])
axs[0].set_ylim([1e-9,0.1])
axs[0].set_xlabel(r'$z$')
axs[0].set_ylabel(r'$\Omega_{\rm de}$')

axs[1].plot(cl_LCDM[2:,0], c='C0')
axs[1].plot(cl_PPF[2:,0], c='C1')
axs[1].plot(cl_PPFtabulated[2:,0], linestyle='--', c='C2')
axs[1].set_xlabel(r'$\ell$')
axs[1].set_ylabel(r'$D_l [\mu {\rm D}^2]$')
axs[1].legend(['$\Lambda$CDM','PPF','tabulated PPF'])
plt.show()
which outputs

Code: Select all

LCDM:                H0 =  67.42062819302447
PPF DE:              H0 =  59.92277075565107
tabulated PPF DE:    H0 =  59.9227705574317
set_w_a_table_IssueSolved.png
set_w_a_table_IssueSolved.png (57.09 KiB) Viewed 140 times
There remains a small difference in H0 between the two PPF models but it seems small enough that it could be a feature of how CAMB handles the two methods. Either way, it is good enough for me. Good job, team. Cheap drinks on me.

Post Reply