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

Problem with get_pk_and_k_and_z() in python wrapper #471

Closed fmccarthy closed 10 months ago

fmccarthy commented 2 years ago

Hi; I am finding that the below code produces the following error in v3.1.2

"classy.pyx in classy.Class.get_pk_and_k_and_z() 
ValueError: negative dimensions are not allowed"

It seems that computing the tCl along with mPk messes something up that is required for get_pk_and_k_and_z()

from classy import Class

params={'N_ncdm': 1,
        'N_ur': 2.0328,
        'non linear': 'hmcode', 
        'output': 'mPk', 
        'z_pk':'3',
        'P_k_max_1/Mpc': 15,
        '100*theta_s': 1.0417368567740997, 
        'A_s': 2.1102839631833067e-09, 
        'm_ncdm': 0.06, 
        'n_s': 0.9671828913167801, 
        'omega_b': 0.02255434170350831,
        'omega_cdm': 0.11817158102801589,
        'tau_reio': 0.05515052267600599}

c = Class()

c.set(params)

c.compute()

print("getting pk")

c.get_pk_and_k_and_z()   # this works fine

print("got pk")

c.set({'output':'mPk tCl'})

c.compute()
print("getting pk")

c.get_pk_and_k_and_z()    # this line produces an error

print("got pk")
jcolinhill commented 2 years ago

Echoing Fiona's comment -- this error breaks (e.g.) the interface between CLASS and any likelihood in Cobaya that requires the matter power spectrum, such as DES. I briefly tried to find a fix, but with no immediate success -- it appears to be indexing-related somehow.

jcolinhill commented 2 years ago

(note that this must be due to a change from CLASS v2 to v3, as this error is not thrown when running P(k)-based likelihoods with CLASSv2 in Cobaya)

alexander-reeves commented 2 years ago

Hi both, I am also encountering the same issue- has there been any update or workaround of this? I have tried installing previous versions of Class but with no success.

Many thanks,

Alex

svenguenther commented 2 years ago

Hey all, I could reproduce that bug. For me it works that I downgrade this function to the version 3.1.1. It is communicated to the maintainer of CLASS and will be fixed in one of the next releases. Thank you for making us aware of that problem. Best, Sven

schoeneberg commented 1 year ago

Dear all, this has been finally propagated to me, and the solution is now in the newest development branch and will be released as a minor release shortly!

jcolinhill commented 1 year ago

Thanks @schoeneberg !

fmccarthy commented 1 year ago

Thanks for sorting that out @schoeneberg !

knaidoo29 commented 1 year ago

Hi, I've come across the same error. Is the update coming anytime soon? What can I do to get this working in the mean time? I've added a model to class so can't move to an older version.

schoeneberg commented 1 year ago

Dear @knaidoo29 , the PR on this issue is already underway on the private devel branch, and should be released with the next minor release. When that will be, I cannot tell you. You can write an email to @lesgourg and ask him about it :smile:

I think there's no easy "working-in-the-meantime" fix, at least not one I could describe in a comment. It might help to include tCl/pCl in your output if you haven't already, but beyond that, I do agree that the PR is urgent. Feel free to contact Prof. Julien Lesgourgues about this issue if it is blocking your work.

kcroker commented 10 months ago

@schoeneberg is this fixed in v3.2.1? If so, could we close this issue?

schoeneberg commented 10 months ago

Dear all, I confirm that the bug is fixed and the fix is propagated to v3.2.1. ( @kcroker , @knaidoo29 , @fmccarthy , @jcolinhill , @alexreevesy ) Sadly I cannot currently close any issues, so this will have to be done from @lesgourg !

kcroker commented 10 months ago

Dear all, I confirm that the bug is fixed and the fix is propagated to v3.2.1. ( @kcroker , @knaidoo29 , @fmccarthy , @jcolinhill , @alexreevesy ) Sadly I cannot currently close any issues, so this will have to be done from @lesgourg !

@schoeneberg thank you for following up quickly. @fmccarthy as you opened this issue, I think you also have the ability to close it? If so, could you please close it?

fmccarthy commented 10 months ago

thank you for fixing this!