Skip to content

Commit

Permalink
camb version check for new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed Feb 23, 2022
1 parent d26e833 commit c459615
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions cobaya/theories/camb/camb.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
from cobaya.log import LoggedError, get_logger
from cobaya.install import download_github_release, check_gcc_version, NotInstalledError
from cobaya.tools import getfullargspec, get_class_methods, get_properties, load_module, \
VersionCheckError, str_to_list, Pool1D, Pool2D, PoolND
VersionCheckError, check_component_version, str_to_list, Pool1D, Pool2D, PoolND
from cobaya.theory import HelperTheory
from cobaya.typing import InfoDict, empty_dict

Expand Down Expand Up @@ -354,6 +354,7 @@ def must_provide(self, **requirements):
elif k in ("angular_diameter_distance", "comoving_radial_distance"):
self.set_collector_with_z_pool(k, v["z"], getattr(CAMBdata, k))
elif k == "angular_diameter_distance_2":
check_component_version(self.camb, '1.3.5')
self.set_collector_with_z_pool(
k, v["z_pairs"], CAMBdata.angular_diameter_distance2, d=2)
elif k == "sigma8_z":
Expand All @@ -368,7 +369,7 @@ def must_provide(self, **requirements):
self.collectors[k] = Collector(
method=CAMBdata.get_fsigma8,
kwargs={},
post=(lambda* x: x[::-1])) # returned in inverse order
post=(lambda *x: x[::-1])) # returned in inverse order
self.needs_perts = True
elif isinstance(k, tuple) and k[0] == "sigma_R":
kwargs = v.copy()
Expand Down
3 changes: 2 additions & 1 deletion cobaya/theories/classy/classy.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def add_z_for_matter_power(self, z):
self.extra_args["z_pk"] = " ".join(["%g" % zi for zi in self.z_for_matter_power])

def set_collector_with_z_pool(self, k, zs, method, args=(), args_names=(),
kwargs=empty_dict, arg_array=None, post=None, d=1):
kwargs=None, arg_array=None, post=None, d=1):
"""
Creates a collector for a z-dependent quantity, keeping track of the pool of z's.
Expand All @@ -355,6 +355,7 @@ def set_collector_with_z_pool(self, k, zs, method, args=(), args_names=(),
Pool = {1: Pool1D, 2: Pool2D}[d]
z_pool = Pool(zs)
# Insert z as arg or kwarg
kwargs = kwargs or {}
if d == 1 and "z" in kwargs:
kwargs = deepcopy(kwargs)
kwargs["z"] = z_pool.values
Expand Down
2 changes: 1 addition & 1 deletion cobaya/theories/cosmo/boltzmannbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def must_provide(self, **requirements):
r"""
Specifies the quantities that this Boltzmann code is requested to compute.
Typical requisites in Cosmology (as keywords, case insensitive):
Typical requisites in Cosmology (as keywords, case-insensitive):
- ``Cl={...}``: CMB lensed power spectra, as a dictionary ``{[spectrum]:
l_max}``, where the possible spectra are combinations of ``"t"``, ``"e"``,
Expand Down
2 changes: 1 addition & 1 deletion cobaya/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def must_provide(self, **requirements) -> Union[None, InfoDict, Sequence[str],
Function to be called specifying any output products that are needed and hence
should be calculated by this component depending..
The requirements argument is a requirement name with any optional parameters.
The ``requirements'' argument is a requirement name with any optional parameters.
This function may be called more than once with different requirements.
:return: optional dictionary (or list of requirement name, option tuples) of
Expand Down
14 changes: 7 additions & 7 deletions cobaya/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def find_with_regexp(regexp, root, walk_tree=False):
Returns all files found which are compatible with the given regexp in directory root,
including their path in their name.
Set `walk_tree=True` if there is more that one directory level (default: `False`).
Set walk_tree=True if there is more than one directory level (default: `False`).
"""
try:
if walk_tree:
Expand Down Expand Up @@ -991,21 +991,21 @@ def write_config_file(config_info, append=True):
yaml_dump_file(os.path.join(get_config_path(), packages_path_config_file),
info, error_if_exists=False)
except Exception as e:
log.error("Could not write the external packages installation path into the "
log.error("Could not write the external packages' installation path into the "
"config file. Reason: %r", str(e))


def load_packages_path_from_config_file():
"""
Returns the external packages path stored in the config file,
Returns the external packages' path stored in the config file,
or `None` if it can't be found.
"""
return load_config_file().get(packages_path_input)


def write_packages_path_in_config_file(packages_path):
"""
Writes the external packages installation path into the config file.
Writes the external packages' installation path into the config file.
Relative paths are converted into absolute ones.
"""
Expand All @@ -1015,11 +1015,11 @@ def write_packages_path_in_config_file(packages_path):
def resolve_packages_path(infos=None):
# noinspection PyStatementEffect
"""
Gets the external packages installation path given some infos.
Gets the external packages' installation path given some infos.
If more than one occurrence of the external packages path in the infos,
raises an error.
If there is no external packages path defined in the given infos,
If there is no external packages' path defined in the given infos,
defaults to the env variable `%s`, and in its absence to that stored
in the config file.
Expand Down Expand Up @@ -1103,7 +1103,7 @@ class PoolND(ABC):

values: np.ndarray

def __init__(self, values=[],
def __init__(self, values=(),
rtol_min=1e-5, rtol_max=1e-3, atol_min=1e-8, atol_max=1e-6, logger=None):
assert values is not None and len(values) != 0, \
"Pool needs to be initialised with at least one value."
Expand Down
1 change: 0 additions & 1 deletion tests/test_cosmo_bao.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from copy import deepcopy
import pytest

from cobaya.tools import get_class

Expand Down

0 comments on commit c459615

Please sign in to comment.