LSSTDESC / augur

DESC forecasting and inference validation tool
MIT License
3 stars 2 forks source link

Using A_s instead of sigma8 in a 3x2pt forecast is generating invalid values in CCL boltzmann.py when performing derivative calculations #62

Open bruno-moraes opened 1 week ago

bruno-moraes commented 1 week ago

TL;DR: A call to boltzmann.py within CCL is failing in the derivative calculation, presumably due to O(10^-9) values in A_s.

Explanation: When attempting a 3x2pt forecast, it runs and completes when the sigma8 parameter is used. If A_s is used instead, the Jupyter kernel dies after a few seconds when trying to calculate the Fisher matrix. Running the code as a python script from the command line, the error returned is:

(forecasting) brunomor@Brunos-MacBook-Pro-2 forecasts_neutrinos_workshop2024 % time python 2024-07-02_neutrino_3x2pt_SRD.py 
forecasting_strawberry_run.sacc
/Users/brunomor/miniforge3/envs/forecasting/lib/python3.12/site-packages/pyccl/boltzmann.py:170: RuntimeWarning: invalid value encountered in log
  ln_p_k_and_z[i, :] = np.log(pk[sind, :])
zsh: abort      python 2024-07-02_neutrino_3x2pt_SRD.py

The trace did not contain information about where this error occurred, so I ran pdb on the script (my first time, so not very skillfully) and found the spot where it is breaking:

> /Users/brunomor/lib/python/augur/augur/analyze.py(191)get_fisher_matrix()
-> if self.derivatives is None:
(Pdb) n
> /Users/brunomor/lib/python/augur/augur/analyze.py(192)get_fisher_matrix()
-> self.get_derivatives(method=method)
(Pdb) n
/Users/brunomor/miniforge3/envs/forecasting/lib/python3.12/site-packages/pyccl/boltzmann.py:170: RuntimeWarning: invalid value encountered in log ln_p_k_and_z[i, :] = np.log(pk[sind, :])
zsh: abort      python 2024-07-02_neutrino_3x2pt_SRD.py
bruno-moraes commented 1 week ago

I will work on this now.

bruno-moraes commented 1 week ago

@fjaviersanchez , I could pinpoint more or less where the error is, but this is something I never fixed before. I assume it's numerical instabilities in the derivatives due to the small values of A_s compared to the other parameters. I won't be able to solve it now.

fjaviersanchez commented 1 week ago

Thank you for checking and identifying the issue! I think this can be potentially solved when we add the stem derivative method. One potential solution is to normalize all parameters internally for the derivatives and then change back or change the step size dynamically, but will check first if the easy fix works.