Skip to content

Commit

Permalink
Issue/592/ccl v2.7 (#593)
Browse files Browse the repository at this point in the history
* Use CCL 2.7.1dev9

* add check for CCL versions

* Update README, INSTALL and CONTRIBUTING

* Check UnlockInstance directly

* Update version to 1.8.2

---------

Co-authored-by: m-aguena <michel.aguena@gmail.com>
Co-authored-by: m-aguena <aguena@if.usp.br>
Co-authored-by: m-aguena <aguena@apc.in2p3.fr>
  • Loading branch information
4 people authored Jun 13, 2023
1 parent 09d54d0 commit c6cf806
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ NOTE: Code is not complete without unit tests and documentation. Please ensure t

To test this, first install the code by running `python setup.py install --user` (required after any change whatsoever to the `.py` files in `clmm/` directory). To run all of the unit tests, run `pytest` in the root package directory. To test the docs, in the root package directory after installing, run `./update_docs`. This script both deletes the old compiled documentation files and rebuilds them. You can view the compiled docs by running `open docs/_build/html/index.html`.

NOTE2: If the changes you are making affect which CCL versions are compatible with the code,
please update `clmm/theory/_ccl_supported_versions.py`, `README.md` and `INSTALL.md` accordingly.

## Adding documentation <a name="adding_documentation"></a>

If you are adding documentation either in the form of example jupyter notebooks or new python modules, your documentation will need to compile for our online documentation hosted by the LSST-DESC website: http://lsstdesc.org/CLMM/
Expand Down
5 changes: 4 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ To create a specific conda environment for CLMM, we recommend you to check the b
[Access to the proper environment on cori.nersc.gov](#access_to_the_proper_environment_on_cori).

### Theory backend installation
First, choose and install a theory backend for CLMM. This can be CCL (v2.1.0 or later) or NumCosmo (v0.15 or later), or cluster_toolkit and they are installable as follows.
First, choose and install a theory backend for CLMM.
This can be CCL (versions between 2.6.0 and 2.7.1.dev9+g1a351df6),
NumCosmo (v0.15 or later),
or cluster_toolkit and they are installable as follows.

To install CCL as the theory/cosmology backend, run

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ CLMM requires Python version 3.8 or later. CLMM has the following dependencies:
For the theoretical predictions of the signal, CLMM relies on existing libraries and **at least one of the following must be installed as well**:

- [cluster-toolkit](https://cluster-toolkit.readthedocs.io/en/latest/)
- [CCL](https://ccl.readthedocs.io/en/latest/) (v2.6 or later)
- [CCL](https://ccl.readthedocs.io/en/latest/) (versions between 2.6.0 and 2.7.1.dev9+g1a351df6)
- [NumCosmo](https://numcosmo.github.io/) (v0.15 or later)


(See the [INSTALL documentation](INSTALL.md) for more detailed installation instructions.)

For developers, you will also need to install:
Expand Down
2 changes: 1 addition & 1 deletion clmm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
)
from . import support

__version__ = "1.8.1"
__version__ = "1.8.2"
5 changes: 5 additions & 0 deletions clmm/theory/_ccl_supported_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""@file _ccl_supported_versions.py
Versions of CCL supported by the current CLMM version
"""
VMIN = '2.6.0'
VMAX = '2.7.1.dev9+g1a351df6'
16 changes: 13 additions & 3 deletions clmm/theory/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
from ..cosmology.ccl import CCLCosmology
from .parent_class import CLMModeling

# Check which versions of ccl are currently supported
from . import _ccl_supported_versions

if parse(ccl.__version__) < parse(_ccl_supported_versions.VMIN) or parse(ccl.__version__) > parse(
_ccl_supported_versions.VMAX
):
raise EnvironmentError(
f"Current CCL version ({ccl.__version__}) not supported by CLMM. "
f"It must be between {_ccl_supported_versions.VMIN} and {_ccl_supported_versions.VMAX}."
)


class CCLCLMModeling(CLMModeling):
r"""Object with functions for halo mass modeling
Expand Down Expand Up @@ -89,9 +100,6 @@ def _update_halo_density_profile(self):
"""updates halo density profile with set internal properties"""
# prepare mdef object
self.mdef = ccl.halos.MassDef(self.delta_mdef, self.mdef_dict[self.massdef])
# adjust it for ccl version > 2.6.1
if parse(ccl.__version__) >= parse("2.6.2dev7"):
ccl.UnlockInstance.Funlock(type(self.mdef), "_concentration_init", True)
# setting concentration (also updates hdpm)
self.cdelta = self.cdelta if self.hdpm else 4.0 # ccl always needs an input concentration

Expand All @@ -107,6 +115,8 @@ def _set_concentration(self, cdelta):
"""set concentration. Also sets/updates hdpm"""
# pylint: disable=protected-access
self.conc = ccl.halos.ConcentrationConstant(c=cdelta, mdef=self.mdef)
if hasattr(ccl, 'UnlockInstance'):
ccl.UnlockInstance.Funlock(type(self.mdef), "_concentration_init", True)
self.mdef._concentration_init(self.conc)
self.hdpm = self.hdpm_dict[self.halo_profile_model](
self.conc, **self.hdpm_opts[self.halo_profile_model]
Expand Down
51 changes: 51 additions & 0 deletions tests/test_theory_be.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for backend of theory.py"""
import importlib
import pytest
from numpy.testing import assert_raises


Expand Down Expand Up @@ -48,3 +49,53 @@ def nie():
# restore original code that will be monkeypatched here
clmm.theory.Modeling = Modeling_safe
clmm.theory.__backends = backends_safe


def get_ccl_versions_from_md(filename):
lines = [l for l in open(filename).readlines() if "CCL" and "versions between" in l]
if len(lines) != 1:
raise SyntaxError(f"Number of lines with CCL version (={len(lines)}) is not 1.")
vmin = lines[0].split("versions between ")[1].split(" and ")[0]
vmax = lines[0].split(" and ")[1].split(")")[0]
return vmin, vmax


def test_documented_ccl_versions_consistency():
from clmm.theory import _ccl_supported_versions

# Compare to readme
vmin, vmax = get_ccl_versions_from_md("README.md")
assert vmin == _ccl_supported_versions.VMIN
assert vmax == _ccl_supported_versions.VMAX

# Compare to install
vmin, vmax = get_ccl_versions_from_md("INSTALL.md")
assert vmin == _ccl_supported_versions.VMIN
assert vmax == _ccl_supported_versions.VMAX


def test_clmm_versioning_error():
import os

try:
import clmm

avail = clmm.theory.backend_is_available("ccl")
except ValueError:
pytest.skip(f"CCL backend not available'.")

if avail:
from clmm.theory import _ccl_supported_versions

vmin_safe = _ccl_supported_versions.VMIN
vmax_safe = _ccl_supported_versions.VMAX

_ccl_supported_versions.VMIN = "999"
_ccl_supported_versions.VMAX = "999"

os.environ["CLMM_MODELING_BACKEND"] = "ccl"

assert_raises(EnvironmentError, importlib.reload, clmm.theory.ccl)

_ccl_supported_versions.VMIN = vmin_safe
_ccl_supported_versions.VMAX = vmax_safe

0 comments on commit c6cf806

Please sign in to comment.