Skip to content

Commit

Permalink
Merge pull request #94 from joezuntz/theta_h0_issue
Browse files Browse the repository at this point in the history
Change the consistency cosmomc_theta->H0 to use camb
  • Loading branch information
joezuntz authored Aug 22, 2023
2 parents 729cc21 + cf0c0ad commit 8436306
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 261 deletions.
237 changes: 55 additions & 182 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ jobs:
run: |
wget https://lambda.gsfc.nasa.gov/data/map/dr5/dcp/likelihood/wmap_likelihood_full_v5.tar.gz
- name: Cache ACT data
id: cache-act
uses: actions/cache@v3
with:
path: ACT_dr6_likelihood_v1.1.tgz
key: act-dr6-data
enableCrossOsArchive: true

- if: ${{ steps.cache-act.outputs.cache-hit != 'true' }}
name: Download ACT data
run: |
wget https://lambda.gsfc.nasa.gov/data/suborbital/ACT/ACT_dr6/likelihood/data/ACT_dr6_likelihood_v1.1.tgz
Expand All @@ -74,8 +87,7 @@ jobs:

- name: Install dependencies with conda
shell: bash -l {0}
run: mamba install -c conda-forge "cosmosis>=3.0.1" cosmosis-build-standard-library

run: mamba install -c conda-forge "cosmosis>=3.2" cosmosis-build-standard-library pytest

- name: Get Cached Planck
uses: actions/cache/restore@v3
Expand All @@ -90,188 +102,49 @@ jobs:
path: wmap_likelihood_full_v5.tar.gz
key: wmap-9-data
fail-on-cache-miss: true

- name: Get Cached ACT
uses: actions/cache/restore@v3
with:
path: ACT_dr6_likelihood_v1.1.tgz
key: act-dr6-data
fail-on-cache-miss: true

- name: Extract data
shell: bash -l {0}
run: |
# WMAP
pushd likelihood/wmap9/data
tar -zxvf ../../../wmap_likelihood_full_v5.tar.gz
mv wmap_likelihood_v5/data/* .
popd
#Planck
pushd likelihood/planck2018
tar -zxvf ../../COM_Likelihood_Data-baseline_R3.00.tar.gz
popd
# ACT
mkdir likelihood/act-dr6-lens/data
pushd likelihood/act-dr6-lens/data
tar -zxvf ../../../ACT_dr6_likelihood_v1.1.tgz
popd
- name: Build standard library
shell: bash -l {0}
run: |
source cosmosis-configure
make
- name: Smail example
- name: Run Tests
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/various-spectra.ini -p consistency.extra_relations='omega_x=omega_c+100'
grep -e 'omega_x = 100.261' output/various-spectra/cosmological_parameters/values.txt
- name: BAO
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/bao.ini
- name: CAMB Planck
shell: bash -l {0}
run: |
# print out the configuration
python -m cosmosis.configure
source cosmosis-configure
export
mkdir -p output
# And that the pipeline runs afterwards
cosmosis examples/planck.ini | tee output/planck.log
grep -e 'Likelihood = -1441.30' -e 'Likelihood = -1441.46' output/planck.log
- name: Class Planck
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/planck_class.ini -p class.mpk=T | tee output/class.log
# This may need updating as we modify the class interface
# The settings are not optimized
# grep 'Likelihood = -5968.93' output/class.log
# This seems to give different results on different systems
- name: WMAP likelihood
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/wmap.ini | tee output/wmap.log
- name: Pantheon emcee
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/pantheon.ini -p emcee.samples=20
cosmosis-postprocess examples/pantheon.ini -o output/pantheon
test -f output/pantheon/cosmological_parameters--omega_m.png
- name: PantheonPlusAndShoes
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/pantheon_plus_shoes.ini -p runtime.sampler=test | tee output/pantheon_plus_shoes_log.txt
grep 'Likelihood = -738.23' output/pantheon_plus_shoes_log.txt
- name: DES Y1 likelihood
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y1.ini | tee output/des-y1.log
# unchanged in camb 1.4
grep 'Likelihood = 5237.3' output/des-y1.log
- name: DES Y1 likelihood with cl_to_corr
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y1.ini -p 2pt_shear.file=./shear/cl_to_corr/cl_to_corr.py 2pt_shear.corr_type=xi | tee output/des-y1.log
# unchanged in camb 1.4
grep 'Likelihood = 5237.3' output/des-y1.log
- name: DES Y3 likelihood
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3.ini -p pk_to_cl_gg.save_kernels=T pk_to_cl.save_kernels=T | tee output/des-y3.log
# Different versions - camb changes and scipy interpolation changes both alter these
grep -e 'Likelihood = 6043.23' -e 'Likelihood = 6043.34' -e 'Likelihood = 6043.33' output/des-y3.log
- name: DES Y3 Class likelihood
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3-class.ini
# class is not consistent across systems to the level needed here
- name: DES Y3 cosmic shear likelihood
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3-shear.ini | tee output/des-y3-shear.log
grep -e 'Likelihood = 2957.03' -e 'Likelihood = 2957.12' -e 'Likelihood = 2957.11' output/des-y3-shear.log
- name: DES Y3 likelihood with Mira Titan
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3-mira-titan.ini | tee output/des-y3-mt.log
grep -e 'Likelihood = 6048.0' -e 'Likelihood = 6048.1' output/des-y3-mt.log
- name: DES Y3 likelihood with Mead nonlinear
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3.ini -v halo_model_parameters.logT_AGN=8.2 -p camb.halofit_version=mead2020_feedback | tee output/des-y3-mead.log
grep -e 'Likelihood = 6049.94' -e 'Likelihood = 6049.00' output/des-y3-mead.log
- name: Joint DES Y3 and KiDS-1000 likelihood
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3_and_kids-1000.ini | tee output/des-y3_and_kids-1000.log
grep 'Likelihood = -199.409' output/des-y3_and_kids-1000.log
- uses: actions/cache@v2
name: ACT Data Cache
id: cache-act
with:
path: likelihood/act-dr6-lens/data/v1.1
key: ${{ runner.os }}-act-dr6-v1.1

- name: Download ACT DR6 Lensing Data
if: steps.cache-act.outputs.cache-hit != 'true'
run: |
cd likelihood/act-dr6-lens/
./get-act-data.sh
- name: ACT DR6 Lensing
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/act-dr6-lens.ini | tee output/act-dr6.log
grep -e 'Likelihood = -9.89' -e 'Likelihood = -9.90' output/act-dr6.log
- name: DES Y3 6x2pt
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/des-y3-6x2.ini
- name: Euclid emulator
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/euclid-emulator.ini
test -f output/euclid-emulator/matter_power_nl/p_k.txt
- name: Log w example
shell: bash -l {0}
run: |
source cosmosis-configure
cosmosis examples/w_model.ini | tee output/w_model.log
pytest -vv --durations=0 tests/test_cosmosis_standard_library.py
- name: Run Demos
shell: bash -l {0}
run: |
.github/run-demos.sh
source cosmosis-configure
pytest -vv --durations=0 tests/test_demos.py
Expand All @@ -280,7 +153,7 @@ jobs:
needs: Download_Data
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]

steps:
- name: Checkout repository
Expand Down Expand Up @@ -315,16 +188,30 @@ jobs:
key: wmap-9-data
fail-on-cache-miss: true

- name: Get Cached ACT
uses: actions/cache/restore@v3
with:
path: ACT_dr6_likelihood_v1.1.tgz
key: act-dr6-data
fail-on-cache-miss: true

- name: Extract data
shell: bash -l {0}
run: |
pushd likelihood/wmap9/data
tar -zxvf ../../../wmap_likelihood_full_v5.tar.gz
mv wmap_likelihood_v5/data/* .
popd
pushd likelihood/planck2018
tar -zxvf ../../COM_Likelihood_Data-baseline_R3.00.tar.gz
popd
# WMAP
pushd likelihood/wmap9/data
tar -zxvf ../../../wmap_likelihood_full_v5.tar.gz
mv wmap_likelihood_v5/data/* .
popd
#Planck
pushd likelihood/planck2018
tar -zxvf ../../COM_Likelihood_Data-baseline_R3.00.tar.gz
popd
# ACT
mkdir likelihood/act-dr6-lens/data
pushd likelihood/act-dr6-lens/data
tar -zxvf ../../../ACT_dr6_likelihood_v1.1.tgz
popd

- uses: actions/cache@v2
Expand All @@ -338,7 +225,7 @@ jobs:
- name: Install python dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
pip install "cosmosis>=3.2"
pip install "cosmosis>=3.2" "nautilus-sampler==0.6.*"
pip install -v --no-cache-dir --no-binary=mpi4py,camb mpi4py camb
pip install fitsio astropy fast-pt "Cython<3.0" jupyter
Expand All @@ -365,20 +252,6 @@ jobs:
grep -e "🟢 fiducial-test-only" output/campaign.log
cosmosis-campaign examples/des-campaign.yml --status
- name: Demo 2 Planck 2018 Likelihood
run: |
source .github/ci-setup.sh
cosmosis demos/demo2.ini
cosmosis-postprocess demos/demo2.ini -o output/demo2
test -f output/demo2/comoving_distance.png
- name: Demo 9 Low-Resolution Multinest
run: |
source .github/ci-setup.sh
cosmosis demos/demo9.ini -p multinest.live_points=100
cosmosis-postprocess output/demo9.txt -o output/demo9
test -f output/demo9/2D_supernova_params--deltam_cosmological_parameters--omega_m.png
- name: ExampleNotebook
shell: bash -l {0}
run: |
Expand Down
41 changes: 27 additions & 14 deletions boltzmann/camb/camb_interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from cosmosis.datablock import names, option_section as opt
from cosmosis.datablock.cosmosis_py import errors
import numpy as np
from scipy.interpolate import InterpolatedUnivariateSpline
import warnings
import traceback
import contextlib

# Finally we can now import camb
import camb
Expand Down Expand Up @@ -38,6 +38,15 @@
'v_baryon_cdm': 'baryon_cdm_relative_velocity_power',
}

@contextlib.contextmanager
def be_quiet_camb():
original_feedback_level = camb.config.FeedbackLevel
try:
camb.set_feedback_level(0)
yield
finally:
camb.set_feedback_level(original_feedback_level)


def get_optional_params(block, section, names):
params = {}
Expand Down Expand Up @@ -349,12 +358,12 @@ def extract_camb_params(block, config, more_config):
warnings.warn("Parameter omega_nu and omnuh2 are being ignored. Set mnu and num_massive_neutrinos instead.")

# Set h if provided, otherwise look for theta_mc
if block.has_value(cosmo, "hubble"):
if block.has_value(cosmo, "cosmomc_theta"):
cosmology_params["cosmomc_theta"] = block[cosmo, "cosmomc_theta"] / 100
elif block.has_value(cosmo, "hubble"):
cosmology_params["H0"] = block[cosmo, "hubble"]
elif block.has_value(cosmo, "h0"):
cosmology_params["H0"] = block[cosmo, "h0"]*100
else:
cosmology_params["cosmomc_theta"] = block[cosmo, "cosmomc_theta"]/100
cosmology_params["H0"] = block[cosmo, "h0"]*100

p = camb.CAMBparams(
InitPower = init_power,
Expand All @@ -366,11 +375,12 @@ def extract_camb_params(block, config, more_config):
**config,
)
# Setting up neutrinos by hand is hard. We let CAMB deal with it instead.
p.set_cosmology(ombh2 = block[cosmo, 'ombh2'],
omch2 = block[cosmo, 'omch2'],
omk = block[cosmo, 'omega_k'],
**more_config["cosmology_params"],
**cosmology_params)
with be_quiet_camb():
p.set_cosmology(ombh2 = block[cosmo, 'ombh2'],
omch2 = block[cosmo, 'omch2'],
omk = block[cosmo, 'omega_k'],
**more_config["cosmology_params"],
**cosmology_params)

# Fix for CAMB version < 1.0.10
if np.isclose(p.omnuh2, 0) and "nnu" in cosmology_params and not np.isclose(cosmology_params["nnu"], p.num_nu_massless):
Expand Down Expand Up @@ -642,14 +652,17 @@ def execute(block, config):
more_config["n_printed_errors"] += 1
return 1

save_derived_parameters(r, block)
save_distances(r, block, more_config)
with be_quiet_camb():
save_derived_parameters(r, block)
save_distances(r, block, more_config)

if p.WantTransfer:
save_matter_power(r, block, more_config)
with be_quiet_camb():
save_matter_power(r, block, more_config)

if p.WantCls:
save_cls(r, block)
with be_quiet_camb():
save_cls(r, block)

return 0

Expand Down
Loading

0 comments on commit 8436306

Please sign in to comment.