Skip to content

Commit

Permalink
win test working
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed Jul 26, 2024
1 parent 22cd36a commit 2099f54
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 72 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ exclude_lines = [
# Don't complain about IPython completion helper
"def _ipython_key_completions_",
]

[tool.pytest.ini_options]
markers = [
"require_ccl",
]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fuzzywuzzy
astropy
getdist
cobaya
pyccl
pyccl >= 3.0; platform_system!='Windows'
sacc
fgspectra>=1.1.0
syslibrary
Expand Down
18 changes: 12 additions & 6 deletions soliket/clusters/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

import numpy as np
import pandas as pd
import pyccl as ccl
from scipy.interpolate import interp1d

from soliket.clusters import massfunc as mf
from soliket.poisson import PoissonLikelihood

from .survey import SurveyData
from .sz_utils import szutils
from cobaya import LoggedError

C_KM_S = 2.99792e5

Expand All @@ -54,8 +54,14 @@ def initialize(self):

self.zarr = np.arange(0, 2, 0.05)
self.k = np.logspace(-4, np.log10(5), 200)
# self.mdef = ccl.halos.MassDef(500, 'critical')

# self.mdef = self.ccl.halos.MassDef(500, 'critical')

try:
import pyccl as ccl
except ImportError:
raise LoggedError(self.log, "Could not import ccl. Install pyccl to use ClusterLikelihood.")
else:
self.ccl = ccl
super().initialize()

def get_requirements(self):
Expand All @@ -82,11 +88,11 @@ def get_requirements(self):

def _get_sz_model(self, cosmo):
model = SZModel()
model.hmf = ccl.halos.MassFuncTinker08(cosmo, mass_def=self.mdef)
model.hmb = ccl.halos.HaloBiasTinker10(
model.hmf = self.ccl.halos.MassFuncTinker08(cosmo, mass_def=self.mdef)
model.hmb = self.ccl.halos.HaloBiasTinker10(
cosmo, mass_def=self.mdef, mass_def_strict=False
)
model.hmc = ccl.halos.HMCalculator(cosmo, model.hmf, model.hmb, self.mdef)
model.hmc = self.ccl.halos.HMCalculator(cosmo, model.hmf, model.hmb, self.mdef)
# model.szk = SZTracer(cosmo)
return model

Expand Down
2 changes: 1 addition & 1 deletion soliket/lensing/lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def initialize(self):
Cls = self._get_fiducial_Cls()

# Set the fiducial spectra
self.ls = np.arange(0, self.lmax)
self.ls = np.arange(0, self.lmax, dtype=np.longlong)
self.fcltt = Cls["tt"][0: self.lmax]
self.fclpp = Cls["pp"][0: self.lmax]
self.fclee = Cls["ee"][0: self.lmax]
Expand Down
9 changes: 9 additions & 0 deletions soliket/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import pytest
import sys


def pytest_collection_modifyitems(config, items):
if sys.platform.startswith('win'):
skip_on_windows = pytest.mark.skip(reason="Skipped on Windows")
for item in items:
if "require_ccl" in item.keywords:
item.add_marker(skip_on_windows)


@pytest.fixture
Expand Down
6 changes: 5 additions & 1 deletion soliket/tests/test_ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
Check that CCL works correctly.
"""
import numpy as np
import pytest
from cobaya.likelihood import Likelihood
from cobaya.model import get_model

pytestmark = pytest.mark.require_ccl


class CheckLike(Likelihood):
"""
This is a mock likelihood that simply forces soliket.CCL to calculate
a CCL object.
"""

def logp(self, **params_values):
ccl = self.provider.get_CCL() # noqa F841
ccl = self.provider.get_CCL() # noqa F841
return -1.0

def get_requirements(self):
Expand Down
8 changes: 4 additions & 4 deletions soliket/tests/test_clusters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import numpy as np
import pytest
from cobaya.model import get_model

pytestmark = pytest.mark.require_ccl

clusters_like_and_theory = {
"likelihood": {"soliket.ClusterLikelihood": {"stop_at_error": True}},
"theory": {
Expand All @@ -20,15 +23,13 @@


def test_clusters_model(evaluate_one_info, test_cosmology_params):

evaluate_one_info["params"] = test_cosmology_params
evaluate_one_info.update(clusters_like_and_theory)

model_fiducial = get_model(evaluate_one_info) # noqa F841
model_fiducial = get_model(evaluate_one_info) # noqa F841


def test_clusters_loglike(evaluate_one_info, test_cosmology_params):

evaluate_one_info["params"] = test_cosmology_params
evaluate_one_info.update(clusters_like_and_theory)

Expand All @@ -40,7 +41,6 @@ def test_clusters_loglike(evaluate_one_info, test_cosmology_params):


def test_clusters_n_expected(evaluate_one_info, test_cosmology_params):

evaluate_one_info["params"] = test_cosmology_params
evaluate_one_info.update(clusters_like_and_theory)

Expand Down
Loading

0 comments on commit 2099f54

Please sign in to comment.