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)
220 stars 291 forks source link

python wrapper #482

Closed fhenryco closed 2 years ago

fhenryco commented 2 years ago

Hello ,

I had a python 2.7 code working well with a 2 years old version of class. Now i'm trying a new version of class with my python code translated into 3.8 and get a new issue. even though i followed exactly what is detailed in https://github.com/lesgourg/class_public/issues/291 to add new parameters in the CLASS code and be able to input values to these parameters through the python wrapper, (lines added in background.h , input.c , classy.pyx and cclassy.pxd ) i now get the error

File "classy.pyx", line 371, in classy.Class.compute classy.CosmoSevereError: Error in Class: Class did not read input parameter(s): my_input_parameter

so i'm wondering if there is something else to do ...i'm not using monte python

Thanks in advance for any suggestion and comment.

fhenryco commented 2 years ago

I made a little progress in understanding the origin of the error:

in my python code i use two instances of classy and it worked with class two years ago but not anymore (i'm using now a more recent september 2021 version ).

import importlib import sys sys.path.remove('/home/henry/.local/lib/python3.8/site-packages') sys.path.insert(1,'/home/henry/.local/lib/python3.8/site-packages/LCDM')

import classy from classy import Class as ClassLCDM

sys.path.remove('/home/henry/.local/lib/python3.8/site-packages/LCDM') sys.path.insert(1, '/home/henry/.local/lib/python3.8/site-packages') importlib.reload(classy) import classy from classy import Class as ClassDG

and then i use ClassLCDM for LCDM and ClassDG for my alternative theory.

to track the origin of the error, i simplify the code to use just one instance of classy replacing all the above code by

import classy from classy import Class as ClassDG

then it works (i dont have the error Error in Class: Class did not read input parameter(s): my_input_parameter).

So it seems that what i did before to use two instances of class does not work anymore with the new version... no idea why and what would be the alternative

fhenryco commented 2 years ago

it works now using sys.modules.pop('classy') to unload the module

IamSreeman commented 2 years ago

@fhenryco I can't thank you enough. I wasted many hours because of this error.