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)
234 stars 290 forks source link

Cannot create multiple instances of CLASS through CLASSY #414

Open ShazAlvi opened 3 years ago

ShazAlvi commented 3 years ago

I am trying to simply study the Growth factor and other cosmological quantities for different sets of cosmological parameters. I am using the following code,

from classy import Class
import numpy as np
import matplotlib.pyplot as plt
import math

for DE_Fld in [-0.5,-0.6,-0.7,-0.8,-0.9]:
    params = {}
    MyClass = Class()
    params = {'omega_b': 0.022237,'omega_cdm': 0.1201, 'ln10^{10}A_s': 3.054, 'n_s': 0.9651,
                '100*theta_s': 1.04090, 'tau_reio': 0.0590,'w0_fld':DE_Fld,
                'Omega_Lambda': 0.0}
    print(params)
    MyClass.set(params)
    MyClass.compute()
    z = np.linspace(0, 4.0, 200)
    Growth = np.zeros(len(z))
    for i in range(len(z)):
        Growth[i] = MyClass.scale_independent_growth_factor(z[i])
    plt.plot(z, Growth)
    MyClass.struct_cleanup()
    MyClass.empty()
plt.show()

But I keep getting the following error whenever there is more than one value of DE_Fld in the list.

Traceback (most recent call last):
  File "/home/shaz_alvi/Documents/PhD_Codes/CLASSY_Code/CLASSY_Lab.py", line 19, in <module>
    MyClass.compute()
  File "classy.pyx", line 376, in classy.Class.compute
classy.CosmoComputationError: 

Error in Class: background_init(L:698) :condition (pba->shooting_failed == _TRUE_) is true; Shooting failed, try optimising input_get_guess(). Error message:

input_init(L:386) :error in input_find_root(&xzero, &fevals, &fzw, errmsg);
=>input_find_root(L:4069) :error in input_fzerofun_1d(x1, pfzw, &f1, errmsg);
=>input_fzerofun_1d(L:3543) :error in input_try_unknown_parameters(&input, 1, pfzw, output, error_message);
=>input_try_unknown_parameters(L:3753) :error in thermodynamics_init(&pr,&ba,&th);
=>thermodynamics_init(L:339) :error in thermodynamics_helium_from_bbn(ppr,pba,pth);
=>thermodynamics_helium_from_bbn(L:1656) :condition (sscanf(line,"%lg %lg %lg", &(omegab[array_line%num_omegab]), &(deltaN[array_line/num_omegab]), &(YHe[array_line]) ) != 3) is true; could not read value of parameters (omegab,deltaN,YHe) in file /home/shaz_alvi/Documents/PhD_Codes/class_public/bbn/sBBN_2017.dat

I am probably doing something silly but I can't see what I am doing wrong here?

ThomasTram commented 3 years ago

Hi

According to the error message, it cannot read the file /home/shaz_alvi/Documents/PhD_Codes/class_public/bbn/sBBN_2017.dat properly. Did you move the CLASS directory after installing? Does the file exist, and does it look fine when you open it?

Cheers, Thomas

ShazAlvi commented 3 years ago

Hi,

Yes, I can see the file when I follow the path that it gives here. Moreover, the code works fine when I give just one value of the w0. It is only when a list of w0 parameters is provided that the code gives this error.

On Wed, Apr 21, 2021 at 10:32 AM Thomas Tram @.***> wrote:

Hi

According to the error message, it cannot read the file /home/shaz_alvi/Documents/PhD_Codes/class_public/bbn/sBBN_2017.dat properly. Did you move the CLASS directory after installing? Does the file exist, and does it look fine when you open it?

Cheers, Thomas

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lesgourg/class_public/issues/414#issuecomment-823884135, or unsubscribe https://github.com/notifications/unsubscribe-auth/APD5PLXKSDJMVVJDX4BZRWTTJ2EQ7ANCNFSM43J2REIA .

ShazAlvi commented 3 years ago

So, I could not sort out the previous problem. I ended up exporting the out of each instance to a file and reading it later. However, I have run into issue #420 which is similar to this because it also involves multiple instances of CLASS.

Update: Refer to issue #420 for updates on this matter.