Bindings¶
- class desilike.bindings.base.BaseLikelihoodGenerator(factory, dirname='.')[source]¶
Bases:
BaseClassBase class to write necessary files for likelihoods to be imported by external inference codes.
Initialize
BaseLikelihoodGenerator.- Parameters:
factory (callable) – A callable that returns a likelihood object adapted to the external inference code, and takes as input a callable that returns a
BaseLikelihood, a dictionary of optional arguments (passed to the latter callable), and the name of the module where it is called. and returns a likelihood object adapted to the external inference code.dirname (str, Path, default='.') – Base directory for the file structure: bindings are saved in dirname/{code}_bindings/, with {code} the directory where
factoryis defined: ‘cobaya’, ‘cosmosis’, ‘montepython’…
- get_code(likelihood, name_like=None, kw_like=None, module=None, fn=None, **kwargs)[source]¶
Internal method to write code to generate likelihood object to be imported by the external inference code.
- Parameters:
likelihood (type, callable) – Callable that returns a
BaseLikelihood, given some optional arguments (seekw_like).name_like (str, default=None) – Likelihood name, defaults to
likelihoodname.kw_like (dict, default=None) – Optional arguments for
likelihood.module (str, default=None) – Full module name where
likelihoodis defined. IfNone, the full module name is searched withfind_module_from_file(); if not in a package, absolute path to file wherelikelihoodobject is defined will be used to import it in the generated code.fn (Path, str, default=None) – Where to save the likelihood definition for the inference code. It is prefixed by
dirname.**kwargs (dict) – Other optional arguments for likelihood factory, e.g.
kw_cobaya.
- Returns:
cls, name, fn, code – Callable that generates
BaseLikelihood, likelihood name, file name where the code is to be written, and code itself.- Return type:
callable, str, str
- desilike.bindings.base.find_module_from_file(fn)[source]¶
Return full module name corresponding to
fn. It first checks if there is an ‘__init__.py’ file in the same directory asfn, and if so, it recursively finds the module name of that directory and combines it with the basename offn.>>> find_module_from_file('base.py') 'desilike.bindings.base'
If there is no ‘__init__.py’ in the same directory as the given file, it returns
None.