CosmoMC: Combining Python code with CosmoMC
-
- Posts: 10
- Joined: March 17 2016
- Affiliation: Laboratoire d’Astrophysique de Marseille
CosmoMC: Combining Python code with CosmoMC
Hi everyone,
I am running CosmoMC on a Windows 7 OS using COSMOBOX virtual environment. We have a Python code for JLA SN1a dataset with a different likelihood with different parameters than the one used in CosmoMC with just two parameters (alpha and beta). We would like to use this new likelihood in CosmoMC instead of the the existing one.
So is there a way to combine this likelihood written in Python with CosmoMC without having to convert the whole Python code in Fortran?
Thank you.
I am running CosmoMC on a Windows 7 OS using COSMOBOX virtual environment. We have a Python code for JLA SN1a dataset with a different likelihood with different parameters than the one used in CosmoMC with just two parameters (alpha and beta). We would like to use this new likelihood in CosmoMC instead of the the existing one.
So is there a way to combine this likelihood written in Python with CosmoMC without having to convert the whole Python code in Fortran?
Thank you.
-
- Posts: 1948
- Joined: September 23 2004
- Affiliation: University of Sussex
- Contact:
Re: CosmoMC: Combining Python code with CosmoMC
I think it's possible, but probably not easy e.g.
http://stackoverflow.com/questions/1707 ... fortran-90
http://stackoverflow.com/questions/1707 ... fortran-90
-
- Posts: 10
- Joined: March 17 2016
- Affiliation: Laboratoire d’Astrophysique de Marseille
CosmoMC: Combining Python code with CosmoMC
Thank you very much for your reply and the link. We are going to try it and see if we can make it.
Thank you.
Thank you.
-
- Posts: 1
- Joined: May 19 2016
- Affiliation: Institut Lagrange de Paris
- Contact:
CosmoMC: Combining Python code with CosmoMC
Hey Abhishek, its actually not too bad, that's exactly how PICO works when its called from CosmoMC. Easiest way IMO is to write some small Cython wrapper functions which can be called directly from C or Fortran. Here's the ones for PICO as an example https://github.com/marius311/pypico/blo ... o/pico.pyx The trickiest part is converting strings (see the add_null_term function which does this) and writing the function signatures correctly (Fortran passes args by reference, and passes the length of variable-length strings by value after all other parameters, see e.g. fpico_load_)
-
- Posts: 10
- Joined: March 17 2016
- Affiliation: Laboratoire d’Astrophysique de Marseille
CosmoMC: Combining Python code with CosmoMC
Hey Marius,
Thank you very much for your suggestions. I will give it a try soon.
Thank you very much for your suggestions. I will give it a try soon.