Open ghost opened 5 years ago
Hi,
Did you add it in classy.pyx
?
MontePython calls get_current_derived_parameters
to get the value of the parameters in data.parameters
.
So you would need to add your parameter in get_current_derived_parameters
if you haven't.
Cheers,
Carlos
Hi, thanks for the reply!
You mean I have to do in the classy.pyx
file something like the following?
def get_current_derived_parameters(self, names):
if type(names) != type([]):
raise TypeError("Deprecated")
derived = {}
for name in names:
if name == 'h':
value = self.ba.h
elif name == 'H0':
value = self.ba.h*100
elif name == 'newparamiter':
value = self.ba.newparamiter
*newparamiter is declared in the background modeules and used in the background and perturbations modeules.
Yes, that's it.
I wrote it as it is there and I get the same error of segmentation fault. I also defined in the classy.pxd before as I wrote it in the first post, so is it needed in both places or just in the .pyx file?
It's needed in both places.
I need more info to understand where the segmentation fault comes from.
BTW, the value = self.ba.newparamiter
has the indentation wrong but I don't think that is causing the segmentation fault. You may try fixing it.
The indentation was just a copy/past issue, in the code is fine.
The changes I made are the following:
+CLASS:
in background.h double newparamiter;
In input.c insideint input_read_parameters
class_read_double("newparamiter",pba->newparamiter);
and inside int input_default_params
pba->newparamiter=0.;
In classy.pyx inside def get_current_derived_parameters(self, names):
elif name == 'newparamiter': value = self.ba.newparamiter
In cclassy.pxd inside cdef struct background:
double newparamiter
The equationf for DM and DE of the background and perturbation were modified.
I run class and it works perfectly, then I usemake clean;
make;
, cd python/
, python setup.py build
and python setup.py install --user
+Montepython:
In the example.param file I add a new line data.parameters['newparamiter'] = [1.0, 0,2, 0.1,1, 'cosmo']
I think that is all (maybe I forgot something), I do not know what i am missing so MontePyhton can work.
Just to double check. Did you run the problematic model in CLASS and worked fine? Does the segmentation fault give you some output? (if so, it might be helpful to see it) It might be a double free or something like that.
Yes, I run it in CLASS using a .ini file with the newparamiter (changing the values of different Omega and using use_ppf= no...) and everything works fine and I obtained plots that I previously expected.
What happens when I try to run MontePython is the following:
+CLASS
$cd python/
$python setup.py build
running build
running build_ext
skipping '/mnt/Datos/usuario/Escritorio/code/class/python/../python/classy.c' Cython extension (up-to-date)
$python setup.py install --user
running install
running build
running build_ext
skipping '/mnt/Datos/usuario/Escritorio/code/class/python/../python/classy.c' Cython extension (up-to-date)
running install_lib
running install_egg_info
Removing /home/usuario/.local/lib/python2.7/site-packages/classy-2.7.2.egg-info
Writing /home/usuario/.local/lib/python2.7/site-packages/classy-2.7.2.egg-info
+In MontePython
$ python montepython/MontePython.py run -o test -p example.param
Running Monte Python v3.2.0
with CLASS v2.7.2
/!\ Running CLASS from a non version-controlled repository
/!\ Detecting empty folder, logging the parameter file
Testing likelihoods for:
-> fake_planck_bluebook
Initialised likelihood_mock_cmb with following options:
unlensed_clTTTEEE is False
Bmodes is False
delensing is False
LensingExtraction is False
neglect_TD is True
ExcludeTTTEEE is False
OnlyTT is False
Creating test/2019-10-03_10__1.txt
Deduced starting covariance matrix:
['omega_b', 'omega_cdm', 'n_s', 'A_s', 'h', 'tau_reio', 'newparamiter']
[[2.56e-04 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00]
[0.00e+00 2.56e-06 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00]
[0.00e+00 0.00e+00 1.60e-05 0.00e+00 0.00e+00 0.00e+00 0.00e+00]
[0.00e+00 0.00e+00 0.00e+00 1.44e-03 0.00e+00 0.00e+00 0.00e+00]
[0.00e+00 0.00e+00 0.00e+00 0.00e+00 4.22e-05 0.00e+00 0.00e+00]
[0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 1.94e-05 0.00e+00]
[0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 0.00e+00 1.00e-02]]
Update routine is enabled with value 50 (recommended: 50)
This number is rescaled by cycle length 7 (N_slow + f_fast * N_fast) to 350
Segmentation fault (core dumped)
Ok. I'd do two checks:
Hi
$cd python
$ python setup.py build
running build
running build_ext
skipping '/mnt/Datos/usuario/Escritorio/code/class/python/../python/classy.c' Cython extension (up-to-date)
$ python setup.py install --user
running install
running build
running build_ext
skipping '/mnt/Datos/usuario/Escritorio/code/class/python/../python/classy.c' Cython extension (up-to-date)
running install_lib
running install_egg_info
Removing /home/usuario/.local/lib/python2.7/site-packages/classy-2.7.2.egg-info
Writing /home/usuario/.local/lib/python2.7/site-packages/classy-2.7.2.egg-info
A new classy.c appeared in /python. And again when using Montepython the same problem.
The different possible values of the new parameter has been previously run in class using the .ini file and range is not problematic. Sorry I am just a beginner in python, what do you mean by running with classy?
Look at the wiki to see how to use classy: https://github.com/lesgourg/class_public/wiki/Python-wrapper
Hi,
Thanks for the help! Well this appeared when I tried that:
Error in Class: Class did not read input parameter(s): newparamiter
The newparamiter is used only in the modules where:
if (pba->has_fld == _TRUE_) {
if (pba->use_ppf == _FALSE_){...
This is known to MontePython in any way?
It seems that you didn't add your new parameter in input.c
to be read. ./class
ignore the undefined parameters, but classy doesn't. You have to add newparmiter
to input.c
to be read.
But I have defined in this way inside input.c of CLASS:
In input.c inside int input_read_parameters
I wrote
class_read_double("newparamiter",pba->newparamiter);
and inside int input_default_params
I have pba->newparamiter=0.;
And in fact CLASS read it because using different values in the .ini file I obtain different output for P(k) or C_l
Is there something more to add?
I've run out of ideas. I'd need to see the code. You have to manage to make your model work with classy before using MP, as it calls classy to compute the cosmology.
I have look in another issues for some problem with the Python part while running class works with ./class. One of them suggest this test and i found the same error that the one in MP is happening while executing it
$python -c "from classy import Class; cosmo=Class(); cosmo.set({'output':'tCl', 'Omega_Lambda':0.0,'w0_fld':-0.9,'newparamiter':1.0});cosmo.compute()"
Segmentation fault (core dumped)
Does this give any idea of what I am doing wrongly?
The command seems ok, it must be something about the implementation.
I will try to modify the implementation in a way it works. Thanks for the help!!
No problem, just share the solution here when you find it so that other people can learn from it.
Hi -- maybe try to just add a new parameter to the background structure without modifying the physics and see if that works for you. A patch to add my_new_param
is attached (based on commit 3dc78882860a23a4952c5e49d4b20bc51dd000d0).
With this the command
python -c "from classy import Class; cosmo=Class(); cosmo.set({'output':'tCl', 'my_new_param':2}); cosmo.compute()"
should run fine after running make clean; make all
.
The SegFault you see comes from trying to access unmapped memory. So double check if you declared the new parameter everywhere and that there is not type mismatch.
Cheers, Janina
I'm having the same issue with CLASS 2.9 and python 3.7 (via anaconda) and Mac Os Catalina, with both gcc 9.2 (via homebrew) or clang (the system default C compilers)
So I decided to test the same modification on Linux, and it worked!
So, if you are working on macos I recomend you to do the same
Hello everyone,
I was able to modify CLASS in order to include a new model that only adds a new parameter and everything worked fine. Now I am trying to use MontePython and I think I am missing something while changing the Python wrapper of CLASS. I did the following:
-I did every change in CLASS to add the new parameter. I run it and It worked with no problem and calculated everything.
-In CLASS Python classy.pxd file I added a line in the background struct as
double newparamiter
. I did everything of make clean, make and python build and install following the instructions.-In MontePython I added the new parameter in the .param file.
I think I am missing something in doing the Python Wrapper of CLASS. Any idea of what I am missing?
Thanks!!!