Skip to content

Commit

Permalink
Merge pull request #97 from LSSTDESC/cclv3
Browse files Browse the repository at this point in the history
Update to CCLv3
  • Loading branch information
carlosggarcia authored Oct 17, 2023
2 parents 255cb11 + 3528b14 commit f99d399
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 92 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- numpy
- scipy
- pyyaml
- pyccl>=2.5.0,<2.8.0
- pyccl>=3.0.0
- sacc>=0.12
- namaster
- camb
Expand Down
1 change: 0 additions & 1 deletion examples/clusters/conf_covariance_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"numpy",
"Jinja2",
"pyyaml",
"pyccl>=2.5.0,<2.8.0",
"pyccl>=3.0.0",
"sacc>=0.12",
"camb",
"healpy",
Expand Down
1 change: 0 additions & 1 deletion tests/benchmarks/32_DES_tjpcov_bm/desy1_tjpcov_bm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ cov:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'


#### Biases to apply to the tracers ####
Expand Down
1 change: 0 additions & 1 deletion tests/data/conf_covariance_builder_minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'
1 change: 0 additions & 1 deletion tests/data/conf_covariance_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'
1 change: 0 additions & 1 deletion tests/data/conf_covariance_gaussian_fourier_nmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'

cache:
'workspaces':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'

cache:
'workspaces':
Expand Down
1 change: 0 additions & 1 deletion tests/data/conf_covariance_ssc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ parameters:
w0: -1
wa: 0
transfer_function: 'boltzmann_camb'
baryons_power_spectrum: 'nobaryons'
36 changes: 18 additions & 18 deletions tests/data/cosmo_desy1.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
Omega_c: 2.545000e-01
Omega_b: 4.850000e-02
Omega_m: 3.030000e-01
# Omega_m: 3.030000e-01
Omega_k: 0.000000e+00
k_sign: 0
# k_sign: 0
w0: -1.000000e+00
wa: 0.000000e+00
H0: 6.820000e+01
# H0: 6.820000e+01
h: 6.820000e-01
Neff: 3.046000e+00
N_nu_mass: 0
N_nu_rel: 3.046000e+00
sum_nu_masses: 0.000000e+00
Omega_nu_mass: 0.000000e+00
Omega_nu_rel: 3.675179e-05
A_s: nan
# N_nu_mass: 0
# N_nu_rel: 3.046000e+00
# sum_nu_masses: 0.000000e+00
# Omega_nu_mass: 0.000000e+00
# Omega_nu_rel: 3.675179e-05
# A_s: nan
n_s: 9.710000e-01
Omega_g: 5.312726e-05
T_CMB: 2.725000e+00
bcm_log10Mc: 1.407918e+01
bcm_etab: 5.000000e-01
bcm_ks: 5.500000e+01
mu_0: 0.000000e+00
sigma_0: 0.000000e+00
# bcm_log10Mc: 1.407918e+01
# bcm_etab: 5.000000e-01
# bcm_ks: 5.500000e+01
# mu_0: 0.000000e+00
# sigma_0: 0.000000e+00
sigma8: 8.010000e-01
Omega_l: 6.969101e-01
z_star: nan
has_mgrowth: 0
nz_mgrowth: 0
# Omega_l: 6.969101e-01
# z_star: nan
# has_mgrowth: 0
# nz_mgrowth: 0
16 changes: 9 additions & 7 deletions tests/test_covariance_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
N_z_bins = 18
N_lambda_bins = 3

MASSDEF = ccl.halos.MassDef200m


def teardown_module():
shutil.rmtree(OUTDIR)
Expand Down Expand Up @@ -108,7 +110,7 @@ def mock_covariance_gauss(mock_cosmo):
cc_cov.fft_helper = FFTHelper(
mock_cosmo, cc_cov.z_lower_limit, cc_cov.z_upper_limit
)
cc_cov.mass_func = hmf.MassFuncTinker10(mock_cosmo)
cc_cov.mass_func = hmf.MassFuncTinker10(mass_def=MASSDEF)
cc_cov.h0 = 0.67
return cc_cov

Expand All @@ -120,7 +122,7 @@ def mock_covariance_ssc(mock_cosmo):
cc_cov.fft_helper = FFTHelper(
mock_cosmo, cc_cov.z_lower_limit, cc_cov.z_upper_limit
)
cc_cov.mass_func = hmf.MassFuncTinker10(mock_cosmo)
cc_cov.mass_func = hmf.MassFuncTinker10(mass_def=MASSDEF)
cc_cov.h0 = 0.67
return cc_cov

Expand Down Expand Up @@ -163,21 +165,21 @@ def test_integral_mass_no_bias(
mock_covariance_gauss: CovarianceClusterCounts, z, ref_val
):
test = mock_covariance_gauss.mass_richness_integral(z, 0, remove_bias=True)
assert test == pytest.approx(ref_val, rel=1e-4)
assert test == pytest.approx(ref_val, rel=1e-3)


def test_double_bessel_integral(
mock_covariance_gauss: CovarianceClusterCounts,
):
ref = 8.427201745032292e-05
test = mock_covariance_gauss.double_bessel_integral(0.3, 0.3)
assert test == pytest.approx(ref, rel=1e-4)
assert test == pytest.approx(ref, rel=1e-3)


def test_shot_noise(mock_covariance_gauss: ClusterCountsGaussian):
ref = 63973.635143644424
test = mock_covariance_gauss.shot_noise(0, 0)
assert test == pytest.approx(ref, 1e-4)
assert test == pytest.approx(ref, rel=1e-3)


@pytest.mark.parametrize(
Expand All @@ -191,7 +193,7 @@ def test_integral_mass(
mock_covariance_gauss: CovarianceClusterCounts, z, reference_val
):
test = mock_covariance_gauss.mass_richness_integral(z, 0)
assert test == pytest.approx(reference_val, rel=1e-4)
assert test == pytest.approx(reference_val, rel=1e-3)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -278,7 +280,7 @@ def test_cov_nxn(
("mock_survey", "bin_z_0", "bin_rich_0"),
("mock_survey", "bin_z_0", "bin_rich_0"),
)
assert cov_00_gauss + cov_00_ssc == pytest.approx(ref_sum, rel=1e-4)
assert cov_00_gauss + cov_00_ssc == pytest.approx(ref_sum, rel=1e-3)


def test_cluster_count_tracer_missing_throws():
Expand Down
27 changes: 22 additions & 5 deletions tests/test_covariance_fourier_base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

import numpy as np
import pyccl as ccl
import pymaster as nmt
import pytest
import sacc
import shutil
import pyccl as ccl

from tjpcov.covariance_builder import CovarianceFourier

Expand Down Expand Up @@ -235,14 +235,31 @@ def test_get_tracer_info(mock_cov_fourier):
else:
assert np.abs(nl / (sigma_e**2 / Ngal) - 1) < 1e-5

# TODO: We should check the CCL tracers are the same
sacc = mock_cov_fourier.io.sacc_file
cosmo = mock_cov_fourier.get_cosmology()
for tr, ccltr in ccl_tracers.items():
trsacc = sacc.tracers[tr]
if "gc" in tr:
assert isinstance(ccltr, ccl.NumberCountsTracer)
z, nz = (trsacc.z, trsacc.nz)
assert nz == pytest.approx(ccltr.get_dndz(z), rel=1e-4)
chi = ccl.comoving_radial_distance(cosmo, 1 / (1 + z))
kz = ccltr.get_kernel(chi)[0]
z_max_nz = z[np.argmax(nz)]
z_max_kz = z[np.argmax(kz)]
assert z_max_nz == pytest.approx(z_max_kz, rel=1e-2)
elif "wl" in tr:
assert isinstance(ccltr, ccl.WeakLensingTracer)
z, nz = (trsacc.z, trsacc.nz)
assert nz == pytest.approx(ccltr.get_dndz(z), rel=1e-4)
chi = ccl.comoving_radial_distance(cosmo, 1 / (1 + z))
kz = ccltr.get_kernel(chi)[0]
z_max_nz = z[np.argmax(nz)]
z_max_kz = z[np.argmax(kz)]
assert z_max_kz < z_max_nz
elif "cv" in tr:
assert isinstance(ccltr, ccl.CMBLensingTracer)
assert not isinstance(ccltr, ccl.tracers.NzTracer)
chi_max = ccltr.chi_max
chi_max2 = ccl.comoving_radial_distance(cosmo, 1 / (1 + 1100))
assert chi_max == pytest.approx(chi_max2, rel=1e-4)

# Check tracer_noise_coupled. Modify the sacc file to add metadata
# information for the tracer noise
Expand Down
6 changes: 3 additions & 3 deletions tests/test_covariance_fourier_gaussian_nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def test_get_covariance_block(tracer_comb1, tracer_comb2):
# Check chi2, which is what we actually care about
if tracer_comb1 == tracer_comb2:
s = cnmt.io.get_sacc_file()
assert_chi2(s, tracer_comb1, tracer_comb2, cov, cov_bm, 1e-4)
assert_chi2(s, tracer_comb1, tracer_comb2, cov, cov_bm, 1e-3)

# Check that it runs if one of the masks does not overlap with the others
if tracer_comb1 != tracer_comb2:
Expand Down Expand Up @@ -1153,7 +1153,7 @@ def test_full_covariance_benchmark():
delta = clf - cl
chi2 = delta.dot(np.linalg.inv(cov)).dot(delta)
chi2_bm = delta.dot(np.linalg.inv(cov_bm)).dot(delta)
assert np.abs(chi2 / chi2_bm - 1) < 1e-4
assert np.abs(chi2 / chi2_bm - 1) < 1e-3

# Clean after the test
clean_outdir()
Expand Down Expand Up @@ -1224,4 +1224,4 @@ def test_txpipe_like_input():
delta = clf - cl
chi2 = delta.dot(np.linalg.inv(cov)).dot(delta)
chi2_bm = delta.dot(np.linalg.inv(cov_bm)).dot(delta)
assert np.abs(chi2 / chi2_bm - 1) < 1e-4
assert np.abs(chi2 / chi2_bm - 1) < 1e-3
30 changes: 15 additions & 15 deletions tests/test_covariance_fourier_ssc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ def get_config():


def get_halo_model(cosmo):
md = ccl.halos.MassDef200m()
mf = ccl.halos.MassFuncTinker08(cosmo, mass_def=md)
hb = ccl.halos.HaloBiasTinker10(cosmo, mass_def=md)
hmc = ccl.halos.HMCalculator(cosmo, mf, hb, md)
md = ccl.halos.MassDef200m
mf = ccl.halos.MassFuncTinker08(mass_def=md)
hb = ccl.halos.HaloBiasTinker10(mass_def=md)
hmc = ccl.halos.HMCalculator(mass_function=mf, halo_bias=hb, mass_def=md)

return hmc


def get_NFW_profile():
md = ccl.halos.MassDef200m()
cm = ccl.halos.ConcentrationDuffy08(mdef=md)
pNFW = ccl.halos.HaloProfileNFW(cm)
md = ccl.halos.MassDef200m
cm = ccl.halos.ConcentrationDuffy08(mass_def=md)
pNFW = ccl.halos.HaloProfileNFW(mass_def=md, concentration=cm)

return pNFW

Expand Down Expand Up @@ -158,7 +158,7 @@ def test_get_covariance_block(cov_fssc, tracer_comb1, tracer_comb2):
tkk_ssc = ccl.halos.halomod_Tk3D_SSC_linear_bias(
cosmo,
hmc,
nfw_profile,
prof=nfw_profile,
bias1=bias1,
bias2=bias2,
bias3=bias3,
Expand All @@ -170,7 +170,7 @@ def test_get_covariance_block(cov_fssc, tracer_comb1, tracer_comb2):
)

cl_mask = get_cl_footprint(*tracer_comb1, *tracer_comb2)
sigma2_B = ccl.sigma2_B_from_mask(cosmo, a=a_arr, mask_wl=cl_mask)
sigma2_B = ccl.sigma2_B_from_mask(cosmo, a_arr=a_arr, mask_wl=cl_mask)

ccl_tracers, _ = cov_fssc.get_tracer_info()
tr1 = ccl_tracers[tracer_comb1[0]]
Expand All @@ -179,13 +179,13 @@ def test_get_covariance_block(cov_fssc, tracer_comb1, tracer_comb2):
tr4 = ccl_tracers[tracer_comb2[1]]
cov_ccl = ccl.angular_cl_cov_SSC(
cosmo,
cltracer1=tr1,
cltracer2=tr2,
tracer1=tr1,
tracer2=tr2,
ell=ell,
tkka=tkk_ssc,
t_of_kk_a=tkk_ssc,
sigma2_B=(a_arr, sigma2_B),
cltracer3=tr3,
cltracer4=tr4,
tracer3=tr3,
tracer4=tr4,
)

assert np.max(np.fabs(np.diag(cov_ssc / cov_ccl - 1))) < 1e-5
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_get_covariance_block_WL_benchmark(cov_fssc):
cosmo = ccl.Cosmology(
Omega_c=0.25, Omega_b=0.05, h=h, n_s=0.97, sigma8=0.8, m_nu=0.0
)
WL_tracer = ccl.WeakLensingTracer(cosmo, (z, nofz))
WL_tracer = ccl.WeakLensingTracer(cosmo, dndz=(z, nofz))

# Trick TJPCov to use the ells we want instead the ones in the file
s = sacc.Sacc()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_get_covariance(fg_nmt_cov):
cov = fg_nmt_cov.get_covariance() + 1e-100
cov_bm = s.covariance.covmat + 1e-100
assert np.max(np.abs(np.diag(cov) / np.diag(cov_bm) - 1)) < 1e-3
assert np.max(np.abs(cov / cov_bm - 1)) < 1
assert np.max(np.abs(np.diag(cov, 1) / np.diag(cov_bm, 1) - 1)) < 1e-2

# Check chi2
clf = np.array([])
Expand All @@ -157,7 +157,7 @@ def test_get_covariance(fg_nmt_cov):
delta = clf - cl
chi2 = delta.dot(np.linalg.inv(cov)).dot(delta)
chi2_bm = delta.dot(np.linalg.inv(cov_bm)).dot(delta)
assert np.abs(chi2 / chi2_bm - 1) < 1e-4
assert np.abs(chi2 / chi2_bm - 1) < 1e-3


def test_covariance_calculator(cov_calc, cov_calc_mpi):
Expand Down
4 changes: 2 additions & 2 deletions tjpcov/covariance_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def get_cosmology(self):

if cosmo is None or cosmo == "set":
self.cosmo = ccl.Cosmology(**self.config["parameters"])
elif isinstance(cosmo, ccl.core.Cosmology):
elif isinstance(cosmo, ccl.Cosmology):
self.cosmo = cosmo
elif isinstance(cosmo, str):
ext = cosmo.split(".")[-1]
Expand All @@ -258,7 +258,7 @@ def get_cosmology(self):
else:
raise ValueError(
"cosmo entry looks wrong. It has to be one"
"of ['set', ccl.core.Cosmology instance, "
"of ['set', ccl.Cosmology instance, "
"a yaml file or a pickle"
)

Expand Down
Loading

0 comments on commit f99d399

Please sign in to comment.