Compute CAMB P(k)

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Katharina Borm
Posts: 6
Joined: February 18 2015
Affiliation: Argelander Institute for Astronomy, Univ. of Bonn

Compute CAMB P(k)

Post by Katharina Borm » February 18 2015

I am running into some problems/question marks of how to compute P(k) with CAMB. It would be great if someone has an idea for it.

Here is the problem: I implemented my own LogLikelihood in CosmoMC including P(k) from CAMB. Everything runs fine, if I call the MPK_Likelihood.
But is there a way to compute P(k) without calling the MPK_Likelihood? Right now CosmoMC is telling me to call a SetPk first? But how do I do this exactly?

Thanks a lot for any idea,
Katharina

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

Re: Compute CAMB P(k)

Post by Antony Lewis » February 19 2015

You just need to derived your own likelihood class (e.g. inheriting from TCosmoCalcLikelihood), and set %needs_powerspectra , %num_z, %needs_nonlinear_pk , etc appropriately depending on what data your likelihood actually needs. It's probably easiest to follow the MPKLikelihood example in mpk.f90 or WiggleZLikelihood in wigglez.f90 - copy and adapt as required for your likelihood (and make sure you add your likelihood to the global likelihood list).

Jason Dossett
Posts: 97
Joined: March 19 2010
Affiliation: The University of Texas at Dallas
Contact:

Compute CAMB P(k)

Post by Jason Dossett » February 19 2015

I have a little more detail in my reply here

Katharina Borm
Posts: 6
Joined: February 18 2015
Affiliation: Argelander Institute for Astronomy, Univ. of Bonn

Compute CAMB P(k)

Post by Katharina Borm » February 19 2015

Thanks a lot for the quick reply!
I already followed Jason's detailed description and it works out fine, as long as I set use_mpk = T in my .ini file.
However, at the moment I only want to compute my own likelihood without adding a second likelihood from MPK. So as soon as I set use_mpk = F, I am getting a segmentation fault and the error, that I need to call a SetPk.
I hope you have some hints for me on how to do so.

Thanks a lot

Jason Dossett
Posts: 97
Joined: March 19 2010
Affiliation: The University of Texas at Dallas
Contact:

Compute CAMB P(k)

Post by Jason Dossett » February 20 2015

Hi, I am trying to spot where things could be going wrong. Are you using exact_z's or just a max_z. If you are using a max_z, then you need to set num_z for your likelihood too. I forgot to put that in my referenced post. Note that if your max_z is greater than 0 you need num_z > 1.

-Jason

Katharina Borm
Posts: 6
Joined: February 18 2015
Affiliation: Argelander Institute for Astronomy, Univ. of Bonn

Compute CAMB P(k)

Post by Katharina Borm » February 20 2015

Hi! I want to compute the P(k) at only one exact_z=0. And this is how I set the parameters in my Likelihood_Add subroutine:

this%needs_powerspectra = .true.
this%needs_exact_z = .true.
this%num_z = 1
this%needs_nonlinear_pk = .false.

allocate (this%exact_z(this%num_z))
allocate (this%exact_z _index(this%num_z))

However, it seems like the definition this%num_z = 1 gives me a segmentation fault right away. When I un-comment this line and artificially put

allocate (this%exact_z(1))

it works as long as I set use_mpk=T. So maybe that's exactly where the problem comes from...?
Any idea where the error for the this%num_z = 1 might come from?

Thanks for the effort!

Jason Dossett
Posts: 97
Joined: March 19 2010
Affiliation: The University of Texas at Dallas
Contact:

Compute CAMB P(k)

Post by Jason Dossett » February 21 2015

Hi, I think the issue comes from you just wanting z=0 and using the needs_exact_z flag. This was something I did not account for in the my coding of the redshift sorting module and I think that is why you are getting a segmentation fault.

The best option with you just needing z=0 is to set

this%num_z = 1
and
this%max_z=0.d0

and remove your this%needs_exact_z settings (set it to false and remove the allocation flags), in that case the code should work just fine.

Let me know if that still does not work

I will look at getting a fix for using the exact_z flag with only 1 desired redshift and that redshift being 0.

Best,
Jason

Katharina Borm
Posts: 6
Joined: February 18 2015
Affiliation: Argelander Institute for Astronomy, Univ. of Bonn

Compute CAMB P(k)

Post by Katharina Borm » February 23 2015

Hi, thanks a lot for the many comments!

I changed my code according to your hints and now the command this%num_z=1 does not lead to a segmentation fault any longer. However, the segmentation fault still appears when I try to compute Pk%PowerAt.

Also, my vectors Pk%x for the wavenumbers and Pk%y for the redshifts are empty. I had the impression, that with defining this%num_z, this%max_z etc. these vectors are filled by camb "automatically".
What am I missing at this point? Do I need to allocate and fill these vectors myself?

Thanks again for your efforts!

Katharina

Jason Dossett
Posts: 97
Joined: March 19 2010
Affiliation: The University of Texas at Dallas
Contact:

Compute CAMB P(k)

Post by Jason Dossett » February 24 2015

Hi Katharina,

I have looked through the existing code, and it is not immediately clear to me why the issue you are having is arising. Did you want me to take a look at your code? You can email it to me if you don't want it posted publicly on the forum.

-Jason

Post Reply