Base components

CobayaComponent class

class component.CobayaComponent(info: Mapping[str, Any] = mappingproxy({}), name: Optional[str] = None, timing: Optional[bool] = None, packages_path: Optional[str] = None, initialize=True, standalone=True)

Bases: cobaya.log.HasLogger, cobaya.input.HasDefaults

Base class for a theory, likelihood or sampler with associated .yaml parameter file that can set attributes.

get_name() → str

Get the name. This is usually set by the name used in the input .yaml, but otherwise defaults to the fully-qualified class name.

Returns:name string

Finalizes the class, if something needs to be cleaned up.


Can use this to define any default instance attributes before setting to the input dictionary (from inputs or defaults)


Initializes the class (called from __init__, before other initializations).

get_version() → Union[None, str, Dict[str, Any]]

Get version information for this component.

Returns:string or dict of values or None

Whether to track version information for this component

classmethod compare_versions(version_a, version_b, equal=True)

Checks whether version_a is equal or higher than version_b.

For strictly higher, pass equal=False (default: True).


ComponentCollection class

class component.ComponentCollection

Base class for a dictionary of components (e.g. likelihoods or theories)

get_versions(add_version_field=False) → Dict[str, Any]

Get version dictionary :return: dictionary of versions for all components

get_speeds(ignore_sub=False) → Dict[str, Any]

Get speeds dictionary :return: dictionary of versions for all components

Provider class

class theory.Provider(model, requirement_providers: Dict[str, theory.Theory])

Class used to retrieve computed requirements. Just passes on get_X and get_param methods to the component assigned to compute them.

For get_param it will also take values directly from the current sampling parameters if the parameter is defined there.

get_param(param: Union[str, Iterable[str]]) → Union[float, List[float]]

Returns the value of a derived (or sampled) parameter. If it is not a sampled parameter it calls Theory.get_param() on component assigned to compute this derived parameter.

Parameters:param – parameter name, or a list of parameter names
Returns:value of parameter, or list of parameter values

HasDefaults class

class input.HasDefaults

Base class for components that can read settings from a .yaml file. Class methods provide the methods needed to get the defaults information and associated data.

classmethod get_qualified_class_name() → str

Get the distinct shortest reference name for the class of the form module.ClassName or module.submodule.ClassName etc. For Cobaya components the name is relative to subpackage for the relevant kind of class (e.g. Likelihood names are relative to cobaya.likelihoods).

For external classes it loads the shortest fully qualified name of the form package.ClassName or package.module.ClassName or package.subpackage.module.ClassName, etc.

classmethod get_class_path() → str

Get the file path for the class.

classmethod get_file_base_name() → str

Gets the string used as the name for .yaml, .bib files, typically the class name or a un-CamelCased class name

classmethod get_yaml_file() → Optional[str]

Gets the file name of the .yaml file for this component if it exists on file (otherwise None).


Returns a short description of the class. By default, returns the class’ docstring.

You can redefine this method to dynamically generate the description based on the class initialisation info (see e.g. the source code of MCMC’s class method _get_desc()).

classmethod get_bibtex() → Optional[str]

Get the content of .bibtex file for this component. If no specific bibtex from this class, it will return the result from an inherited class if that provides bibtex.

classmethod get_class_options(input_options=mappingproxy({})) → Dict[str, Any]

Returns dictionary of names and values for class variables that can also be input and output in yaml files, by default it takes all the (non-inherited and non-private) attributes of the class excluding known specials.

Could be overridden using input_options to dynamically generate defaults, e.g. a set of input parameters generated depending on the input_options.

Parameters:input_options – optional dictionary of input parameters
Returns:dict of names and values
classmethod get_defaults(return_yaml=False, yaml_expand_defaults=True, input_options=mappingproxy({}))

Return defaults for this component_or_class, with syntax:

option: value

  [...]  # if required

  [...]  # if required

If keyword return_yaml is set to True, it returns literally that, whereas if False (default), it returns the corresponding Python dict.

Note that in external components installed as zip_safe=True packages files cannot be accessed directly. In this case using !default .yaml includes currently does not work.

Also note that if you return a dictionary it may be modified (return a deep copy if you want to keep it).

if yaml_expand_defaults then !default: file includes will be expanded

input_options may be a dictionary of input options, e.g. in case default params are dynamically dependent on an input variable