tilmantroester / pyhmcode

Augmented halo model for accurate non-linear matter power spectrum calculations
MIT License
4 stars 5 forks source link

Order matters (unexpectedly?) when setting up linear power and cosmology parameters #10

Closed jessmuir closed 1 year ago

jessmuir commented 1 year ago

Hi! I'm not sure if this is a bug or just user error but I wanted to flag this just in case (at the very least it might signal useful documentation to add):

I've been exploring using this module as an option for separating CAMB calculations of linear P(k,z) and the nonlinear calculation into separate steps in modeling pipeline. As part of that, I've been comparing the two-step CAMB-then-pyhmcode calculations to a single-step CAMB run using the built-in HMCode. In doing so I've found that the results of this comparison depends on the order of how different parts of the pyhmcode.Cosmology() object are set up.

If I follow your example notebook directly, the one-step and two-step setups match when doing:

cosm_hm = pyhmcode.Cosmology()
cosm_hm.om_m = 0.3
#[ set other cosmology parameters]
cosm_hm.set_linear_power_spectrum(k, z, linpk)

However, things do not match if instead I do something like this, with the set_linear_power_spectrum before parameters (as I was initially trying):

cosm_hm = pyhmcode.Cosmology()
cosm_hm.set_linear_power_spectrum(k, z, linpk)
cosm_hm.om_m = 0.3
#[ set other cosmology parameters]

This results in offsets between the one-step and two-step calculations even at linear scales, with bigger differences at higher redshifts.

tilmantroester commented 1 year ago

Thanks for catching this. Could you try afc6bc113762d7735d054460b6b7ed74aaf4d835 and let me know if that works as intended?

jessmuir commented 1 year ago

This seems to fix things: I now get the same behavior (matching CAMB HMCode) independent of the order in which linear power and parameters are set. Thanks!