Skip to content

Commit

Permalink
allow classes to have yaml and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed Aug 14, 2024
1 parent 8a45af6 commit 0cc707a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.5.4

- allow classes to have both yaml and class attributes as long as no duplicate keys
- Option to return lensed scalar Cl's from CAMB (without tensors) (thanks @kimmywu})

## 3.5.3

- added --allow-changes option to cobaya-run to allow changes in the input file when resuming or minimizing
Expand Down
2 changes: 1 addition & 1 deletion cobaya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


__author__ = "Jesus Torrado and Antony Lewis"
__version__ = "3.5.3"
__version__ = "3.5.4"
__obsolete__ = False
__year__ = "2024"
__url__ = "https://cobaya.readthedocs.io"
18 changes: 11 additions & 7 deletions cobaya/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cobaya.tools import resolve_packages_path, load_module, get_base_classes, \
get_internal_class_component_name, deepcopy_where_possible, VersionCheckError
from cobaya.conventions import kinds, cobaya_package, reserved_attributes
from cobaya.yaml import yaml_load_file, yaml_dump
from cobaya.yaml import yaml_load_file, yaml_dump, yaml_load
from cobaya.mpi import is_main_process


Expand Down Expand Up @@ -271,12 +271,16 @@ def get_defaults(cls, return_yaml=False, yaml_expand_defaults=True,
yaml_text = cls.get_associated_file_content('.yaml')
options = cls.get_class_options(input_options=input_options)
if options and yaml_text:
log = get_logger(cls.get_qualified_class_name())
raise LoggedError(log,
"%s: any class can either have .yaml or class variables "
"but not both (type declarations without values are fine "
"also with yaml file). You have class attributes: %s",
cls.get_qualified_class_name(), list(options))
yaml_options = yaml_load(yaml_text)
if both := set(yaml_options).intersection(options):
raise LoggedError(get_logger(cls.get_qualified_class_name()),
"%s: class has .yaml and class variables/options "
"that define the same keys: %s \n"
"(type declarations without values are fine "
"with yaml file as well).",
cls.get_qualified_class_name(), list(both))
options |= yaml_options
yaml_text = None
if return_yaml and not yaml_expand_defaults:
return yaml_text or ""
this_defaults = yaml_load_file(cls.get_yaml_file(), yaml_text) \
Expand Down

0 comments on commit 0cc707a

Please sign in to comment.