CAMB icon indicating copy to clipboard operation
CAMB copied to clipboard

CAMB and CLASS disagree on lensing-polarization cross spectrum

Open hersle opened this issue 2 months ago • 7 comments

Hi!

I am unable to make CAMB and CLASS to agree on $C_l$ for lensing-polarization with default-ish precision parameters. Here is a script to reproduce my comparison (run in an empty directory, and modify class and camb to executable paths if not in $PATH):

echo '
output_root = camb
scalar_covariance_output_file = cl.dat
feedback_level = 1
get_scalar_cls = T
get_transfer = F
do_lensing = T
l_max_scalar = 2500
CMB_outputscale = 7.42835025e12

# recommended in inifiles/params.ini
k_eta_max_scalar = 10000
accuracy_boost = 2
l_accuracy_boost = 2

# same minimal model parameters as CLASS
hubble = 70.0
temp_cmb = 2.7
ombh2 = 0.02
omch2 = 0.12
omk = 0
massless_neutrinos = 0.0
omnuh2 = 0.0
massive_neutrinos = 0
scalar_amp = 2e-9
scalar_spectral_index = 1.0
helium_fraction = 0.25
reionization = F
recombination_model = Recfast
' > camb.ini

echo '
root = class
overwrite_root = yes
background_verbose = 2
output = tCl,pCl,lCl
format = camb

# same minimal model parameters as CAMB
H0 = 70.0
T_cmb = 2.7
omega_b = 0.02
omega_cdm = 0.12
omega_k = 0.0
N_ur = 0
N_ncdm = 0
A_s = 2e-9
n_s = 1.0
YHe = 0.25
reio_parametrization = reio_none
recombination = recfast
' > class.ini

echo "Running CLASS:"
class class.ini

echo -e "\nRunning CAMB:"
camb camb.ini

echo -e "\nPlotting CLASS vs CAMB to out.png:"
gnuplot -e "
	set terminal png size 1600, 800;
	set output 'out.png';
	set xlabel 'l';
	set ylabel 'Dₗ (lensing × polarization)';
	plot 'camb_cl.dat' using 1:9 with lines, 'class_cl.dat' using 1:8 with lines;
"
xdg-open out.png

Output:

Running CLASS:
Running CLASS version v3.2.3
Computing background
Chose ndf15 as generic_evolver
 -> age = 13.648033 Gyr
 -> conformal age = 14230.579653 Mpc
 -> N_eff = 0 (summed over all species that are non-relativistic at early times) 
 -> radiation/matter equality at z = 5877.103771
    corresponding to conformal time = 86.574974 Mpc
 ---------------------------- Budget equation ----------------------- 
 ---> Nonrelativistic Species 
-> Bayrons                        Omega = 0.0408163       , omega = 0.02           
-> Cold Dark Matter               Omega = 0.244898        , omega = 0.12           
 ---> Relativistic Species 
-> Photons                        Omega = 4.86065e-05     , omega = 2.38172e-05    
 ---> Other Content 
-> Cosmological Constant          Omega = 0.714237        , omega = 0.349976       
 ---> Total budgets 
 Radiation                        Omega = 4.86065e-05     , omega = 2.38172e-05     
 Non-relativistic                 Omega = 0.285714        , omega = 0.14            
 Other Content                    Omega = 0.714237        , omega = 0.349976        
 TOTAL                            Omega = 1               , omega = 0.49            
 -------------------------------------------------------------------- 

Running CAMB:
Om_b h^2             =  0.020000
Om_c h^2             =  0.120000
Om_nu h^2            =  0.000000
Om_darkenergy        =  0.714237
Om_K                 =  0.000000
Om_m (inc Om_u)      =  0.285714
100 theta (CosmoMC)  =  1.195719
Age of universe/GYr  =  13.648
zstar                =  1101.75
r_s(zstar)/Mpc       =  165.07
100*theta            =  1.186388
DA(zstar)/Gpc        =  13.91371
zdrag                =  1064.92
r_s(zdrag)/Mpc       =  168.56
k_D(zstar) Mpc       =  0.1307
100*theta_D          =  0.172743
z_EQ (if v_nu=1)     =  5877.11
k_EQ Mpc (if v_nu=1) =  0.013532
100*theta_EQ         =  0.622227
100*theta_rs_EQ      =  0.350612
tau_recomb/Mpc       =  317.21  tau_now/Mpc =  14230.6

Plotting CLASS vs CAMB to out.png:
Image

Do you know the reason for this disagreement and/or how it can be resolved? Thank you!

hersle avatar Oct 27 '25 15:10 hersle

Also cross-posted in https://github.com/lesgourg/class_public/issues/645.

hersle avatar Oct 27 '25 15:10 hersle

No, but are they both numerically stable to increasing accuracy? Would have thought should be negligibly small without reionization, what's the cross-correlation coeff?

cmbant avatar Oct 27 '25 16:10 cmbant

Thanks for the reply! I disabled reionization in both codes just to keep the comparison minimal. If I change CAMB to use

reionization = T
re_use_optical_depth = T
re_optical_depth = 0.09

and similarly CLASS to use

reio_parametrization = reio_camb
tau_reio = 0.09

then I get similar disagreement, only with somewhat crazier features close to $l \approx 0$:

Image

Apologies for my ignorance: what exactly do you mean by

what's the cross-correlation coeff?

I will check convergence with precision parameters!

hersle avatar Oct 27 '25 21:10 hersle

Disabling the Limber approximation makes a difference (I find it a little ambiguous whether CAMB/CLASS uses the Limber approximation for lensing-polarization in addition to lensing-lensing), but does not resolve the problem:

echo '
output_root = camb
scalar_covariance_output_file = cl.dat
feedback_level = 1
get_scalar_cls = T
get_transfer = F
do_lensing = T
l_max_scalar = 2500
CMB_outputscale = 7.42835025e12

# recommended in inifiles/params.ini
accuracy_boost = 2
l_accuracy_boost = 2

# same minimal model parameters as CLASS
hubble = 70.0
temp_cmb = 2.7
ombh2 = 0.02
omch2 = 0.12
omk = 0
massless_neutrinos = 0.0
omnuh2 = 0.0
massive_neutrinos = 0
scalar_amp = 2e-9
scalar_spectral_index = 1.0
helium_fraction = 0.25
reionization = F
recombination_model = Recfast

# disable Limber approximation and sample high k
l_limber_phiphi = 10000
k_eta_max_scalar = 10000
' > camb.ini

echo '
root = class
overwrite_root = yes
background_verbose = 2
output = tCl,pCl,lCl
format = camb

# same minimal model parameters as CAMB
H0 = 70.0
T_cmb = 2.7
omega_b = 0.02
omega_cdm = 0.12
omega_k = 0.0
N_ur = 0
N_ncdm = 0
A_s = 2e-9
n_s = 1.0
YHe = 0.25
reio_parametrization = reio_none
recombination = recfast

# disable Limber approximation and sample high k
l_switch_limber = 10000
k_max_tau0_over_l_max = 4
' > class.ini

echo "Running CLASS:"
class class.ini

echo -e "\nRunning CAMB:"
camb camb.ini

echo -e "\nPlotting CLASS vs CAMB to out.png:"
gnuplot -e "
	set terminal png size 1600, 800;
	set output 'out.png';
	set xlabel 'l';
	set ylabel 'Dₗ (lensing × polarization)';
	plot 'camb_cl.dat' using 1:9 with lines, 'class_cl.dat' using 1:8 with lines;
"
xdg-open out.png
Image

But now the problem is somewhat switched around, with agreement for $l \lesssim 700$ and disagreement for $l \gtrsim 700$.

hersle avatar Oct 27 '25 21:10 hersle

I think the correlation coefficient here is tiny, i.e. |E-phi/sqrt(EE*phiphi)|<<1 - so negligible in practice (and hence likely dominated by numerical error).

cmbant avatar Oct 27 '25 21:10 cmbant

I think the correlation coefficient here is tiny, i.e. |phi-phi/sqrt(EE*phiphi)|<<1 - so negligible in practice (and hence likely dominated by numerical error).

Hmm ok, I see. But if numerical error is the cause, should we not see a more "random"/noisy pattern with $l$?

I also find it suspicious that the error pattern changes when switching off the Limber approximation (see post above).

Starting from the original example, I tried to use the high l_sample_boost = 8 in CAMB (making a kink around $l \approx 500$):

Image

I also tried to increase $l_\text{max}$ in the perturbations by setting l_accuracy_boost = 8 in CAMB and l_max_g = 80 and l_max_pol_g = 80 in CLASS (no big effect):

Image

hersle avatar Oct 28 '25 10:10 hersle

Numerical error will not necessarily be random, e.g. to switch-off times etc. varying with accuracy parameters. I would plot C^E\phi/sqrt(C^EE*C^phiphi) to see how negligible the errors are in practice except at very low L < 15 if you turn reionization on (https://arxiv.org/abs/1101.2234).

cmbant avatar Nov 07 '25 14:11 cmbant