From 97b48c7bb48166bb0367ec38de1db51c41b41b37 Mon Sep 17 00:00:00 2001 From: Hsin Fan <57552401+hsinfan1996@users.noreply.github.com> Date: Sat, 20 Jul 2024 07:24:40 +0800 Subject: [PATCH] Rename backend to use_backend; Add tests --- tests/test_theory.py | 82 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/tests/test_theory.py b/tests/test_theory.py index 61fcab813..35c021c7e 100644 --- a/tests/test_theory.py +++ b/tests/test_theory.py @@ -346,37 +346,37 @@ def test_profiles(modeling_data, profile_init): 2.5e-2, ) assert_allclose( - mod.eval_mean_surface_density( + mod.eval_surface_density( cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], r_mis=0.1, - verbose=True)[-40:], - (cfg["numcosmo_profiles"]["Sigma"] + cfg["numcosmo_profiles"]["DeltaSigma"])[-40:], - 8.5e-3, + verbose=True, use_backend=True)[-40:], + cfg["numcosmo_profiles"]["Sigma"][-40:], + 2.5e-2, ) assert_allclose( - mod.eval_excess_surface_density( + mod.eval_mean_surface_density( cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], r_mis=0.1, verbose=True)[-40:], - cfg["numcosmo_profiles"]["DeltaSigma"][-40:], - 3e-2 - ) - assert_allclose( - mod.eval_surface_density( - cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], r_mis=0.1, - verbose=True, backend=True)[-40:], - cfg["numcosmo_profiles"]["Sigma"][-40:], - 2.5e-2, + (cfg["numcosmo_profiles"]["Sigma"] + cfg["numcosmo_profiles"]["DeltaSigma"])[-40:], + 8.5e-3, ) assert_allclose( mod.eval_mean_surface_density( cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], r_mis=0.1, - verbose=True, backend=True)[-40:], + verbose=True, use_backend=True)[-40:], (cfg["numcosmo_profiles"]["Sigma"] + cfg["numcosmo_profiles"]["DeltaSigma"])[-40:], 8.5e-3, ) assert_allclose( mod.eval_excess_surface_density( cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], r_mis=0.1, - verbose=True, backend=False)[-40:], + verbose=True)[-40:], + cfg["numcosmo_profiles"]["DeltaSigma"][-40:], + 2.5e-2 + ) + assert_allclose( + mod.eval_excess_surface_density( + cfg["SIGMA_PARAMS"]["r_proj"], cfg["SIGMA_PARAMS"]["z_cl"], r_mis=0.1, + verbose=True, use_backend=False)[-40:], cfg["numcosmo_profiles"]["DeltaSigma"][-40:], 2.5e-2 ) @@ -422,6 +422,56 @@ def test_profiles(modeling_data, profile_init): reltol, ) + if mod.backend == "nc": + assert_allclose( + theo.compute_surface_density( + cosmo=cosmo, **cfg["SIGMA_PARAMS"], alpha_ein=alpha_ein, verbose=True, + r_mis=0.1 + )[-40:], + cfg["numcosmo_profiles"]["Sigma"][-40:], + 2.5e-2, + ) + assert_allclose( + theo.compute_surface_density( + cosmo=cosmo, **cfg["SIGMA_PARAMS"], alpha_ein=alpha_ein, verbose=True, + r_mis=0.1, use_backend=True + )[-40:], + cfg["numcosmo_profiles"]["Sigma"][-40:], + 2.5e-2, + ) + assert_allclose( + theo.compute_mean_surface_density( + cosmo=cosmo, **cfg["SIGMA_PARAMS"], alpha_ein=alpha_ein, verbose=True, + r_mis=0.1 + )[-40:], + (cfg["numcosmo_profiles"]["Sigma"] + cfg["numcosmo_profiles"]["DeltaSigma"])[-40:], + 8.5e-3, + ) + assert_allclose( + theo.compute_mean_surface_density( + cosmo=cosmo, **cfg["SIGMA_PARAMS"], alpha_ein=alpha_ein, verbose=True, + r_mis=0.1, use_backend=True + )[-40:], + (cfg["numcosmo_profiles"]["Sigma"] + cfg["numcosmo_profiles"]["DeltaSigma"])[-40:], + 8.5e-3, + ) + assert_allclose( + theo.compute_excess_surface_density( + cosmo=cosmo, **cfg["SIGMA_PARAMS"], alpha_ein=alpha_ein, verbose=True, + r_mis=0.1 + )[-40:], + cfg["numcosmo_profiles"]["DeltaSigma"][-40:], + 2.5e-2, + ) + assert_allclose( + theo.compute_excess_surface_density( + cosmo=cosmo, **cfg["SIGMA_PARAMS"], alpha_ein=alpha_ein, verbose=True, + r_mis=0.1, use_backend=True + )[-40:], + cfg["numcosmo_profiles"]["DeltaSigma"][-40:], + 2.5e-2, + ) + # Test use_projected_quad if mod.backend == "ccl" and profile_init == "einasto": if hasattr(mod.hdpm, 'projected_quad'):