lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
223 stars 292 forks source link

Code crashing when using the parameter sigma8 #461

Open PedroFerreirAstro opened 2 years ago

PedroFerreirAstro commented 2 years ago

Hello, I would like to request your help in an issue that's been annoying me for a couple weeks. When using the module classy with a certain set of cosmological parameters (i.e omega_b, omega_cdm, 100*theta_s, tau_reio, ln10^{10}A_s and n_s) , everything works fine. But when I change ln10^{10}A_s by sigma8, the codes simply crashes in the computation step. Bellow I present my code:

#Parameters' average values and sigma tolerance.

#tolerance
n_sig=3

#LambdaCDM parameters' average values according to the Planck's results from 2018.
omega_b=0.0224
sig_omega_b=0.0001

omega_cdm=0.120
sig_omega_cdm=0.001

H_0= 67.4
sig_H_0 = 0.5

tau_reio = 0.054
sig_tau_reio = 0.007

sigma8 = 0.811
sig_sigma8 = 0.006

n_s = 0.965
sig_n_s = 0.004

#import random module
import random
#LambdaCDM parameters
Parameters = {'omega_b':random.uniform(omega_b-n_sig*sig_omega_b, omega_b+n_sig*sig_omega_b), 
               'omega_cdm':random.uniform(omega_cdm - n_sig*sig_omega_cdm, omega_cdm + n_sig*sig_omega_cdm ), 
               'H0':random.uniform(H_0 - n_sig*sig_H_0, H_0 + n_sig*sig_H_0),
               'tau_reio':random.uniform(tau_reio - n_sig*sig_tau_reio, tau_reio + n_sig*sig_tau_reio), 
               'sigma8':random.uniform(sigma8 - n_sig*sig_sigma8, sigma8 + n_sig*sig_sigma8), 
               'n_s':random.uniform(n_s - n_sig*sig_n_s, n_s + n_sig*sig_n_s,)}
#random.uniform(a, b) allows one to get a random number between an interval [a,b) or [a,b] depending on rouding.

#When using sigma8, we get in trouble for some reason that I'm not able to find out.
# output and precision parameters
Output= {'output':'tCl,pCl,lCl','lensing':'yes'}

# import classy module
from classy import Class

# create instance of the class "Class"
LambdaCDM = Class()
# pass input parameters
LambdaCDM.set(Parameters)

# output parameters
LambdaCDM.set(Output)

# run class
LambdaCDM.compute()

After executing LambdaCDM.compute(), the code crashes and the kernel restarts.

Any help will be appreciated, thanks in advance.

schoeneberg commented 2 years ago

Dear @PedroFerreirAstro ,

Julien pointed out this issue to me. I tried to run your code 300 times from the terminal, and 5 times from a jupyter notebook, and I never managed to reproduce the crash. While Julien was able to reproduce similar issues, I am still not able.

As such, to reproduce your bug, I would love to ask what version of python you are using (major and minor), as well as the gcc version. Do you have OpenMP enabled? Are you using MAC or Linux or Windows or some other OS? Finally, are you using the most up-to-date version of the public release or an older one? For the newest version you should be able to get

git log | head -n 1
commit 93a219c5559ce4989a969c39d9db4cf763fe23d6

Further, it would help to know the exact parameters (rather than random ones). You could a) print the cosmo.pars before the execution or b) initialize the numpy random generator with a given seed, and tell me after which iteration of your code you found the bug.

carlosggarcia commented 2 years ago

@PedroFerreirAstro I think I've found this problem before and I had to add 'mPk' in the output; i.e.

Output= {'output':'tCl,pCl,lCl,mPk','lensing':'yes'}