CosmoMC: Combining Python code with CosmoMC

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Abhishek Maniyar
Posts: 10
Joined: March 17 2016
Affiliation: Laboratoire d’Astrophysique de Marseille

CosmoMC: Combining Python code with CosmoMC

Post by Abhishek Maniyar » March 17 2016

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.

Antony Lewis
Posts: 1941
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: CosmoMC: Combining Python code with CosmoMC

Post by Antony Lewis » March 18 2016

I think it's possible, but probably not easy e.g.

http://stackoverflow.com/questions/1707 ... fortran-90

Abhishek Maniyar
Posts: 10
Joined: March 17 2016
Affiliation: Laboratoire d’Astrophysique de Marseille

CosmoMC: Combining Python code with CosmoMC

Post by Abhishek Maniyar » March 18 2016

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.

Marius Millea
Posts: 1
Joined: May 19 2016
Affiliation: Institut Lagrange de Paris
Contact:

CosmoMC: Combining Python code with CosmoMC

Post by Marius Millea » May 19 2016

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_)

Abhishek Maniyar
Posts: 10
Joined: March 17 2016
Affiliation: Laboratoire d’Astrophysique de Marseille

CosmoMC: Combining Python code with CosmoMC

Post by Abhishek Maniyar » June 03 2016

Hey Marius,

Thank you very much for your suggestions. I will give it a try soon.

Post Reply