Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in updates from master #174

Merged
merged 12 commits into from
Jun 7, 2024
Prev Previous commit
Resolving packages path with cobaya tools (#169)
* Fix extra letter in calibration params

* Use cobaya tools to resolve packages path

* flake

* Revert "flake"

This reverts commit 526acde.

* Update yaml files with correct paramnames and paths

For the `test_multi.py`, I switched from `MFLike` to `TestMFLike`, coherently with `test_mflike.py`

* Update paths in test_multi

* Enable multi and mflike in test_runs

* bug fix

* Avoid overwrite global packages_path

* flake

* Change pathfinding to data with packages path

* Revert to request forcing rootdir

* Point to `tox.ini` directory

---------

Co-authored-by: mgerbino <marti.gerbino@gmail.com>
Co-authored-by: Ian Harrison <itrharrison@gmail.com>
  • Loading branch information
3 people authored Apr 26, 2024
commit 0c9d26df9ec47a84f2d45fb62d5c73633f6d4c54
1 change: 1 addition & 0 deletions soliket/tests/test_bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cobaya.model import get_model
from ..constants import T_CMB, h_Planck, k_Boltzmann


info = {"params": {
"bandint_shift_LAT_93": 0.0,
"bandint_shift_LAT_145": 0.0,
Expand Down
5 changes: 3 additions & 2 deletions soliket/tests/test_cross_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from soliket.ccl import CCL
from cobaya.model import get_model


gammakappa_sacc_file = 'soliket/tests/data/des_s-act_kappa.toy-sim.sacc.fits'
gkappa_sacc_file = 'soliket/tests/data/gc_cmass-actdr4_kappa.sacc.fits'

Expand All @@ -25,12 +26,12 @@
}


def test_galaxykappa_import(request):
def test_galaxykappa_import():

from soliket.cross_correlation import GalaxyKappaLikelihood # noqa F401


def test_shearkappa_import(request):
def test_shearkappa_import():

from soliket.cross_correlation import ShearKappaLikelihood # noqa F401

Expand Down
27 changes: 18 additions & 9 deletions soliket/tests/test_lensing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import os
import tempfile
import numpy as np
from cobaya.model import get_model

packages_path = os.environ.get("COBAYA_PACKAGES_PATH") or os.path.join(
tempfile.gettempdir(), "lensing_packages"
)
from cobaya.tools import resolve_packages_path

packages_path = resolve_packages_path()
# Cosmological parameters for the test data from SO sims
# See https://github.com/simonsobs/SOLikeT/pull/101 for validation plots
fiducial_params = {
Expand All @@ -31,8 +28,14 @@ def test_lensing_import(request):
def test_lensing_like(request):

from cobaya.install import install
install({"likelihood": {"soliket.lensing.LensingLikelihood": None}},
path=packages_path, skip_global=False, force=True, debug=True)
install(
{"likelihood": {"soliket.lensing.LensingLikelihood": None}},
path=packages_path,
skip_global=False,
force=True,
debug=True,
no_set_global=True,
)

from soliket.lensing import LensingLikelihood

Expand All @@ -49,8 +52,14 @@ def test_lensing_ccl_limber(request):
"""

from cobaya.install import install
install({"likelihood": {"soliket.lensing.LensingLikelihood": None}},
path=packages_path, skip_global=False, force=True, debug=True)
install(
{"likelihood": {"soliket.lensing.LensingLikelihood": None}},
path=packages_path,
skip_global=False,
force=True,
debug=True,
no_set_global=True,
)

from soliket.lensing import LensingLikelihood
from copy import deepcopy
Expand Down
17 changes: 11 additions & 6 deletions soliket/tests/test_mflike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
Make sure that this returns the same result as original mflike.MFLike from LAT_MFlike repo
"""
import os
import tempfile
import unittest
from packaging.version import Version

import camb
import soliket # noqa
from soliket.mflike import TestMFLike

packages_path = os.environ.get("COBAYA_PACKAGES_PATH") or os.path.join(
tempfile.gettempdir(), "LAT_packages"
)
from cobaya.tools import resolve_packages_path

packages_path = resolve_packages_path()

cosmo_params = {
"cosmomc_theta": 0.0104085,
Expand Down Expand Up @@ -77,8 +76,14 @@ class MFLikeTest(unittest.TestCase):
def setUp(self):
from cobaya.install import install

install({"likelihood": {"soliket.mflike.TestMFLike": None}},
path=packages_path, skip_global=False, force=True, debug=True)
install(
{"likelihood": {"soliket.mflike.TestMFLike": None}},
path=packages_path,
skip_global=False,
force=True,
debug=True,
no_set_global=True,
)


def test_mflike(self):
Expand Down
3 changes: 1 addition & 2 deletions soliket/tests/test_mflike.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ debug: True
likelihood:
soliket.mflike.TestMFLike:
data_folder: TestMFLike
input_file: data_sacc_00044.fits
cov_Bbl_file: data_sacc_w_covar_and_Bbl.fits
input_file: test_data_sacc_00000.fits
defaults:
# Which spectra?
polarizations: ['TT', 'TE', 'ET', 'EE']
Expand Down
14 changes: 7 additions & 7 deletions soliket/tests/test_multi.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import numpy as np
import pytest
from soliket.tests.test_mflike import cosmo_params, nuisance_params
from cobaya.tools import resolve_packages_path

packages_path = resolve_packages_path()

@pytest.mark.xfail(reason="lensing lhood install failure")
def test_multi():

def test_multi():
lensing_options = {"theory_lmax": 5000}

pre = "data_sacc_"
pre = "test_data_sacc_"
mflike_options = {
"input_file": pre + "00000.fits",
"cov_Bbl_file": pre + "w_covar_and_Bbl.fits",
"data_folder": "TestMFLike",
"stop_at_error": True,
}

Expand All @@ -27,7 +27,7 @@ def test_multi():
info = {
"likelihood": {
"soliket.gaussian.MultiGaussianLikelihood": {
"components": ["soliket.mflike.MFLike", "soliket.LensingLikelihood"],
"components": ["soliket.mflike.TestMFLike", "soliket.LensingLikelihood"],
"options": [mflike_options, lensing_options],
"stop_at_error": True,
}
Expand All @@ -40,7 +40,7 @@ def test_multi():
}

info1 = {
"likelihood": {"soliket.mflike.MFLike": mflike_options},
"likelihood": {"soliket.mflike.TestMFLike": mflike_options},
"theory": {"camb": camb_options,
"soliket.TheoryForge_MFLike": {'stop_at_error': True},
"soliket.Foreground": {"stop_at_error": True},
Expand Down
53 changes: 24 additions & 29 deletions soliket/tests/test_multi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ debug: True
likelihood:
soliket.gaussian.MultiGaussianLikelihood:
components:
- soliket.mflike.MFLike
- soliket.mflike.TestMFLike
- soliket.LensingLikelihood
options:
- input_file: data_sacc_00044.fits
cov_Bbl_file: data_sacc_w_covar_and_Bbl.fits
- input_file: test_data_sacc_00000.fits
data_folder: "TestMFLike"
defaults:
# Which spectra?
polarizations: ['TT', 'TE', 'ET', 'EE']
Expand All @@ -22,24 +22,19 @@ likelihood:
symmetrize: False
data:
experiments:
LAT:
frequencies: [93, 145, 225]
- LAT_93
- LAT_145
- LAT_225

spectra:
- experiments: ['LAT', 'LAT']
frequencies: [93, 93]
- experiments: ['LAT_93', 'LAT_93']
polarizations: ['TT','TE','EE']
- experiments: ['LAT', 'LAT']
frequencies: [93, 145]
- experiments: ['LAT', 'LAT']
frequencies: [93, 225]
- experiments: ['LAT', 'LAT']
frequencies: [145, 145]
- experiments: ['LAT_93', 'LAT_145']
- experiments: ['LAT_93', 'LAT_225']
- experiments: ['LAT_145', 'LAT_145']
polarizations: ['TT','TE','EE']
- experiments: ['LAT', 'LAT']
frequencies: [145, 225]
- experiments: ['LAT', 'LAT']
frequencies: [225, 225]
- experiments: ['LAT_145', 'LAT_225']
- experiments: ['LAT_225', 'LAT_225']
polarizations: ['TT','TE','EE']
- theory_lmax: 5000
stop_at_error: true
Expand Down Expand Up @@ -187,43 +182,43 @@ params:
proposal: 0.6
latex: T_d
# Systematics
bandint_shift_93:
bandint_shift_LAT_93:
value: 0
latex: \Delta_{\rm band}^{93}
bandint_shift_145:
bandint_shift_LAT_145:
value: 0
latex: \Delta_{\rm band}^{145}
bandint_shift_225:
bandint_shift_LAT_225:
value: 0
latex: \Delta_{\rm band}^{225}
calT_93:
calT_LAT_93:
value: 1
latex: \mathrm{Cal}_{\rm T}^{93}
calE_93:
calE_LAT_93:
value: 1
latex: \mathrm{Cal}_{\rm E}^{93}
calT_145:
calT_LAT_145:
value: 1
latex: \mathrm{Cal}_{\rm T}^{145}
calE_145:
calE_LAT_145:
value: 1
latex: \mathrm{Cal}_{\rm E}^{145}
calT_225:
calT_LAT_225:
value: 1
latex: \mathrm{Cal}_{\rm T}^{225}
calE_225:
calE_LAT_225:
value: 1
latex: \mathrm{Cal}_{\rm E}^{225}
calG_all:
value: 1
latex: \mathrm{Cal}_{\rm G}^{\rm All}
alpha_93:
alpha_LAT_93:
value: 0 #deg
latex: \alpha^{93}
alpha_145:
alpha_LAT_145:
value: 0 #deg
latex: \alpha^{145}
alpha_225:
alpha_LAT_225:
value: 0 #deg
latex: \alpha^{225}

Expand Down
24 changes: 4 additions & 20 deletions soliket/tests/test_runs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import pkgutil
import pytest
import tempfile
from cobaya.yaml import yaml_load
from cobaya.run import run
from cobaya.tools import resolve_packages_path

import os

packages_path = os.environ.get("COBAYA_PACKAGES_PATH") or os.path.join(
tempfile.gettempdir(), "lensing_packages"
)
packages_path = resolve_packages_path()


@pytest.mark.parametrize("lhood",
Expand All @@ -21,18 +17,12 @@
# "xcorr"
])
def test_evaluate(lhood):
if lhood == "multi":
pytest.xfail(reason="multi lhood install failure")

if lhood == "mflike":
pytest.skip(reason="don't want to install 300Mb of data!")

info = yaml_load(pkgutil.get_data("soliket", f"tests/test_{lhood}.yaml"))
info["force"] = True
info['sampler'] = {'evaluate': {}}

from cobaya.install import install
install(info, path=packages_path, skip_global=True)
install(info, path=packages_path, skip_global=True, no_set_global=True)

updated_info, sampler = run(info)

Expand All @@ -47,17 +37,11 @@ def test_evaluate(lhood):
# "xcorr"
])
def test_mcmc(lhood):
if lhood == "multi":
pytest.xfail(reason="multi lhood install failure")

if lhood == "mflike":
pytest.skip(reason="don't want to install 300Mb of data!")

info = yaml_load(pkgutil.get_data("soliket", f"tests/test_{lhood}.yaml"))
info["force"] = True
info['sampler'] = {'mcmc': {'max_samples': 10, 'max_tries': 1000}}

from cobaya.install import install
install(info, path=packages_path, skip_global=True)
install(info, path=packages_path, skip_global=True, no_set_global=True)

updated_info, sampler = run(info)
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extras =
commands =
pip freeze
all: cobaya-install planck_2018_highl_plik.TTTEEE_lite_native --no-set-global
!cov: pytest -v --pyargs soliket {posargs}
cov: pytest -v --pyargs soliket --cov soliket --cov-report=xml --cov-config={toxinidir}/setup.cfg {posargs}
!cov: pytest -v --rootdir={toxinidir} --pyargs soliket {posargs}
cov: pytest -v --rootdir={toxinidir} --pyargs soliket --cov soliket --cov-report=xml --cov-config={toxinidir}/setup.cfg {posargs}

[testenv:codestyle]
skip_install = true
Expand Down
Loading