Cobaya: "Must set H0" error in camb.transfers theory.

Use of Healpix, camb, CLASS, cosmomc, compilers, etc.
Post Reply
Jack Lashner
Posts: 8
Joined: April 19 2020
Affiliation: University of Southern California

Cobaya: "Must set H0" error in camb.transfers theory.

Post by Jack Lashner » April 26 2020

I'm trying to test a simple cobaya theory that I'm working on, however I've recently been getting this error:

Code: Select all

 2020-04-26 11:11:25,133 [camb.transfers] *ERROR* Error at evaluation: CAMBError('Must set H0, cosmomc_theta or thetastar')
It's not clear to me where the input parameters for the Camb theory are set, but I assumed since I was providing H0 as a parameter in my input dict, this would be passed on to Camb. Here's the info dict I'm providing:

Code: Select all

zs = np.linspace(0, 2, 40)
info = {
    "debug": True,
    "params": {
        "omegabh2": 0.02225,
        "omegach2": 0.1198,
        "H0": 67.3,
        "tau": 0.06,
        "As": 2.2e-9,
        "ns": 0.96,
    },
    "likelihood": {
        'test_likelihood': fake_likelihood
    },
    "theory": {
        "camb": {
            "extra_args": {},
            'stop_at_error': True,
        },
        "cobayahacks.theories.hmf": {
            "zarr": zs,
            "hmf_kwargs": {}
        }
    },
}
Any ideas what could be causing this error? Thanks!

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

Re: Cobaya: "Must set H0" error in camb.transfers theory.

Post by Antony Lewis » April 27 2020

Is this using the latest devel branch? Not sure, could you send the complete example?

Jack Lashner
Posts: 8
Joined: April 19 2020
Affiliation: University of Southern California

Re: Cobaya: "Must set H0" error in camb.transfers theory.

Post by Jack Lashner » April 27 2020

So here's the script that I'm trying to run

Code: Select all

from cobaya.model import get_model
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt

zs = np.linspace(0, 2, 40)
def fake_likelihood(_theory={
    "Pk_grid": {
        "z": zs,
        "k_max": 5.0,
        "nonlinear": False,
        "vars_pairs": [["delta_tot", "delta_tot"]],
    }}):
    z, k, pk = _theory.get_Pk_grid()

    return np.sum(pk[0])


fiducial_params = {
    "omegabh2": 0.02225,
    "omegach2": 0.1198,
    "H0": 67.3,
    "tau": 0.06,
    "As": 2.2e-9,
    "ns": 0.96,
}

info = {
    "debug": True,
    "params": fiducial_params,
    "likelihood": {
        'test_likelihood': fake_likelihood
    },
    "theory": {
        "camb": {
            "extra_args": {},
            'stop_at_error': True
        },
        "cobayahacks.theories.hmf": {
            "zarr": zs,
            "hmf_kwargs": {}
        }
    },
}


m = get_model(info)

print(m.loglike())
cobayahacks.theories.hmf is a custom theory component that I'm writing here: https://github.com/jlashner/cobaya-hacks/blob/starting_hmf/cobayahacks/theories/hmf/hmf.py.

After playing around with this a bit more, I realized that if I comment out the input_parameters in the hmf theory, then Camb gets all of the input parameters that it needs. However if I keep the

Code: Select all

self.input_params = ['omegabh2', 'omegach2', 'H0']
line, then camb doesn't get those parameters in its calculate function. Does this make sense to you? Thanks for your help!

Jack Lashner
Posts: 8
Joined: April 19 2020
Affiliation: University of Southern California

Re: Cobaya: "Must set H0" error in camb.transfers theory.

Post by Jack Lashner » April 27 2020

Yes this is using the most recent devel branch.

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

Re: Cobaya: "Must set H0" error in camb.transfers theory.

Post by Antony Lewis » April 27 2020

You shouldn't normally assign to input_params like that in initialize. use e.g.

Code: Select all

class hmf(Theory):
    params = {'omegabh2':None, 'omegach2':None, 'H0':None}

    def initialize(self):
        self._hmf_kwargs = {
            'use_splined_growth': True
        }
        self._hmf_kwargs.update(self.hmf_kwargs)
        self.quants = ['dndm', 'rho_gtm', 'ngtm', 'power', 'growth_factor']
(There are other issues like self.zarr being undefined etc)

Jack Lashner
Posts: 8
Joined: April 19 2020
Affiliation: University of Southern California

Re: Cobaya: "Must set H0" error in camb.transfers theory.

Post by Jack Lashner » May 04 2020

Sorry I wasn't able to try this until now, but switching to the params dict gives me this error:

Code: Select all

2020-05-03 15:37:35,926 [input] *ERROR* cobayahacks.theories.hmf: any class can either have .yaml or class variables class_options or params, but not both
 2020-05-03 15:37:35,927 [input] *ERROR* Failed to get defaults for module or class 'cobayahacks.theories.hmf' [cobayahacks.theories.hmf: any class can either have .yaml or class variables class_options or params, but not both]
zarr and hmf_kwargs defaults are specified in the `hmf.yaml` file which I guess is conflicting with the params object. Do you know how to set the desired params from the yaml file? Or should I switch everything to the class-level params dict.

Also just wanted to point out that this code does run when switching the "camb" theory to "classy" in the input dict. I just wanted to compare with camb, but am getting these errors. Thanks!

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

Re: Cobaya: "Must set H0" error in camb.transfers theory.

Post by Antony Lewis » May 04 2020

Yes, just put params in .yaml, or move everything into class variables (as you prefer).

Post Reply