## CAMB: missing function in CAMBdata class?

Use of Healpix, camb, CLASS, cosmomc, compilers, etc.
Posts: 19
Joined: November 10 2016
Affiliation: FSU

### CAMB: missing function in CAMBdata class?

Hello everyone,

I have been using camb.get_matter_power_interpolator to obtain a 2D interpolator for the matter power spectrum, which I later use for angular galaxy overdensity power spectra.

I need to change my cosmology in order to get derivatives for Fisher matrix forecasts, so this needs to be run twice per parameter and that gets slow, so I was looking into ways to make this faster.

In the Python docs, I found the same function but from the CAMBdata class: CAMBdata.get_matter_power_interpolator, which I figured would be faster due to reusing previous calculations, but I'm getting an error that the class doesn't have that function. I'm using CAMB version 0.1.6.1.

Here is the error message I get:

Code: Select all

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-6db66903546c> in <module>()
11 results = camb.get_results(pars)
12
---> 13 interpolator = results.get_matter_power_interpolator()

AttributeError: 'CAMBdata' object has no attribute 'get_matter_power_interpolator'

CAMB version =  0.1.6.1
Any help will be appreciated.

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

### Re: CAMB: missing function in CAMBdata class?

The ReadTheDocs docs apply to the latest CAMB version from github.

Posts: 19
Joined: November 10 2016
Affiliation: FSU

### Re: CAMB: missing function in CAMBdata class?

Thank you, professor Lewis.

Posts: 19
Joined: November 10 2016
Affiliation: FSU

### Re: CAMB: missing function in CAMBdata class?

I have a follow up question, if I may.

I'm testing the difference between the two versions of get_matter_power_interpolator, and the CAMBdata version keeps crashing. The error message I see simply says "Error in halofit".

I would be very grateful if I could get some clarification on why this is happening.

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

### Re: CAMB: missing function in CAMBdata class?

Check the parameters look sensible and please give an explicit reproducible example if problems persist.

Code: Select all

print(pars)

Posts: 19
Joined: November 10 2016
Affiliation: FSU

### Re: CAMB: missing function in CAMBdata class?

Hello,

I believe I've isolated the problem to CAMBparams.set_matter_power.

When I don't supply an array of redshifts, I get this error from scipy:

Code: Select all

error: (mx>kx) failed for hidden mx: regrid_smth:mx=1
I understand this error to mean that an interpolator doesn't have enough data points.

I then tried calling set_matter_power again, giving an array of redshifts from down to from numpy:

Code: Select all

cambpars.set_matter_power\
( redshifts=np.linspace( 0.0, 1089.90, 100 ), kmax=1000.0, nonlinear=True\
, accurate_massive_neutrino_transfers=True )
Now I get 'Error in halofit' and the program crashes when calling CAMBdata.get_matter_power_interpolator (I don't even make it to evaluating it).

When I did print(pars), one thing jumps at me as being unusual (I'll spare you the long output, it's just a Planck 2015 cosmology):

Code: Select all

Transfer:
high_precision = 1
accurate_massive_neutrinos = 1
num_redshifts = 1
kmax = 1000.0
redshifts = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
PK_redshifts = [1089.9, 1078.8909090909092, 1067.8818181818183, 1056.8727272727274, 1045.8636363636365, 1034.8545454545456, 1023.8454545454546]
NLL_redshifts = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
PK_redshifts_index = [0, 0, 0, 0, 0, 0, 0]
NLL_redshifts_index = [0, 0, 0, 0, 0, 0, 0]
PK_num_redshifts = 100
NLL_num_redshifts = 0

As you can see, PK_redshifts only has 6 entries, when I passed 100.

With all the exact same parameters, except no call to CAMBparams.set_matter_power, camb.get_matter_power_interpolator doesn't fail, so I'm quite puzzled.

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

### Re: CAMB: missing function in CAMBdata class?

This works for me as an explicit example, with latest github camb installed and built:

Code: Select all

import camb
pars = camb.CAMBparams()
pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122)
pars.InitPower.set_params(ns=0.965, As=2e-9)
pars.set_matter_power(redshifts=np.linspace( 0.0, 1089.90, 100 ), kmax=1000.0, nonlinear=True\
, accurate_massive_neutrino_transfers=True )
data = camb.get_results(pars)
PK=data.get_matter_power_interpolator()
(the six entries is just because the print function only prints six to keep things readable).

However I doubt you actually want the matter power spectrum up to z=1000...

Posts: 19
Joined: November 10 2016
Affiliation: FSU

### Re: CAMB: missing function in CAMBdata class?

Your example runs without issue on my end. I did manage to make it crash with this minimal addition:

Code: Select all

import camb
import numpy as np

pars = camb.CAMBparams()
pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122)
pars.InitPower.set_params(ns=0.965, As=2e-9)
pars.set_matter_power(redshifts=np.linspace( 0.0, 1089.90, 100 ), kmax=1000.0, nonlinear=True\
, accurate_massive_neutrino_transfers=True )
data = camb.get_results(pars)
PK=data.get_matter_power_interpolator()

#trying to change 1 parameter and reuse the CAMBdata instance
#pars.set_cosmology( tau=0.066 ) #this is Planck 2015's value
data.set_params( pars )

PK_perturbed=data.get_matter_power_interpolator() #crashes

I tried changing a parameter that doesn't affect the matter power spectrum, in this case , and it crashed. I then tried commenting out the line where I change and it still crashes. This time, I don't get the "Error in halofit" message, however.

I'm interested in being able to reuse the CAMBdata instance that I first made, because I would like to get matter power spectra interpolators for slightly different cosmologies fast, so that I may obtain derivatives of power spectra for Fisher forecasts. At the moment, I'm using camb.get_matter_power_interpolator, and calling it every time I change the cosmology, which I imagine is what the new CAMBdata function is intended to speed up.

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

### Re: CAMB: missing function in CAMBdata class?

It won't make any significant difference to speed, unless you also want to use the computed transfer functions for something else other than getting the matter power interpolator object. I would use the wrapper functions (i.e. camb.get_matter_power_interpolator) unless you really want to dig in to how it works or need to optimize things like generating lots of results with the same cosmology but different initial power spectra (or generating both CL and P(k) interpolator objects).

If you set the parameters in CAMBdata, nothing is computed. You need to call calc_transfers() to actually get new data consistent with the new parameters. e.g. this will work

Code: Select all

import camb
pars = camb.CAMBparams()
pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122)
pars.InitPower.set_params(ns=0.965, As=2e-9)
pars.set_matter_power(redshifts=np.linspace( 0.0, 1089.90, 100 ), kmax=10.0, nonlinear=True\
, accurate_massive_neutrino_transfers=True )
data = camb.get_results(pars)
PK=data.get_matter_power_interpolator()
pars.set_cosmology( tau=0.066 ) #this will change ombh2, H0 etc back to defaults as well...
data.set_params( pars )
data.calc_transfers(pars)
PK_perturbed=data.get_matter_power_interpolator() 
Note that

Code: Select all

pars.set_cosmology( tau=0.066 )

will also change lots of other parameters back to their defaults (many unspecified parameters have default values).