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

fixing mflike test and fixing np.float error #104

Merged
merged 17 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ getdist
cobaya
pyccl
sacc
fgspectra
fgspectra>=1.1.0
syslibrary
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ install_requires =
cobaya
pyccl
sacc
fgspectra
mflike @ git+https://github.com/simonsobs/lat_mflike@master
fgspectra>=1.1.0
syslibrary

[options.package_data]
soliket = *.yaml,*.bibtex,clusters/data/*,clusters/data/selFn_equD56/*,lensing/data/*.txt,lensing/data/*.fits,mflike/*.yaml,tests/*.yaml,data/xcorr_simulated/*.txt,data/CosmoPower/CP_paper/CMB/*.pkl
Expand Down
2 changes: 1 addition & 1 deletion soliket/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _bandpass_construction(self, **params):

if not hasattr(self.bandint_width, "__len__"):
self.bandint_width = np.full_like(self.freqs, self.bandint_width,
dtype=np.float)
dtype=float)
if np.any(np.array(self.bandint_width) > 0):
assert self.bandint_nsteps > 1, 'bandint_width and bandint_nsteps not \
coherent'
Expand Down
2 changes: 1 addition & 1 deletion soliket/mflike/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .mflike import MFLike
from .mflike import MFLike, TestMFLike
from .theoryforge_MFLike import TheoryForge_MFLike
7 changes: 7 additions & 0 deletions soliket/mflike/mflike.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,10 @@ def _get_power_spectra(self, cmbfg):
ps_vec[i] = clt

return ps_vec


class TestMFLike(MFLike):

_url = "https://portal.nersc.gov/cfs/sobs/users/MFLike_data"
filename = "v0.1_test"
install_options = {"download_url": f"{_url}/{filename}.tar.gz"}
106 changes: 40 additions & 66 deletions soliket/tests/test_mflike.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from packaging.version import Version

import camb
import mflike # noqa
sgiardie marked this conversation as resolved.
Show resolved Hide resolved
import soliket # noqa
from soliket.mflike import TestMFLike

import numpy as np

Expand Down Expand Up @@ -58,44 +58,31 @@
}


if Version(camb.__version__) < Version('1.3'):
chi2s = {"tt": 1384.5669,
"te": 1400.2760,
"ee": 1428.7597,
"tt-te-et-ee": 2412.9275}
if Version(camb.__version__) >= Version('1.4'):
chi2s = {"tt": 545.1257,
"te": 137.4146,
"ee": 167.9850,
"tt-te-et-ee": 790.5121}
else:
chi2s = {"tt": 737.8571537677649,
"te-et": 998.2730263280033,
"ee": 716.4015196388742,
"tt-te-et-ee": 2459.7250}
chi2s = {"tt": 544.9745,
"te-et": 152.6807,
"ee": 168.0953,
"tt-te-et-ee": 790.4124}

pre = "data_sacc_"
pre = "test_data_sacc_"


class MFLikeTest(unittest.TestCase):
orig = False

def setUp(self):
from cobaya.install import install

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

def get_mflike_type(self, as_string=False):
if self.orig:
t = "mflike.MFLike"
else:
t = "soliket.MFLike"

if as_string:
return t
else:
return eval(t)

@pytest.mark.skip(reason="don't want to install 300Mb of data!")
def test_mflike(self):

# As of now, there is not a mechanism
# in soliket to ensure there is .loglike that can be called like this
# w/out cobaya
Expand All @@ -109,69 +96,60 @@ def test_mflike(self):
cl_dict = {k: powers["total"][:, v] for
k, v in {"tt": 0, "ee": 1, "te": 3}.items()}

if not self.orig:

BP = soliket.BandPass()
FG = soliket.Foreground()
TF = soliket.TheoryForge_MFLike()
BP = soliket.BandPass()
FG = soliket.Foreground()
TF = soliket.TheoryForge_MFLike()

ell = np.arange(lmax + 1)
freqs = TF.freqs
requested_cls = TF.requested_cls
BP.freqs = freqs
ell = np.arange(lmax + 1)
freqs = TF.freqs
requested_cls = TF.requested_cls
BP.freqs = freqs

bandpass = BP._bandpass_construction(**nuisance_params)
bandpass = BP._bandpass_construction(**nuisance_params)

fg_dict = FG._get_foreground_model(requested_cls=requested_cls,
fg_dict = FG._get_foreground_model(requested_cls=requested_cls,
ell=ell,
freqs=freqs,
bandint_freqs=bandpass,
**nuisance_params)

dlobs_dict = TF.get_modified_theory(cl_dict, fg_dict, **nuisance_params)
dlobs_dict = TF.get_modified_theory(cl_dict, fg_dict, **nuisance_params)

for select, chi2 in chi2s.items():
MFLike = self.get_mflike_type()

my_mflike = MFLike(
my_mflike = TestMFLike(
{
"external": TestMFLike,
"packages_path": packages_path,
"data_folder": "MFLike/v0.6",
"data_folder": "TestMFLike",
"input_file": pre + "00000.fits",
"cov_Bbl_file": pre + "w_covar_and_Bbl.fits",
"defaults": {
"polarizations": select.upper().split("-"),
"scales": {
"TT": [2, 5000],
"TE": [2, 5000],
"ET": [2, 5000],
"EE": [2, 5000],
"TT": [2, 179],
"TE": [2, 179],
"ET": [2, 179],
"EE": [2, 179],
},
"symmetrize": False,
},
}
)

if not self.orig:
loglike = my_mflike.loglike(dlobs_dict)
else:
loglike = my_mflike.loglike(cl_dict, **nuisance_params)
loglike = my_mflike.loglike(dlobs_dict)

self.assertAlmostEqual(-2 * (loglike - my_mflike.logp_const), chi2, 2)

@pytest.mark.skip(reason="don't want to install 300Mb of data!")
#@pytest.mark.skip(reason="don't want to install 300Mb of data!")
def test_cobaya(self):
mflike_type = self.get_mflike_type(as_string=True)

# params = dict(cosmo_params)
# params['a_tSZ'] = 3.3

info = {
"likelihood": {
mflike_type: {
"data_folder": "MFLike/v0.6",
"soliket.mflike.TestMFLike": {
"datapath": os.path.join(packages_path, "data/TestMFLike"),
"data_folder": "TestMFLike",
"input_file": pre + "00000.fits",
"cov_Bbl_file": pre + "w_covar_and_Bbl.fits",
}
},
"theory": {"camb": {"extra_args": {"lens_potential_accuracy": 1},
Expand All @@ -180,17 +158,13 @@ def test_cobaya(self):
"modules": packages_path,
"debug": True,
}
if not self.orig:
info["theory"]["soliket.TheoryForge_MFLike"] = {'stop_at_error': True}
info["theory"]["soliket.Foreground"] = {'stop_at_error': True}
info["theory"]["soliket.BandPass"] = {'stop_at_error': True}

info["theory"]["soliket.TheoryForge_MFLike"] = {'stop_at_error': True}
info["theory"]["soliket.Foreground"] = {'stop_at_error': True}
info["theory"]["soliket.BandPass"] = {'stop_at_error': True}
from cobaya.model import get_model

model = get_model(info)
my_mflike = model.likelihood[mflike_type]
my_mflike = model.likelihood["soliket.mflike.TestMFLike"]
chi2 = -2 * (model.loglikes(nuisance_params)[0] - my_mflike.logp_const)
self.assertAlmostEqual(chi2[0], chi2s["tt-te-et-ee"], 2)


class MFLikeTestOrig(MFLikeTest):
orig = True
3 changes: 2 additions & 1 deletion soliket/tests/test_mflike.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
debug: True

likelihood:
soliket.mflike.MFLike:
soliket.mflike.TestMFLike:
data_folder: TestMFLike
input_file: data_sacc_00044.fits
cov_Bbl_file: data_sacc_w_covar_and_Bbl.fits
defaults:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extras =

commands =
pip freeze
cobaya-install planck_2018_highl_plik.TTTEEE_lite_native --no-set-global
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}

Expand Down