Cobaya: creating an external theory class

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Heather Prince
Posts: 1
Joined: February 21 2020
Affiliation: Princeton University

Cobaya: creating an external theory class

Post by Heather Prince » February 21 2020

Are there any examples in the documentation of using your own external theory class?

I am trying to create a basic theory class to use with the Planck low-ell EE likelihood. Based on the docstring in external.py ("Just pass an instance of a class through the parameter ``instance``, containing the necessary methods for the likelihood to retrieve observables.") I have used the following input for the likelihood and theory:

Code: Select all

info_txt = r"""
likelihood:
  planck_2018_lowl.EE:
theory:
  external:
    instance: instance_of_my_theory_class
...
info = yaml_load(info_txt)
info['modules'] = '/Users/heatherp/cobaya-cosmo'
I then try to create a model:

Code: Select all

model = get_model(info)
but I get the error

Code: Select all

~/.local/lib/python3.6/site-packages/cobaya/likelihoods/_base_classes/_planck_clik_prototype.py in add_theory(self)
--> 126         self.theory.needs(Cl=dict(zip(self.requested_cls, self.l_maxs_cls)))
TypeError: needs() got an unexpected keyword argument 'Cl'
My method 'needs' does take Cl (I have also tried it with the more general **requirements in a similar way to what is done in _cosmo), so my best guess that theory is somehow set to the wrong class (possibly the superclass Theory, where needs takes 'arguments') to cause this error.

What is the right way to set up a Cobaya model with my external theory class?

Thanks!

Antony Lewis
Posts: 1941
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Cobaya: creating an external theory class

Post by Antony Lewis » February 24 2020

Use the devel Cobaya branch for external theory classes. You can't pass an instance as input: either give the package.ClassName name of your class, or make a dictionary in python and set "external" to be your class (not an instance of it).
You may find the test examples at

https://github.com/CobayaSampler/cobaya/blob/devel/tests/test_cosmo_multi_theory.py

useful to look at.

Post Reply