Skip to content

Commit 6156b63

Browse files
committed
cosmo: moved historical precision settings to tests. restored CLASS tests
1 parent 339c7e9 commit 6156b63

File tree

8 files changed

+74
-64
lines changed

8 files changed

+74
-64
lines changed

cobaya/cosmo_input/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
planck_base_model as planck_base_model,
3333
)
3434
from .input_database import (
35-
planck_lss_precision as planck_lss_precision,
35+
cmb_precision as cmb_precision,
3636
)
3737
from .input_database import (
38-
planck_precision as planck_precision,
38+
cmb_lss_precision as cmb_lss_precision,
3939
)

cobaya/cosmo_input/input_database.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -597,22 +597,22 @@
597597
}
598598

599599
# EXPERIMENTS ############################################################################
600+
601+
# Precision for calculations without perturbations
600602
base_precision: InfoDict = {
601-
"camb": None,
602-
"classy": {"non linear": "hmcode", "nonlinear_min_k_max": 20},
603+
"camb": {},
604+
"classy": {},
603605
}
604-
cmb_precision = deepcopy(base_precision)
605-
cmb_precision["camb"] = {"lens_potential_accuracy": 1}
606606

607-
planck_lss_precision = deepcopy(base_precision)
608-
planck_lss_precision["camb"] = {
609-
"halofit_version": "mead",
610-
"bbn_predictor": "PArthENoPE_880.2_standard.dat",
611-
}
612-
planck_lss_precision["classy"] = {"nonlinear_min_k_max": 25}
607+
# Precision for CMB analises
608+
cmb_precision = deepcopy(base_precision)
609+
cmb_precision["camb"].update({"lens_potential_accuracy": 1})
610+
cmb_precision["classy"].update({"non linear": "hmcode"})
613611

614-
planck_precision = deepcopy(planck_lss_precision)
615-
planck_precision["camb"]["lens_potential_accuracy"] = 1
612+
# Precision for combined CMB + LSS analyses (used for LSS-only too)
613+
cmb_lss_precision = deepcopy(cmb_precision)
614+
cmb_lss_precision["camb"].update({})
615+
cmb_lss_precision["classy"].update({"nonlinear_min_k_max": 20})
616616

617617
default_mcmc_options = {
618618
"proposal_scale": 1.9,
@@ -676,7 +676,7 @@
676676
"desc": "Planck 2018 (Polarized CMB + lensing)",
677677
"sampler": cmb_sampler_recommended,
678678
"theory": {
679-
theo: {"extra_args": planck_precision[theo]} for theo in ["camb", "classy"]
679+
theo: {"extra_args": cmb_precision[theo]} for theo in ["camb", "classy"]
680680
},
681681
"likelihood": {
682682
"planck_2018_lowl.TT": None,
@@ -689,7 +689,7 @@
689689
"desc": "Planck 2018 (Polarized CMB + lensing) + Bicep/Keck-Array 2018",
690690
"sampler": cmb_sampler_recommended,
691691
"theory": {
692-
theo: {"extra_args": planck_precision[theo]} for theo in ["camb", "classy"]
692+
theo: {"extra_args": cmb_precision[theo]} for theo in ["camb", "classy"]
693693
},
694694
"likelihood": {
695695
"planck_2018_lowl.TT": None,
@@ -703,7 +703,7 @@
703703
"desc": "Planck 2018 CMB-marginalized lensing only",
704704
"sampler": cmb_sampler_mcmc,
705705
"theory": {
706-
theo: {"extra_args": planck_precision[theo]} for theo in ["camb", "classy"]
706+
theo: {"extra_args": cmb_precision[theo]} for theo in ["camb", "classy"]
707707
},
708708
"likelihood": {"planck_2018_lensing.CMBMarged": None},
709709
},
@@ -817,7 +817,7 @@
817817
for key, value in like_des.items():
818818
if key is not none:
819819
value["theory"] = {
820-
theo: {"extra_args": base_precision[theo]} for theo in ["camb", "classy"]
820+
theo: {"extra_args": cmb_lss_precision[theo]} for theo in ["camb", "classy"]
821821
}
822822
value["sampler"] = cmb_sampler_recommended
823823

cobaya/likelihoods/base_classes/planck_clik.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class PlanckClik(Likelihood):
3636
clik_file: str
3737

3838
def initialize(self):
39+
# Disable JAX to avoid dependency issues
40+
os.environ["CLIPY_NOJAX"] = "1"
3941
msg_to_install = "run `cobaya-install planck_2018_highl_plik.TTTEEE`"
4042
try:
4143
install_path = (lambda p: self.get_code_path(p) if p else None)(
@@ -58,8 +60,6 @@ def initialize(self):
5860
self.log,
5961
f"{excpt}. To install a new version, {msg_to_install} with `--upgrade`.",
6062
) from excpt
61-
# Disable JAX to avoid dependency issues
62-
os.environ["CLIPY_NOJAX"] = "1"
6363
# Loading the likelihood data
6464
data_path = get_data_path(self.__class__.get_qualified_class_name())
6565
if not os.path.isabs(self.clik_file):

cobaya/theories/classy/classy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def set(self, params_values_dict):
638638
# (e.g. complaints if halofit requested but no Cl's computed.) ?????
639639
# Needed for facilitating post-processing
640640
if not self.extra_args["output"]:
641-
for k in ["non_linear"]:
641+
for k in ["non_linear", "hmcode_version"]:
642642
self.extra_args.pop(k, None)
643643
# Prepare parameters to be passed: this-iteration + extra
644644
args = {self.translate_param(p): v for p, v in params_values_dict.items()}

tests/test_cosmo_bicep_keck_2018.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22

33
from copy import deepcopy
44

5-
from cobaya.cosmo_input import planck_precision
6-
75
from .common_cosmo import body_of_test
8-
9-
camb_extra = deepcopy(planck_precision["camb"])
10-
camb_extra.update({"halofit_version": "takahashi"})
11-
classy_extra = deepcopy(planck_precision["classy"])
12-
classy_extra.update({"non linear": "halofit"})
13-
classy_extra.update({"nonlinear_min_k_max": 20})
6+
from .test_cosmo_planck_2018 import planck_2018_precision
147

158

169
def test_bicep_keck_2018_camb(packages_path, skip_not_installed):
17-
info_theory = {"camb": {"extra_args": camb_extra}}
10+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
1811
body_of_test(
1912
packages_path,
2013
test_point,
21-
lik_info,
14+
like_info,
2215
info_theory,
2316
chi2,
2417
extra_model={"primordial": "SFSR_t"},
@@ -27,22 +20,24 @@ def test_bicep_keck_2018_camb(packages_path, skip_not_installed):
2720

2821

2922
def test_bicep_keck_2018_classy(packages_path, skip_not_installed):
30-
info_theory = {"classy": {"extra_args": classy_extra}}
23+
info_theory = {"classy": {"extra_args": planck_2018_precision["classy"]}}
24+
chi2_classy = deepcopy(chi2)
25+
chi2_classy["tolerance"] += 0.35
3126
body_of_test(
3227
packages_path,
3328
test_point,
34-
lik_info,
29+
like_info,
3530
info_theory,
36-
chi2,
31+
chi2_classy,
3732
extra_model={"primordial": "SFSR_t"},
3833
skip_not_installed=skip_not_installed,
3934
)
4035

4136

42-
lik_info = {"bicep_keck_2018": {}}
37+
like_info = {"bicep_keck_2018": None}
4338

4439
# NB: chi2 obtained using CAMB w HMcode
45-
chi2 = {"bicep_keck_2018": 543.25, "tolerance": 0.16}
40+
chi2 = {"bicep_keck_2018": 543.25, "tolerance": 0.1}
4641

4742
test_point = {
4843
"omegabh2": 0.2235620e-01,

tests/test_cosmo_des_y1.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from copy import deepcopy
22
from types import MappingProxyType
33

4-
from cobaya.cosmo_input import planck_lss_precision
4+
from cobaya.cosmo_input import cmb_lss_precision
55

66
from .common_cosmo import body_of_test
7-
from .test_cosmo_quantities import params_lowTEB_highTTTEEE
7+
from .test_cosmo_quantities import params_lowTEB_highTTTEEE, lss_tests_precision
8+
from .test_cosmo_planck_2018 import planck_2018_precision
9+
10+
info_camb = MappingProxyType({"camb": {"extra_args": lss_tests_precision["camb"]}})
11+
info_classy = MappingProxyType({"classy": {"extra_args": lss_tests_precision["classy"]}})
812

913
best_fit = deepcopy(params_lowTEB_highTTTEEE)
10-
info_camb = MappingProxyType({"camb": {"extra_args": planck_lss_precision["camb"]}})
11-
info_classy = MappingProxyType({"classy": {"extra_args": planck_lss_precision["classy"]}})
12-
# Backport for getting reference test values
13-
info_classy["classy"]["extra_args"]["hmcode_version"] = 16
1414

1515

1616
def test_cosmo_des_y1_shear_camb(

tests/test_cosmo_planck_2018.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Tries to evaluate the likelihood at LCDM's best fit of Planck 2015, with CAMB and CLASS
22
from copy import deepcopy
33

4-
from cobaya.cosmo_input import planck_precision
4+
from cobaya.cosmo_input import cmb_precision
55

66
from .common_cosmo import body_of_test
77

@@ -31,8 +31,21 @@
3131
"Y_p",
3232
]
3333

34-
# Small chi2 difference with CLASS (total still <0.5)
35-
classy_extra_tolerance = 0.45
34+
# Setting some parameter to "historical" values to reproduce Planck results
35+
planck_2018_precision = deepcopy(cmb_precision)
36+
planck_2018_precision["camb"].update({
37+
"halofit_version": "mead2016",
38+
"bbn_predictor": "PArthENoPE_880.2_standard.dat",
39+
})
40+
planck_2018_precision["classy"].update({
41+
"non linear": "hmcode",
42+
"hmcode_version": "2016",
43+
"sBBN file": "sBBN_2017.dat",
44+
"want_lcmb_full_limber": "no", # When it's on, it changes by chi2 ~ 0.5
45+
})
46+
47+
# Small chi2 difference with CLASS (total still <0.35)
48+
classy_extra_tolerance = 0.25
3649

3750

3851
# STANDARD ###############################################################################
@@ -48,7 +61,7 @@ def test_planck_2018_t_camb(packages_path, skip_not_installed, clik=False):
4861
"planck_2018_lowl.TT"
4962
)
5063
chi2["planck_2018_lowl.TT_clik"] = chi2.pop("planck_2018_lowl.TT")
51-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
64+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
5265
best_fit_derived = derived_lowl_highTT_lensing
5366
body_of_test(
5467
packages_path,
@@ -75,7 +88,7 @@ def test_planck_2018_p_camb(packages_path, skip_not_installed, clik=False):
7588
"planck_2018_lowl.EE"
7689
)
7790
chi2["planck_2018_lowl.EE_clik"] = chi2.pop("planck_2018_lowl.EE")
78-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
91+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
7992
best_fit_derived = derived_lowTE_highTTTEEE_lensingcmblikes
8093
body_of_test(
8194
packages_path,
@@ -100,7 +113,7 @@ def test_planck_2018_t_lite_camb(packages_path, skip_not_installed, native=False
100113
best_fit.pop("H0")
101114
like_name = "planck_2018_highl_plik.TT_lite" + ("_native" if native else "")
102115
info_likelihood = {like_name: None}
103-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
116+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
104117
chi2 = {like_name: chi2_planck_2018_plikHM_highTT_lite, "tolerance": 0.01}
105118
body_of_test(
106119
packages_path,
@@ -123,7 +136,7 @@ def test_planck_2018_p_lite_camb(packages_path, skip_not_installed, native=False
123136
best_fit.pop("H0")
124137
like_name = "planck_2018_highl_plik.TTTEEE_lite" + ("_native" if native else "")
125138
info_likelihood = {like_name: None}
126-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
139+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
127140
chi2 = {like_name: chi2_planck_2018_plikHM_highTTTEEE_lite, "tolerance": 0.01}
128141
body_of_test(
129142
packages_path,
@@ -149,7 +162,7 @@ def test_planck_2018_t_unbinned_camb(packages_path, skip_not_installed):
149162
best_fit.pop("H0")
150163
like_name = "planck_2018_highl_plik.TT_unbinned"
151164
info_likelihood = {like_name: None}
152-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
165+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
153166
chi2 = {like_name: 8275.99, "tolerance": 0.03}
154167
body_of_test(
155168
packages_path,
@@ -166,7 +179,7 @@ def test_planck_2018_p_unbinned_camb(packages_path, skip_not_installed):
166179
best_fit.pop("H0")
167180
like_name = "planck_2018_highl_plik.TTTEEE_unbinned"
168181
info_likelihood = {like_name: None}
169-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
182+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
170183
chi2 = {like_name: 24125.92, "tolerance": 0.01}
171184
body_of_test(
172185
packages_path,
@@ -209,7 +222,7 @@ def test_planck_2018_t_CamSpec_camb(packages_path, skip_not_installed):
209222
"calEE": 1.0,
210223
}
211224
)
212-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
225+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
213226
body_of_test(
214227
packages_path,
215228
best_fit,
@@ -236,7 +249,7 @@ def test_planck_2018_t_CamSpec2021_camb(packages_path, skip_not_installed):
236249
"n_143x217": 0.96638,
237250
}
238251
)
239-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
252+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
240253
body_of_test(
241254
packages_path,
242255
best_fit,
@@ -275,7 +288,7 @@ def test_planck_2018_p_CamSpec_camb(packages_path, skip_not_installed):
275288
"calEE": 1.0,
276289
}
277290
)
278-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
291+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
279292
body_of_test(
280293
packages_path,
281294
best_fit,
@@ -304,7 +317,7 @@ def test_planck_2018_p_CamSpec2021_camb(packages_path, skip_not_installed):
304317
"calEE": 1.00124,
305318
}
306319
)
307-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
320+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
308321
body_of_test(
309322
packages_path,
310323
best_fit,
@@ -321,7 +334,7 @@ def test_planck_2018_p_CamSpec2021_camb(packages_path, skip_not_installed):
321334
def test_planck_2018_lcmbmarged_camb(packages_path, skip_not_installed):
322335
best_fit = params_lensing_cmbmarged
323336
info_likelihood = lik_info_lensing_cmbmarged.copy()
324-
info_theory = {"camb": {"extra_args": planck_precision["camb"]}}
337+
info_theory = {"camb": {"extra_args": planck_2018_precision["camb"]}}
325338
best_fit_derived = {}
326339
body_of_test(
327340
packages_path,
@@ -342,7 +355,7 @@ def test_planck_2018_t_classy(packages_path, skip_not_installed):
342355
best_fit.pop("theta_MC_100")
343356
best_fit = params_lowl_highTT_lensing
344357
info_likelihood = lik_info_lowl_highTT_lensing.copy()
345-
info_theory = {"classy": {"extra_args": planck_precision["classy"]}}
358+
info_theory = {"classy": {"extra_args": planck_2018_precision["classy"]}}
346359
best_fit_derived = deepcopy(derived_lowl_highTT_lensing)
347360
for p in classy_unknown:
348361
best_fit_derived.pop(p, None)
@@ -363,7 +376,7 @@ def test_planck_2018_p_classy(packages_path, skip_not_installed):
363376
best_fit = deepcopy(params_lowTE_highTTTEEE_lensingcmblikes)
364377
best_fit.pop("theta_MC_100")
365378
info_likelihood = lik_info_lowTE_highTTTEEE_lensingcmblikes.copy()
366-
info_theory = {"classy": {"extra_args": planck_precision["classy"]}}
379+
info_theory = {"classy": {"extra_args": planck_2018_precision["classy"]}}
367380
best_fit_derived = deepcopy(derived_lowTE_highTTTEEE_lensingcmblikes)
368381
for p in classy_unknown:
369382
best_fit_derived.pop(p, None)
@@ -468,7 +481,7 @@ def test_planck_2018_p_classy(packages_path, skip_not_installed):
468481
chi2_lowTE_highTTTEEE_lensingcmblikes = {
469482
"planck_2018_lowl.TT": 23.25,
470483
"planck_2018_lowl.EE": 396.05,
471-
"planck_2018_highl_plik.TTTEEE": 2345.01,
484+
"planck_2018_highl_plik.TTTEEE": 2344.93,
472485
"planck_2018_lensing.native": 8.87,
473486
"tolerance": 0.11,
474487
}

tests/test_cosmo_quantities.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
import numpy as np
88
import pytest
99

10-
from cobaya.cosmo_input import create_input, planck_base_model, planck_lss_precision
10+
from cobaya.cosmo_input import create_input, planck_base_model, cmb_lss_precision
1111
from cobaya.model import get_model
1212
from cobaya.tools import check_2d, recursive_update
1313

1414
from .common import process_packages_path
1515
from .conftest import install_test_wrapper
16+
from .test_cosmo_planck_2018 import planck_2018_precision
17+
18+
lss_tests_precision = deepcopy(cmb_lss_precision)
19+
lss_tests_precision["camb"].update(planck_2018_precision["camb"])
20+
lss_tests_precision["classy"].update(planck_2018_precision["classy"])
1621

1722
# Best fit Planck 2015 as test point
1823
params_lowTEB_highTTTEEE = {
@@ -87,7 +92,7 @@
8792
def _get_model_with_requirements_and_eval(theo, reqs, packages_path, skip_not_installed):
8893
planck_base_model_prime = deepcopy(planck_base_model)
8994
planck_base_model_prime["hubble"] = "H" # intercompatibility CAMB/CLASS
90-
info_theory = {theo: {"extra_args": planck_lss_precision[theo]}}
95+
info_theory = {theo: {"extra_args": lss_tests_precision[theo]}}
9196
info = create_input(planck_names=True, theory=theo, **planck_base_model_prime)
9297
info = recursive_update(info, {"theory": info_theory, "likelihood": {"one": None}})
9398
info["packages_path"] = process_packages_path(packages_path)
@@ -336,7 +341,6 @@ def test_cosmo_omega_camb(packages_path, skip_not_installed):
336341
_test_cosmo_omega("camb", packages_path, skip_not_installed)
337342

338343

339-
@pytest.mark.skip(reason="Failing in GitHub Actions; works locally")
340344
def test_cosmo_omega_classy(packages_path, skip_not_installed):
341345
_test_cosmo_omega("classy", packages_path, skip_not_installed)
342346

@@ -370,7 +374,6 @@ def test_cosmo_ang_diam_dist_2_camb(packages_path, skip_not_installed):
370374
_test_cosmo_ang_diam_dist_2("camb", packages_path, skip_not_installed)
371375

372376

373-
@pytest.mark.skip(reason="Failing in GitHub Actions; works locally")
374377
def test_cosmo_ang_diam_dist_2_classy(packages_path, skip_not_installed):
375378
_test_cosmo_ang_diam_dist_2("classy", packages_path, skip_not_installed)
376379

@@ -415,6 +418,5 @@ def test_cosmo_weyl_pkz_camb(packages_path, skip_not_installed):
415418
_test_cosmo_weyl_pkz("camb", packages_path, skip_not_installed)
416419

417420

418-
@pytest.mark.skip
419421
def test_cosmo_weyl_pkz_classy(packages_path, skip_not_installed):
420422
_test_cosmo_weyl_pkz("classy", packages_path, skip_not_installed)

0 commit comments

Comments
 (0)