From 356b4206eb4a0f7fe1e1daf8e2504cd59912c9a1 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 18 Oct 2023 14:43:30 +0100 Subject: [PATCH 01/19] add npipe --- examples/planck-npipe-values.ini | 31 +++++++++ examples/planck-npipe.ini | 49 +++++++++++++++ likelihood/planck-npipe/npipe_interface.py | 73 ++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 examples/planck-npipe-values.ini create mode 100644 examples/planck-npipe.ini create mode 100644 likelihood/planck-npipe/npipe_interface.py diff --git a/examples/planck-npipe-values.ini b/examples/planck-npipe-values.ini new file mode 100644 index 00000000..60f75aef --- /dev/null +++ b/examples/planck-npipe-values.ini @@ -0,0 +1,31 @@ +[cosmological_parameters] +cosmomc_theta = 1.040909 ; this is actually 100 * theta_mc +omega_k = 0.0 ;spatial curvature +ombh2 = 0.022383 +omch2 = 0.12011 + +;neutrinos +mnu = 0.06 +nnu = 3.046 +num_massive_neutrinos = 1 + +;helium +yhe = 0.245341 ;helium mass fraction + +;reionization +tau = 0.0543 ;reionization optical depth + +;inflation Parameters +n_s = 0.96605 ;scalar spectral index +log1e10As = 3.0448 ; structure amplitude parameter +k_s = 0.05 ;Power spectrum pivot scale +n_run = 0.0 ;running of scalar spectrum +r_t = 0.0 ;tensor to scalar ratio +n_t = 0.0 ;tensor spectral index + +;dark energy equation of state +w = -1.0 ;equation of state of dark energy +wa = 0.0 ;equation of state of dark energy (redshift dependency) + +[planck] +a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini new file mode 100644 index 00000000..57b8146b --- /dev/null +++ b/examples/planck-npipe.ini @@ -0,0 +1,49 @@ +[runtime] +sampler = test +root = ${PWD} +verbosity = standard + +[test] +save_dir=output/planck +fatal_errors=T + + +[DEFAULT] +; This value is used below as %(planck_path)s +planck_path = likelihood/planck2018/baseline/plc_3.0 + + +[pipeline] +; these names refer to sections later in the file: +modules = consistency camb planck_npipe +values = examples/planck_values.ini +priors = examples/planck_priors.ini +debug=T +timing=F + + +[planck_npipe] +;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) +;without CMB lensing +file = likelihood/planck-npipe/npipe_interface.py +mode = tt + +; The consistency module translates between our chosen parameterization +; and any other that modules in the pipeline may want (e.g. camb) +[consistency] +file = ./utility/consistency/consistency_interface.py +cosmomc_theta = T + + +[camb] +file = boltzmann/camb/camb_interface.py +mode = cmb +lmax = 2800 ;max ell to use for cmb calculation +feedback=1 ;amount of output to print +AccuracyBoost=1.1 ;CAMB accuracy boost parameter +do_tensors = True ;include tensor modes +do_lensing = true ;lensing is required w/ Planck data +NonLinear = lens +accurate_massive_neutrino_transfers = T +theta_H0_range = "20 100" + diff --git a/likelihood/planck-npipe/npipe_interface.py b/likelihood/planck-npipe/npipe_interface.py new file mode 100644 index 00000000..ff6bcf8d --- /dev/null +++ b/likelihood/planck-npipe/npipe_interface.py @@ -0,0 +1,73 @@ +from cosmosis.datablock import option_section +try: + from planckpr4lensing.iswlens_jtliks.lik import cobaya_jtlik +except ImportError: + raise ImportError("Please install the planckpr4lensing with: pip install git+https://github.com/carronj/planck_PR4_lensing") +import numpy as np + + +def setup(options): + mode = options[option_section, "mode"] + mode_choices = [ + 'pp', + 'pt', + 'pt_pp', + 'tt', + 'tt_pp', + 'tt_pp_mtt', + 'tt_pt', + 'tt_pt_mtt', + 'tt_pt_pp', + 'tt_pt_pp_mpp', + 'tt_pt_pp_mtt', + 'tt_pt_pp_mtt_mpp'] + s = ", ".join(mode_choices) + if mode not in mode_choices: + raise ValueError(f"Mode parameter in npipe must be one of: {s}, not {mode}") + calculator = cobaya_jtlik() + calculator.initialize() + chi2_method = getattr(calculator, f'get_chi2_{mode}') + return calculator, chi2_method, mode + + + +def execute(block, config): + calculator, chi2_method, mode = config + + c_ells = {} + ell = block['cmb_cl', 'ell'] + A = block['planck', 'a_planck'] + + # Not sure if pt currently calculated in camb module - need to check. might be. + # be careful with normalizations. + c_ells['tt'] = block['cmb_cl', 'tt'] + if 'pp' in mode: + c_ells['pp'] = block['cmb_cl', 'pp'] + if 'pt' in mode: + c_ells['pt'] = block['cmb_cl', 'pt'] + if 'tt_pt' in mode: + c_ells['ee'] = block['cmb_cl', 'ee'] + c_ells['te'] = block['cmb_cl', 'te'] + + # npipe wants to start at zero. + if ell[0] == 2: + ell = np.concatenate([[0, 1], ell]) + for name, c_ell in c_ells.items(): + c_ells[name] = np.concatenate([[0.0, 0.0], c_ell]) + + # Convert from D_ell to C_ell + factor = ell * (ell + 1) / 2 / np.pi + # avoid divide-by-zero + factor[:2] = 1 + + # Scale by calibration parameter as in this line: + factor *= A**2 + + for cl in c_ells.values(): + cl /= factor + + # Compute and save likelihood + like = chi2_method(c_ells) + block['likelihoods', 'npipe_like'] = -like / 2 + + return 0 From 35c516e9a8f8ddc2c5b53d1021882b193b9f3312 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Fri, 21 Jun 2024 14:57:54 +0100 Subject: [PATCH 02/19] added npipe priors to match paper lensing-only one --- examples/npipe-priors.ini | 7 +++++ ...anck-npipe-values.ini => npipe-values.ini} | 27 ++++++++++++------- examples/planck-npipe.ini | 17 +++++++++--- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 examples/npipe-priors.ini rename examples/{planck-npipe-values.ini => npipe-values.ini} (68%) diff --git a/examples/npipe-priors.ini b/examples/npipe-priors.ini new file mode 100644 index 00000000..b9a2e993 --- /dev/null +++ b/examples/npipe-priors.ini @@ -0,0 +1,7 @@ +[cosmological_parameters] +n_s = gaussian 0.96 0.02 +ombh2 = gaussian 0.0222 0.0005 + + +[planck] +a_planck = gaussian 1.0 0.0025 \ No newline at end of file diff --git a/examples/planck-npipe-values.ini b/examples/npipe-values.ini similarity index 68% rename from examples/planck-npipe-values.ini rename to examples/npipe-values.ini index 60f75aef..a3d3e40f 100644 --- a/examples/planck-npipe-values.ini +++ b/examples/npipe-values.ini @@ -1,8 +1,22 @@ +[planck] +a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels + + [cosmological_parameters] -cosmomc_theta = 1.040909 ; this is actually 100 * theta_mc +; cosmomc_theta = 1.0 1.040909 1.08 ; this is actually 100 * theta_mc +h0 = 0.4 0.7 1.0 +omch2 = 0.05 0.12 0.2 +log1e10As = 2.9 3.0448 3.1 ; structure amplitude parameter + +ombh2 = 0.020 0.0222 0.025 +n_s = 0.9 0.96 1.02 + + omega_k = 0.0 ;spatial curvature -ombh2 = 0.022383 -omch2 = 0.12011 + +;reionization +tau = 0.055 ;reionization optical depth + ;neutrinos mnu = 0.06 @@ -12,12 +26,7 @@ num_massive_neutrinos = 1 ;helium yhe = 0.245341 ;helium mass fraction -;reionization -tau = 0.0543 ;reionization optical depth -;inflation Parameters -n_s = 0.96605 ;scalar spectral index -log1e10As = 3.0448 ; structure amplitude parameter k_s = 0.05 ;Power spectrum pivot scale n_run = 0.0 ;running of scalar spectrum r_t = 0.0 ;tensor to scalar ratio @@ -27,5 +36,3 @@ n_t = 0.0 ;tensor spectral index w = -1.0 ;equation of state of dark energy wa = 0.0 ;equation of state of dark energy (redshift dependency) -[planck] -a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini index 57b8146b..06cc352e 100644 --- a/examples/planck-npipe.ini +++ b/examples/planck-npipe.ini @@ -1,13 +1,22 @@ [runtime] -sampler = test +sampler = nautilus root = ${PWD} verbosity = standard +[nautilus] +n_live = 1000 +verbose = T + + + [test] save_dir=output/planck fatal_errors=T +[output] +filename = output/npipe.txt + [DEFAULT] ; This value is used below as %(planck_path)s planck_path = likelihood/planck2018/baseline/plc_3.0 @@ -16,8 +25,8 @@ planck_path = likelihood/planck2018/baseline/plc_3.0 [pipeline] ; these names refer to sections later in the file: modules = consistency camb planck_npipe -values = examples/planck_values.ini -priors = examples/planck_priors.ini +values = examples/npipe-values.ini +priors = examples/npipe-priors.ini debug=T timing=F @@ -39,7 +48,7 @@ cosmomc_theta = T file = boltzmann/camb/camb_interface.py mode = cmb lmax = 2800 ;max ell to use for cmb calculation -feedback=1 ;amount of output to print +feedback=0 ;amount of output to print AccuracyBoost=1.1 ;CAMB accuracy boost parameter do_tensors = True ;include tensor modes do_lensing = true ;lensing is required w/ Planck data From fbcf79c7d4dbb7596b5c3210f9c51a27ab7f52b5 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Mon, 24 Jun 2024 10:53:42 +0100 Subject: [PATCH 03/19] change tt to pp in npipe example --- examples/planck-npipe.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini index 06cc352e..248564ae 100644 --- a/examples/planck-npipe.ini +++ b/examples/planck-npipe.ini @@ -35,7 +35,7 @@ timing=F ;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) ;without CMB lensing file = likelihood/planck-npipe/npipe_interface.py -mode = tt +mode = pp ; The consistency module translates between our chosen parameterization ; and any other that modules in the pipeline may want (e.g. camb) From 11d79901f34d7864149e6adb1ed701fdae8e047a Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Mon, 24 Jun 2024 10:54:44 +0100 Subject: [PATCH 04/19] save derived params --- examples/planck-npipe.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini index 06cc352e..35acbf29 100644 --- a/examples/planck-npipe.ini +++ b/examples/planck-npipe.ini @@ -29,7 +29,7 @@ values = examples/npipe-values.ini priors = examples/npipe-priors.ini debug=T timing=F - +extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m [planck_npipe] ;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) From 75ffd3179028297938abece27cb32b92dd27a72d Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Mon, 24 Jun 2024 11:34:10 +0100 Subject: [PATCH 05/19] require numpy<2 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 416d4a26..228e0da0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,7 @@ jobs: - name: Install dependencies with conda shell: bash -l {0} - run: mamba install -c conda-forge "cosmosis>=3.2" cosmosis-build-standard-library pytest + run: mamba install -c conda-forge "cosmosis>=3.2" cosmosis-build-standard-library pytest "numpy<2" - name: Get Cached Planck uses: actions/cache/restore@v3 @@ -230,7 +230,7 @@ jobs: - name: Install python dependencies run: | python -m pip install --upgrade pip wheel setuptools - pip install "cosmosis>=3.2" "nautilus-sampler==0.6.*" + pip install "cosmosis>=3.2" "nautilus-sampler==0.6.*" "numpy<2" pip install -v --no-cache-dir --no-binary=mpi4py,camb mpi4py camb pip install fitsio astropy fast-pt "Cython<3.0" jupyter From effced5556ed3cd8edb5156676f5ec7d82aed648 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Tue, 25 Jun 2024 12:57:08 +0100 Subject: [PATCH 06/19] try old planck lensing --- examples/planck-npipe.ini | 2 +- examples/planck.ini | 8 ++++---- examples/planck_values.ini | 27 +++++++++++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini index 805d783e..45fdb142 100644 --- a/examples/planck-npipe.ini +++ b/examples/planck-npipe.ini @@ -10,7 +10,7 @@ verbose = T [test] -save_dir=output/planck +save_dir=output/npipe fatal_errors=T diff --git a/examples/planck.ini b/examples/planck.ini index e20e5adb..4a86d083 100644 --- a/examples/planck.ini +++ b/examples/planck.ini @@ -26,10 +26,10 @@ timing=F ;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) ;without CMB lensing file = likelihood/planck2018/planck_interface.so -data_1 = %(planck_path)s/hi_l/plik_lite/plik_lite_v22_TTTEEE.clik -data_2 = %(planck_path)s/low_l/commander/commander_dx12_v3_2_29.clik -data_3 = %(planck_path)s/low_l/simall/simall_100x143_offlike5_EE_Aplanck_B.clik - +; data_1 = %(planck_path)s/hi_l/plik_lite/plik_lite_v22_TTTEEE.clik +; data_2 = %(planck_path)s/low_l/commander/commander_dx12_v3_2_29.clik +; data_3 = %(planck_path)s/low_l/simall/simall_100x143_offlike5_EE_Aplanck_B.clik +lensing_1 = %(planck_path)s/lensing/smicadx12_Dec5_ftl_mv2_ndclpp_p_teb_consext8_CMBmarged.clik_lensing ; The consistency module translates between our chosen parameterization ; and any other that modules in the pipeline may want (e.g. camb) diff --git a/examples/planck_values.ini b/examples/planck_values.ini index 60f75aef..a3d3e40f 100644 --- a/examples/planck_values.ini +++ b/examples/planck_values.ini @@ -1,8 +1,22 @@ +[planck] +a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels + + [cosmological_parameters] -cosmomc_theta = 1.040909 ; this is actually 100 * theta_mc +; cosmomc_theta = 1.0 1.040909 1.08 ; this is actually 100 * theta_mc +h0 = 0.4 0.7 1.0 +omch2 = 0.05 0.12 0.2 +log1e10As = 2.9 3.0448 3.1 ; structure amplitude parameter + +ombh2 = 0.020 0.0222 0.025 +n_s = 0.9 0.96 1.02 + + omega_k = 0.0 ;spatial curvature -ombh2 = 0.022383 -omch2 = 0.12011 + +;reionization +tau = 0.055 ;reionization optical depth + ;neutrinos mnu = 0.06 @@ -12,12 +26,7 @@ num_massive_neutrinos = 1 ;helium yhe = 0.245341 ;helium mass fraction -;reionization -tau = 0.0543 ;reionization optical depth -;inflation Parameters -n_s = 0.96605 ;scalar spectral index -log1e10As = 3.0448 ; structure amplitude parameter k_s = 0.05 ;Power spectrum pivot scale n_run = 0.0 ;running of scalar spectrum r_t = 0.0 ;tensor to scalar ratio @@ -27,5 +36,3 @@ n_t = 0.0 ;tensor spectral index w = -1.0 ;equation of state of dark energy wa = 0.0 ;equation of state of dark energy (redshift dependency) -[planck] -a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels From f64462530db96e88128f364ae5a88341a00a3dc8 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Tue, 25 Jun 2024 13:00:15 +0100 Subject: [PATCH 07/19] try old planck lensing --- examples/planck.ini | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/planck.ini b/examples/planck.ini index 4a86d083..fa866c82 100644 --- a/examples/planck.ini +++ b/examples/planck.ini @@ -8,6 +8,11 @@ save_dir=output/planck fatal_errors=T +[nautilus] +n_live = 1000 +verbose = T + + [DEFAULT] ; This value is used below as %(planck_path)s planck_path = likelihood/planck2018/baseline/plc_3.0 From 2d83f481cef1747e7586f1c9e8ef22105c70d1cf Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Tue, 25 Jun 2024 13:00:41 +0100 Subject: [PATCH 08/19] try old planck lensing --- examples/planck.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/planck.ini b/examples/planck.ini index fa866c82..b3f228a2 100644 --- a/examples/planck.ini +++ b/examples/planck.ini @@ -25,6 +25,7 @@ values = examples/planck_values.ini priors = examples/planck_priors.ini debug=T timing=F +extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m [planck] From 80a7bba605b095fc25810caf2ddce10b0f9735bb Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Tue, 25 Jun 2024 13:02:31 +0100 Subject: [PATCH 09/19] match priors --- examples/planck.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/planck.ini b/examples/planck.ini index b3f228a2..70862220 100644 --- a/examples/planck.ini +++ b/examples/planck.ini @@ -22,7 +22,7 @@ planck_path = likelihood/planck2018/baseline/plc_3.0 ; these names refer to sections later in the file: modules = consistency camb planck values = examples/planck_values.ini -priors = examples/planck_priors.ini +priors = examples/npipe-priors.ini debug=T timing=F extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m From 40e520baa5642943724a94d575355aaeec942241 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 26 Jun 2024 11:21:57 +0100 Subject: [PATCH 10/19] return_all mode --- likelihood/planck-npipe/npipe_interface.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/likelihood/planck-npipe/npipe_interface.py b/likelihood/planck-npipe/npipe_interface.py index ff6bcf8d..de87e01f 100644 --- a/likelihood/planck-npipe/npipe_interface.py +++ b/likelihood/planck-npipe/npipe_interface.py @@ -24,15 +24,16 @@ def setup(options): s = ", ".join(mode_choices) if mode not in mode_choices: raise ValueError(f"Mode parameter in npipe must be one of: {s}, not {mode}") + return_all = ("mpp" not in mode) and ("mtt" not in mode) calculator = cobaya_jtlik() calculator.initialize() chi2_method = getattr(calculator, f'get_chi2_{mode}') - return calculator, chi2_method, mode + return calculator, chi2_method, mode, return_all def execute(block, config): - calculator, chi2_method, mode = config + calculator, chi2_method, mode, return_all = config c_ells = {} ell = block['cmb_cl', 'ell'] @@ -67,7 +68,12 @@ def execute(block, config): cl /= factor # Compute and save likelihood - like = chi2_method(c_ells) - block['likelihoods', 'npipe_like'] = -like / 2 + chi2 = chi2_method(c_ells, return_all=return_all) + if return_all: + like, info = like + block["data_vector", "npipe_theory"] = info['pred'] + block["data_vector", "npipe_data"] = info['meas'] + block["data_vector", "npipe_inv_cov"] = info['inv_cov'] + block['likelihoods', 'npipe_like'] = - 0.5 * chi2 return 0 From f5e102c69a42846afeff31e5f40c358b7c69e66d Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 26 Jun 2024 16:42:25 +0100 Subject: [PATCH 11/19] match planck range on log1e10As --- examples/planck_values.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/planck_values.ini b/examples/planck_values.ini index a3d3e40f..32a9660d 100644 --- a/examples/planck_values.ini +++ b/examples/planck_values.ini @@ -6,7 +6,7 @@ a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at ma ; cosmomc_theta = 1.0 1.040909 1.08 ; this is actually 100 * theta_mc h0 = 0.4 0.7 1.0 omch2 = 0.05 0.12 0.2 -log1e10As = 2.9 3.0448 3.1 ; structure amplitude parameter +log1e10As = 1.91 3.0448 3.61 ; structure amplitude parameter ombh2 = 0.020 0.0222 0.025 n_s = 0.9 0.96 1.02 From 8b60c3cdfdca19e26607f3fed1bdc64da2538660 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 26 Jun 2024 16:43:02 +0100 Subject: [PATCH 12/19] Revert "return_all mode" This reverts commit 40e520baa5642943724a94d575355aaeec942241. --- likelihood/planck-npipe/npipe_interface.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/likelihood/planck-npipe/npipe_interface.py b/likelihood/planck-npipe/npipe_interface.py index de87e01f..ff6bcf8d 100644 --- a/likelihood/planck-npipe/npipe_interface.py +++ b/likelihood/planck-npipe/npipe_interface.py @@ -24,16 +24,15 @@ def setup(options): s = ", ".join(mode_choices) if mode not in mode_choices: raise ValueError(f"Mode parameter in npipe must be one of: {s}, not {mode}") - return_all = ("mpp" not in mode) and ("mtt" not in mode) calculator = cobaya_jtlik() calculator.initialize() chi2_method = getattr(calculator, f'get_chi2_{mode}') - return calculator, chi2_method, mode, return_all + return calculator, chi2_method, mode def execute(block, config): - calculator, chi2_method, mode, return_all = config + calculator, chi2_method, mode = config c_ells = {} ell = block['cmb_cl', 'ell'] @@ -68,12 +67,7 @@ def execute(block, config): cl /= factor # Compute and save likelihood - chi2 = chi2_method(c_ells, return_all=return_all) - if return_all: - like, info = like - block["data_vector", "npipe_theory"] = info['pred'] - block["data_vector", "npipe_data"] = info['meas'] - block["data_vector", "npipe_inv_cov"] = info['inv_cov'] - block['likelihoods', 'npipe_like'] = - 0.5 * chi2 + like = chi2_method(c_ells) + block['likelihoods', 'npipe_like'] = -like / 2 return 0 From 1c7b316df8e000378cc867686eba50d5a2529cfb Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 3 Jul 2024 14:16:14 +0100 Subject: [PATCH 13/19] Entirely new npipe interface using hopefully correct classes --- examples/npipe-values.ini | 4 ++ examples/planck-npipe.ini | 7 +- likelihood/planck-npipe/npipe_interface.py | 76 +++++++--------------- 3 files changed, 33 insertions(+), 54 deletions(-) diff --git a/examples/npipe-values.ini b/examples/npipe-values.ini index a3d3e40f..67fec3c1 100644 --- a/examples/npipe-values.ini +++ b/examples/npipe-values.ini @@ -36,3 +36,7 @@ n_t = 0.0 ;tensor spectral index w = -1.0 ;equation of state of dark energy wa = 0.0 ;equation of state of dark energy (redshift dependency) + +[halo_model_parameters] +A = 3.13 +eta = 0.603 \ No newline at end of file diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini index 45fdb142..df157b37 100644 --- a/examples/planck-npipe.ini +++ b/examples/planck-npipe.ini @@ -1,5 +1,5 @@ [runtime] -sampler = nautilus +sampler = test root = ${PWD} verbosity = standard @@ -35,7 +35,7 @@ extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m ;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) ;without CMB lensing file = likelihood/planck-npipe/npipe_interface.py -mode = pp +use_marginalized = T ; The consistency module translates between our chosen parameterization ; and any other that modules in the pipeline may want (e.g. camb) @@ -54,5 +54,6 @@ do_tensors = True ;include tensor modes do_lensing = true ;lensing is required w/ Planck data NonLinear = lens accurate_massive_neutrino_transfers = T -theta_H0_range = "20 100" +theta_H0_range = "40 100" +halofit_version = mead diff --git a/likelihood/planck-npipe/npipe_interface.py b/likelihood/planck-npipe/npipe_interface.py index ff6bcf8d..e4f038f7 100644 --- a/likelihood/planck-npipe/npipe_interface.py +++ b/likelihood/planck-npipe/npipe_interface.py @@ -1,73 +1,47 @@ from cosmosis.datablock import option_section try: - from planckpr4lensing.iswlens_jtliks.lik import cobaya_jtlik + from planckpr4lensing import PlanckPR4LensingMarged, PlanckPR4Lensing except ImportError: raise ImportError("Please install the planckpr4lensing with: pip install git+https://github.com/carronj/planck_PR4_lensing") import numpy as np + def setup(options): - mode = options[option_section, "mode"] - mode_choices = [ - 'pp', - 'pt', - 'pt_pp', - 'tt', - 'tt_pp', - 'tt_pp_mtt', - 'tt_pt', - 'tt_pt_mtt', - 'tt_pt_pp', - 'tt_pt_pp_mpp', - 'tt_pt_pp_mtt', - 'tt_pt_pp_mtt_mpp'] - s = ", ".join(mode_choices) - if mode not in mode_choices: - raise ValueError(f"Mode parameter in npipe must be one of: {s}, not {mode}") - calculator = cobaya_jtlik() - calculator.initialize() - chi2_method = getattr(calculator, f'get_chi2_{mode}') - return calculator, chi2_method, mode + marged = options.get_bool(option_section, "use_marginalized", default=True) + if marged: + calculator = PlanckPR4LensingMarged() + else: + calculator = PlanckPR4Lensing() + return calculator, marged def execute(block, config): - calculator, chi2_method, mode = config - - c_ells = {} + calculator, marged = config ell = block['cmb_cl', 'ell'] A = block['planck', 'a_planck'] - # Not sure if pt currently calculated in camb module - need to check. might be. - # be careful with normalizations. - c_ells['tt'] = block['cmb_cl', 'tt'] - if 'pp' in mode: - c_ells['pp'] = block['cmb_cl', 'pp'] - if 'pt' in mode: - c_ells['pt'] = block['cmb_cl', 'pt'] - if 'tt_pt' in mode: - c_ells['ee'] = block['cmb_cl', 'ee'] - c_ells['te'] = block['cmb_cl', 'te'] + # Convert from D_ell to the PP pre-factor, ell**2 (ell+1)**2 / 2pi + pp = block['cmb_cl', 'pp'] * ell * (ell + 1.) + cl = {"pp":pp} - # npipe wants to start at zero. - if ell[0] == 2: - ell = np.concatenate([[0, 1], ell]) - for name, c_ell in c_ells.items(): - c_ells[name] = np.concatenate([[0.0, 0.0], c_ell]) + # If we are not using the marginalized version, we need to provide the full set of Cls + # If we are using the marginalized version these are pre-marginalized over + if not marged: + cl["tt"] = block['cmb_cl', 'tt'] + cl["te"] = block['cmb_cl', 'te'] + cl["ee"] = block['cmb_cl', 'ee'] + cl["bb"] = block['cmb_cl', 'bb'] - # Convert from D_ell to C_ell - factor = ell * (ell + 1) / 2 / np.pi - # avoid divide-by-zero - factor[:2] = 1 - # Scale by calibration parameter as in this line: - factor *= A**2 + # npipe wants to start at zero + if ell[0] == 2: + ell = np.concatenate([[0, 1], ell]) + for key in cl: + cl[key] = np.concatenate([[0.0, 0.0], cl[key]]) - for cl in c_ells.values(): - cl /= factor + block["likelihoods", "npipe_like"] = calculator.log_likelihood(cl, A_planck=A) - # Compute and save likelihood - like = chi2_method(c_ells) - block['likelihoods', 'npipe_like'] = -like / 2 return 0 From 6100173ce926cd8a57abff3b20fe0cc53382e15b Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Wed, 3 Jul 2024 14:21:52 +0100 Subject: [PATCH 14/19] switch to sampling in theta and report which likelihood is used --- examples/npipe-values.ini | 4 ++-- likelihood/planck-npipe/npipe_interface.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/npipe-values.ini b/examples/npipe-values.ini index 67fec3c1..6778479f 100644 --- a/examples/npipe-values.ini +++ b/examples/npipe-values.ini @@ -3,8 +3,8 @@ a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at ma [cosmological_parameters] -; cosmomc_theta = 1.0 1.040909 1.08 ; this is actually 100 * theta_mc -h0 = 0.4 0.7 1.0 + cosmomc_theta = 0.9 1.040909 1.2 ; this is actually 100 * theta_mc +;h0 = 0.4 0.7 1.0 omch2 = 0.05 0.12 0.2 log1e10As = 2.9 3.0448 3.1 ; structure amplitude parameter diff --git a/likelihood/planck-npipe/npipe_interface.py b/likelihood/planck-npipe/npipe_interface.py index e4f038f7..03719046 100644 --- a/likelihood/planck-npipe/npipe_interface.py +++ b/likelihood/planck-npipe/npipe_interface.py @@ -11,8 +11,10 @@ def setup(options): marged = options.get_bool(option_section, "use_marginalized", default=True) if marged: calculator = PlanckPR4LensingMarged() + print("Using primary CMB-marginalized PR4 likelihood. TT, EE, TE, BB, will not be used") else: calculator = PlanckPR4Lensing() + print("NOT using primary CMB-marginalized PR4 likelihood. TT, EE, TE, BB, will be used") return calculator, marged From 1314b4ee68db48fbd82b2289f763473c3167faaa Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Tue, 9 Jul 2024 09:48:23 +0100 Subject: [PATCH 15/19] save h0 --- examples/planck-npipe.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/planck-npipe.ini b/examples/planck-npipe.ini index df157b37..36fb31ec 100644 --- a/examples/planck-npipe.ini +++ b/examples/planck-npipe.ini @@ -29,7 +29,7 @@ values = examples/npipe-values.ini priors = examples/npipe-priors.ini debug=T timing=F -extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m +extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m cosmological_parameters/h0 [planck_npipe] ;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) From 28f51f3df78694e3cf4e149fafef61bb808d33b1 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Thu, 11 Jul 2024 15:04:27 +0200 Subject: [PATCH 16/19] revert back to original main planck ini files --- examples/planck.ini | 16 +++++----------- examples/planck_values.ini | 27 ++++++++++----------------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/examples/planck.ini b/examples/planck.ini index 70862220..e20e5adb 100644 --- a/examples/planck.ini +++ b/examples/planck.ini @@ -8,11 +8,6 @@ save_dir=output/planck fatal_errors=T -[nautilus] -n_live = 1000 -verbose = T - - [DEFAULT] ; This value is used below as %(planck_path)s planck_path = likelihood/planck2018/baseline/plc_3.0 @@ -22,20 +17,19 @@ planck_path = likelihood/planck2018/baseline/plc_3.0 ; these names refer to sections later in the file: modules = consistency camb planck values = examples/planck_values.ini -priors = examples/npipe-priors.ini +priors = examples/planck_priors.ini debug=T timing=F -extra_output = cosmological_parameters/sigma_8 cosmological_parameters/omega_m [planck] ;Planck 2018 high ell TT,TE and EE + low ell TT + low ell EE (in Planck notations = TT+lowE) ;without CMB lensing file = likelihood/planck2018/planck_interface.so -; data_1 = %(planck_path)s/hi_l/plik_lite/plik_lite_v22_TTTEEE.clik -; data_2 = %(planck_path)s/low_l/commander/commander_dx12_v3_2_29.clik -; data_3 = %(planck_path)s/low_l/simall/simall_100x143_offlike5_EE_Aplanck_B.clik -lensing_1 = %(planck_path)s/lensing/smicadx12_Dec5_ftl_mv2_ndclpp_p_teb_consext8_CMBmarged.clik_lensing +data_1 = %(planck_path)s/hi_l/plik_lite/plik_lite_v22_TTTEEE.clik +data_2 = %(planck_path)s/low_l/commander/commander_dx12_v3_2_29.clik +data_3 = %(planck_path)s/low_l/simall/simall_100x143_offlike5_EE_Aplanck_B.clik + ; The consistency module translates between our chosen parameterization ; and any other that modules in the pipeline may want (e.g. camb) diff --git a/examples/planck_values.ini b/examples/planck_values.ini index 32a9660d..60f75aef 100644 --- a/examples/planck_values.ini +++ b/examples/planck_values.ini @@ -1,22 +1,8 @@ -[planck] -a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels - - [cosmological_parameters] -; cosmomc_theta = 1.0 1.040909 1.08 ; this is actually 100 * theta_mc -h0 = 0.4 0.7 1.0 -omch2 = 0.05 0.12 0.2 -log1e10As = 1.91 3.0448 3.61 ; structure amplitude parameter - -ombh2 = 0.020 0.0222 0.025 -n_s = 0.9 0.96 1.02 - - +cosmomc_theta = 1.040909 ; this is actually 100 * theta_mc omega_k = 0.0 ;spatial curvature - -;reionization -tau = 0.055 ;reionization optical depth - +ombh2 = 0.022383 +omch2 = 0.12011 ;neutrinos mnu = 0.06 @@ -26,7 +12,12 @@ num_massive_neutrinos = 1 ;helium yhe = 0.245341 ;helium mass fraction +;reionization +tau = 0.0543 ;reionization optical depth +;inflation Parameters +n_s = 0.96605 ;scalar spectral index +log1e10As = 3.0448 ; structure amplitude parameter k_s = 0.05 ;Power spectrum pivot scale n_run = 0.0 ;running of scalar spectrum r_t = 0.0 ;tensor to scalar ratio @@ -36,3 +27,5 @@ n_t = 0.0 ;tensor spectral index w = -1.0 ;equation of state of dark energy wa = 0.0 ;equation of state of dark energy (redshift dependency) +[planck] +a_planck = 0.9 1.0 1.1 ; Total Planck calibration (relative to 1) at map level, scales all channels From c41909d0e4a8a55149d21b10afe0f0cc430456b7 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Thu, 11 Jul 2024 15:05:30 +0200 Subject: [PATCH 17/19] rename npipe file --- examples/{planck-npipe.ini => npipe.ini} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{planck-npipe.ini => npipe.ini} (100%) diff --git a/examples/planck-npipe.ini b/examples/npipe.ini similarity index 100% rename from examples/planck-npipe.ini rename to examples/npipe.ini From 15d4e660a5b18e8eda66588bb6c5c49182c23517 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Thu, 11 Jul 2024 15:09:04 +0200 Subject: [PATCH 18/19] add npipe to tests --- .github/workflows/ci.yml | 2 +- tests/test_cosmosis_standard_library.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c163cb45..faae4ba3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -232,7 +232,7 @@ jobs: python -m pip install --upgrade pip wheel setuptools pip install "cosmosis>=3.2" "nautilus-sampler==0.6.*" "numpy<2" pip install -v --no-cache-dir --no-binary=mpi4py,camb mpi4py camb - pip install fitsio astropy fast-pt "Cython<3.0" jupyter sacc + pip install fitsio astropy fast-pt "Cython<3.0" jupyter sacc "git+https://github.com/carronj/planck_PR4_lensing" - name: Install likelihood python dependencies run: | diff --git a/tests/test_cosmosis_standard_library.py b/tests/test_cosmosis_standard_library.py index ce46c852..d7b9397d 100644 --- a/tests/test_cosmosis_standard_library.py +++ b/tests/test_cosmosis_standard_library.py @@ -180,3 +180,11 @@ def test_hsc_real(capsys): pytest.skip("Sacc not installed") run_cosmosis("examples/hsc-y3-shear-real.ini") check_likelihood(capsys, "-122.5") + +def test_npipe(capsys): + try: + import planckpr4lensing + except ImportError: + pytest.skip("Planck PR4 lensing likelihood not found") + run_cosmosis("examples/npipe.ini") + check_likelihood(capsys, "-4.22", "-4.23") From 1620ae87b2f37c60512c0205635c8c6d6bcdd8c3 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Mon, 15 Jul 2024 11:26:02 +0100 Subject: [PATCH 19/19] include PR4 in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e41f8209..34dc2d62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,7 +137,7 @@ jobs: - name: Install likelihood python dependencies from pip shell: bash -l {0} run: | - pip install "act_dr6_lenslike>=1.0.2" + pip install "act_dr6_lenslike>=1.0.2" "git+https://github.com/carronj/planck_PR4_lensing" - name: Run Tests shell: bash -l {0} @@ -232,7 +232,7 @@ jobs: python -m pip install --upgrade pip wheel setuptools pip install "cosmosis==3.9.2" "nautilus-sampler==1.0.1" "scipy<1.14" pip install -v --no-cache-dir --no-binary=mpi4py,camb mpi4py camb - pip install fitsio astropy fast-pt "Cython>=3.0" jupyter sacc + pip install fitsio astropy fast-pt "Cython>=3.0" jupyter sacc "git+https://github.com/carronj/planck_PR4_lensing" - name: Install likelihood python dependencies run: |