Skip to content

Commit

Permalink
classy: fix for >v3.3, backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusTorrado committed Mar 3, 2025
1 parent 8f18b20 commit cac4ebf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
16 changes: 11 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
## 3.5.5
## 3.5.5 (unreleased)

- Option for stricter run-time input type checking (#388)
- Detect and fix incomplete last lines when resuming or minimizing from existing runs (#306, #378)
- Added functions module and refactored some numerical functions into it
- Tidier numpy2 outputs and other minor fixes

## 3.5.4
### Cosmology

#### CLASS

- Regression: no multiple local installs after v3.3 (see #404)

## 3.5.4 – 2024-08-14

- Allow classes to have both yaml and class attributes as long as no duplicate keys
- Added get_modified_defaults() class method to cobaya components to dynamically set/modify defaults

### Cosmology
- Option to return lensed scalar Cl's from CAMB (without tensors) (thanks @kimmywu})

## 3.5.3
## 3.5.3 – 2024-08-09

- added --allow-changes option to cobaya-run to allow changes in the input file when resuming or minimizing
- Updates for deprecation warnings
- Minor optimization refactor and doc update

## 3.5.2
## 3.5.2 – 2024-08-09

- Updates for numpy 2 and other compatibility fixes
- Fixes #357, #358, #360, #361, #362, #368
- Added _fast_chi_squared method to base class InstallableLikelihood

## 3.5.1
## 3.5.1 – 2024-04-25

### General

Expand Down
3 changes: 1 addition & 2 deletions cobaya/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ def _bare_load_external_module(name, path=None, min_version=None, reload=False,
Loads an external module ``name``.
If a ``path`` is given, it looks for an installation there and fails if it does
not find one. If ``path`` is not given, tries a global
``import``.
not find one. If ``path`` is not given, tries a global ``import``.
Raises :class:`component.ComponetNotInstalledError` if the module could not be
imported.
Expand Down
45 changes: 38 additions & 7 deletions cobaya/theories/classy/classy.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,25 @@ def initialize(self):
install_path = self.get_path(self.packages_path)
min_version = None if self.ignore_obsolete else self._min_classy_version
try:
self.classy_module = load_external_module(
"classy", path=self.path, install_path=install_path,
min_version=min_version, get_import_path=self.get_import_path,
logger=self.log, not_installed_level="debug")
try:
self.classy_module = load_external_module(
"classy", path=self.path, install_path=install_path,
min_version=min_version, get_import_path=self.get_import_path,
logger=self.log, not_installed_level="debug")
# Regression introduced by CLASS v3.3 -- Deprecate CLASS <v3.3 eventually
except (VersionCheckError,ComponentNotInstalledError) as ni_internal_excpt:
try:
self.classy_module = load_external_module(
"classy", path=self.path, install_path=install_path,
min_version=min_version, get_import_path=self.get_import_path_old,
logger=self.log, not_installed_level="debug")
# Only runs if passed:
self.log.warning(
"Detected an old CLASS version (<3.3). "
"Please update: support for this will be deprecated soon."
)
except ComponentNotInstalledError:
raise ni_internal_excpt
except VersionCheckError as vc_excpt:
raise VersionCheckError(
str(vc_excpt) + " If you are using CLASS unmodified, upgrade with"
Expand Down Expand Up @@ -748,6 +763,10 @@ def get_path(cls, path):

@staticmethod
def get_import_path(path):
return get_compiled_import_path(path)

@staticmethod
def get_import_path_old(path):
return get_compiled_import_path(os.path.join(path, "python"))

@classmethod
Expand All @@ -765,8 +784,22 @@ def is_installed(cls, reload=False, **kwargs):
"classy", path=kwargs["path"], get_import_path=cls.get_import_path,
min_version=cls._min_classy_version, reload=reload,
logger=get_logger(cls.__name__), not_installed_level="debug"))
# Regression introduced by CLASS v3.3 -- Deprecate CLASS <v3.3 eventually
except ComponentNotInstalledError:
return False
try:
success = bool(load_external_module(
"classy", path=kwargs["path"],
get_import_path=cls.get_import_path_old,
min_version=cls._min_classy_version, reload=reload,
logger=get_logger(cls.__name__), not_installed_level="debug"))
# Only runs if passed:
get_logger(cls.__name__).warning(
"Detected an old CLASS version (<3.3). "
"Please update: support for this will be deprecated soon."
)
return success
except ComponentNotInstalledError:
return False

@classmethod
def install(cls, path=None, code=True, no_progress_bars=False, **_kwargs):
Expand All @@ -775,8 +808,6 @@ def install(cls, path=None, code=True, no_progress_bars=False, **_kwargs):
log.info("Code not requested. Nothing to do.")
return True
log.info("Installing pre-requisites...")
# TODO: remove version restriction below when this issue is fixed:
# https://github.com/lesgourg/class_public/issues/531
exit_status = pip_install("cython")
if exit_status:
log.error("Could not install pre-requisite: cython")
Expand Down

0 comments on commit cac4ebf

Please sign in to comment.