CosmoCoffee Forum Index CosmoCoffee

 
 FAQFAQ   SearchSearch  MemberlistSmartFeed   MemberlistMemberlist    RegisterRegister 
   ProfileProfile   Log inLog in 
Arxiv New Filter | Bookmarks & clubs | Arxiv ref/author:

CosmoMC: Combining Python code with CosmoMC
 
Post new topic   Reply to topic    CosmoCoffee Forum Index -> Computers and software
View previous topic :: View next topic  
Author Message
Abhishek Maniyar



Joined: 17 Mar 2016
Posts: 7
Affiliation: Laboratoire d’Astrophysique de Marseille

PostPosted: March 17 2016  Reply with quote

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.
Back to top
View user's profile  
Antony Lewis



Joined: 23 Sep 2004
Posts: 1207
Affiliation: University of Sussex

PostPosted: March 18 2016  Reply with quote

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

http://stackoverflow.com/questions/17075418/embed-python-into-fortran-90
Back to top
View user's profile [ Hidden ] Visit poster's website
Abhishek Maniyar



Joined: 17 Mar 2016
Posts: 7
Affiliation: Laboratoire d’Astrophysique de Marseille

PostPosted: March 18 2016  Reply with quote

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.
Back to top
View user's profile  
Marius Millea



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

PostPosted: May 19 2016  Reply with quote

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/blob/master/pypico/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_)
Back to top
View user's profile [ Hidden ] Visit poster's website
Abhishek Maniyar



Joined: 17 Mar 2016
Posts: 7
Affiliation: Laboratoire d’Astrophysique de Marseille

PostPosted: June 03 2016  Reply with quote

Hey Marius,

Thank you very much for your suggestions. I will give it a try soon.
Back to top
View user's profile  
Display posts from previous:   
Post new topic   Reply to topic    CosmoCoffee Forum Index -> Computers and software All times are GMT + 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group. Sponsored by WordWeb online dictionary and dictionary software.