Cobaya: difficulty with "nonu" power spectrum in cobaya.run

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Alex Krolewski
Posts: 11
Joined: November 07 2019
Affiliation: UC Berkeley

Cobaya: difficulty with "nonu" power spectrum in cobaya.run

Post by Alex Krolewski » November 07 2019

I'm trying to run a custom likelihood in cobaya that takes the CAMB matter power spectrum as input. However, I'm running into some issues using the "nonu" power spectrum. Even though I specify 'vars_pairs': [['delta_nonu','delta_nonu']], I get the following error when I call cobaya.run:

Traceback (most recent call last):
File "/global/homes/a/akrolew/miniconda2/lib/python2.7/site-packages/cobaya/likelihood.py", line 240, in logp
return self.external_function(**params_values)
File "<ipython-input-8-b58d4cc88ea2>", line 12, in clkg_likelihood
Pk_interpolator = _theory.get_Pk_interpolator()['delta_nonu_delta_nonu'].P
KeyError: 'delta_nonu_delta_nonu'

Even though I requested a power spectrum with delta_nonu as the variables, I got a power spectrum with delta_tot (i.e. the key "delta_tot_delta_tot" exists but "delta_nonu_delta_nonu" does not, even though I asked for the latter).

I *don't* get this error when I call model.loglike()--only when I call cobaya.run with this model.

I'm running cobaya 2.0.3. Here's a minimal working example showing the problem:

Code: Select all

import numpy as np
from cobaya.model import get_model

modules_path = '/global/cscratch1/sd/akrolew/cosmo_modules/'

	
def clkg_likelihood(
	_theory={'Pk_interpolator': {'z': np.linspace(0,4,41), 'k_max': 100.0, 'nonlinear': True,'hubble_units': True,'k_hunit': True, 'vars_pairs': [['delta_nonu','delta_nonu']]}}):
	print _theory.get_Pk_interpolator()
	Pk_interpolator = _theory.get_Pk_interpolator()['delta_nonu_delta_nonu'].P
	
	k = np.logspace(-3,1,100)
	return np.sum(Pk_interpolator(0.0,k))

	
	
info = {
    'params': {
        # Fixed
        'ombh2': 0.02242, 'omch2': 0.11933, 'H0': 67.66, 'tau': 0.0561,
        'mnu': 0.06, 'nnu': 3.046, 'num_massive_neutrinos': 1, 'ns': 0.9665, 'YHe': 0.2454,
        # Sampled
        'As': {
            'prior': {'min': 1e-9, 'max': 3e-9},
            'latex': r'$A_s$'}},
    'likelihood': {'clkg_likelihood': clkg_likelihood},
    'theory': {'camb': {'stop_at_error': True}},
    'sampler': {'mcmc': None},  # or polychord...
    'debug': True,
    'modules': modules_path,
    'output': 'chains/test_clkg'}
    
# Activate timing (we will use it later)
info['timing'] = True

from cobaya.model import get_model
model = get_model(info)

As = np.linspace(1e-9,3e-9,10)
likes = [model.loglike({'As': A})[0] for A in As]


info['likelihood']['clkg_likelihood'] = {
    'external': clkg_likelihood,
    'speed': 20}
    
from cobaya.run import run
run(info)
which gives an error on the final line (run(info)) but not on the model.loglike call.

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

Re: Cobaya: difficulty with "nonu" power spectrum in cobaya.run

Post by Antony Lewis » November 07 2019

I think this may be a known issue - try making a new info before calling run.

Alex Krolewski
Posts: 11
Joined: November 07 2019
Affiliation: UC Berkeley

Re: Cobaya: difficulty with "nonu" power spectrum in cobaya.run

Post by Alex Krolewski » November 08 2019

Great, thanks! This solves the issue.

Post Reply