JohannesBuchner / PyMultiNest

Pythonic Bayesian inference and visualization for the MultiNest Nested Sampling Algorithm and PyCuba's cubature algorithms.
http://johannesbuchner.github.io/PyMultiNest/
Other
194 stars 88 forks source link

Compile error with InitSampler used for pyPolychord #69

Closed JaapLeguijt closed 5 years ago

JaapLeguijt commented 8 years ago

I tried to compile polychord together with the pypolychord interface. I started my attempts with the source code that I found in GitHub, but I was not able to get it compiled. Next, I started with the newest release of PolyChord (1.7) that I got from Cambridge. I was able to compile everything and than I started merging in the code from GitHub. I had to compile a few source files by hand, as the order chosen by the make file was not such that all the modules were available when needed. In the end I stumbled with this attempt on the same compiling problem while compiling InitSampler.f90. The compile command is "gfortran -ffree-line-length-none -cpp -fPIC -Ofast -c InitSampler.f90 -lstdc++" and the error that I get is

InitSampler.f90:73.33:

output_info = NestedSampling(Lfunc,priors,settings,0) 
                             1

Error: Interface mismatch in dummy procedure 'loglikelihood' at (1): Type/rank mismatch in argument 'theta' Is there a solution and does the pypolychord interface work with the newest version of PolyChord?

Kind regards,

Jaap Leguijt

JohannesBuchner commented 8 years ago

Hi Jaap,

it works with this modified version: https://github.com/JohannesBuchner/polychord Several modifications were required and I have not had time to upgrade to a newer version. Have there been any major changes? Yes, you have to run make several times because the dependencies between files are not handled in polychord's Makefile.

Cheers, Johannes

On 01/22/2016 09:13 AM, JaapLeguijt wrote:

I tried to compile polychord together with the pypolychord interface I started my attempts with the source code that I found in GitHub, but I was not able to get it compiled Next, I started with the newest release of PolyChord (17) that I got from Cambridge I was able to compile everything and than I started merging in the code from GitHub I had to compile a few source files by hand, as the order chosen by the make file was not such that all the modules were available when needed In the end I stumbled with this attempt on the same compiling problem while compiling InitSamplerf90 The compile command is "gfortran -ffree-line-length-none -cpp -fPIC -Ofast -c InitSamplerf90 -lstdc++" and the error that I get is

InitSamplerf90:7333:

|output_info = NestedSampling(Lfunc,priors,settings,0) 1 |

Error: Interface mismatch in dummy procedure 'loglikelihood' at (1): Type/rank mismatch in argument 'theta' Is there a solution and does the pypolychord interface work with the newest version of PolyChord?

Kind regards,

Jaap Leguijt

— Reply to this email directly or view it on GitHub https://github.com/JohannesBuchner/PyMultiNest/issues/69.

JaapLeguijt commented 8 years ago

I tried to get polychord to work with the source from GitHub and when I tried to run the pypolychord_demo program within ipython, I get an ini error and ipython crashes. The error looks like

In [1]: run pypolychord_demo

ini error: no keyword nlive

STOP 1 Kind regards,

Jaap Leguijt

JaapLeguijt commented 8 years ago

I got it to work. When I copied the file run.py of the polychord inface into my environment, something went wrong with the indenting. After some changes, it started to work.

JaapLeguijt commented 8 years ago

I wonder how long the demo program should run. I have the suspicion that it came in an infinite loop as is already running for more than 20 minutes.

JohannesBuchner commented 8 years ago

Yes, should not take very long. Maybe just run again, and add a print in the likelihood evaluations.

JohannesBuchner commented 8 years ago

oh and please show your modifications (e.g. pull request)

JaapLeguijt commented 8 years ago

I ran it again and I activated the print statements in the run function of the interface. It produced many lines of output but it finished quickly. The end of the output stream look like:

py:calling likelihood... [ 0.3998123 0.40545186] [ 6.28023698 6.36882286] py:returned: 242.628571257 py:loglike called... 472803064 472803068 py:calling likelihood... [ 0.39673846 0.39999812] [ 6.23195311 6.28315572] py:returned: 242.867158924


| | | ndead = 3994 | | log(Z) = 235.71662 +/- 0.11854 | | check = 235.71662 +/- 0.11854 | |____|

I repeated the program 3 times and 2 times it ran OK and one time it started to produce nan's in the output.

Next, commented the the print statement out again and then the program did not came to an end. I forced it to stop with Crtl-C and it came with a weird message: too many R steps ( 1602) Polychord Warning: Non deterministic loglikelihood


| | | ndead = 3902 | | log(Z) = 235.90647 +/- 0.11580 | | check = 235.90647 +/- 0.11580 | |____|

I will give more info, but first I have to discover the function of "pull request".

Kind regards,

Jaap Leguijt

JohannesBuchner commented 8 years ago

My experience has been similar unfortunately. It would be great if you can look into it a bit more -- I do not use polychord much. pypolychord just passes floats between python and polychord, since it works fine at least in some runs I can't quite think of where the problem could be. Perhaps it has to do with Python's garbage collection freeing the returned arrays before polychord reads them. You are not running with any parallelisation, are you?

The R steps are MCMC steps to discover a new point within the likelihood constraints, I think.

JaapLeguijt commented 8 years ago

Dear Johannes,

Thanks for you reaction. I followed your suggestions and the results are in GitHub. I do not understand the workings of "pull request", but I may send you a tar file with my code. It may be of interest to you to have some background information about the things that I try to achieve.

I am working with the Shell Research centre in Rijswijk (The Netherlands) and we started a project together with the group of prof. Hobson in Cambridge. Within this project we want to test the sampling algorithms that are developed in Cambridge in our own probabilistic modeling tools. We have one tool for probabilistic seismic inversion and one for probabilistic inversion of reservoir models (history matching). We have developed our own algorithms, but these do not always have the required performance. We hope to be able to extend our capabilities with new sampling algorithms. At the moment, I mainly use python to test these algorithms. I use python as a glue to pass large data sets from one module to the other. After some struggling I got pymultinest to work and this really helped me to explore the capabilities and the boundaries of multinest. We have problems with a dimension of 100-200 and it seems to me that these problems are to heavy for multinest. This is the reason that I started looking at polychord. It would be nice to be able to repeat the tests that I do with multinest with polychord, usinf the pypolychord interface and I may need some advice as the interface looks different. I can send you a tar file with some code with a test program, if you are curious to see what I am doing.

Kind regards,

Jaap Leguijt

Op 22-1-2016 om 15:30 schreef Johannes Buchner:

oh and please show your modifications (e.g. pull request)

— Reply to this email directly or view it on GitHub https://github.com/JohannesBuchner/PyMultiNest/issues/69#issuecomment-173935368.

JohannesBuchner commented 8 years ago

a tar file is fine too.

JohannesBuchner commented 8 years ago

You may also be interested in using my nested sampling algorithm development & testing framework Documentation: https://johannesbuchner.github.io/UltraNest/ Code: https://github.com/JohannesBuchner/UltraNest

Yes, for 100-200 dimensions, MultiNest wouldn't be my tool of choice.

I would be glad if you can dig a bit deeper into pypolychord to make it work more reliably and possibly upgrade to a newer polychord (if there are major changes). You can see the changes made by comparing the master and upstream branches. The first step would be running polychord with the same likelihood written in Fortran or C and comparing why the results are not deterministic. I can help with advising, but I don't have the time to look into it myself.

JaapLeguijt commented 8 years ago

Johannes,

In the attachment you find a tar file with some python code. After unpacking you find three directories. The directory 'statistics' contains a few modules that are used to define a 'multi normal distribution' object and 'probability' object. The director 'multinest' contains some multinest tests and the directory 'polychord' contains the tests for polychord and the pypolychord inteface. As pypolychord is still in development I have put the inteface in the polychord for the time being. You should be able to run the tests. For the test 'multinestTest2' you also need warpUtils.py. Thsi onen is also in the attchement.

Kind regards,

Jaap Leguijt

Johannes Buchner schreef op 2016-01-22 10:31:

a tar file is fine too.

Reply to this email directly or view it on GitHub [1].

*

Links:

[1] https://github.com/JohannesBuchner/PyMultiNest/issues/69#issuecomment-173951402

JaapLeguijt commented 8 years ago

Johannes,

The UltraNest package looks interesting. I will try to install it next week. Is there a README file with the installation instructions? It seems to me that you are working on sampling problems in high dimensional spaces. We may exchange ideas. In which institute are you working?

Kind regards,

Jaap Leguijt

Op 22-1-2016 om 16:37 schreef Johannes Buchner:

You may also be interested in using my nested sampling algorithm development & testing framework Documentation: https://johannesbuchner.github.io/UltraNest/ Code: https://github.com/JohannesBuchner/UltraNest

Yes, for 100-200 dimensions, MultiNest wouldn't be my tool of choice.

I would be glad if you can dig a bit deeper into pypolychord to make it work more reliably and possibly upgrade to a newer polychord (if there are major changes). You can see the changes made by comparing the master and upstream branches. The first step would be running polychord with the same likelihood written in Fortran or C and comparing why the results are not deterministic. I can help with advising, but I don't have the time to look into it myself.

— Reply to this email directly or view it on GitHub https://github.com/JohannesBuchner/PyMultiNest/issues/69#issuecomment-173954111.

JohannesBuchner commented 8 years ago

I am at astro.uc.cl . There are three parts to that repo, as the documentation says. There are some example scripts to run nested sampling with various set ups. You can install the nested sampling suite as usual, but you don't need to. The goal is to primarily test the correctness of algorithms and secondarily their performance (in terms of likelihood evaluations), and to develop new ideas into algorithms rapidly (because python).

JohannesBuchner commented 8 years ago

You will have to send me the tar file to my email address (e.g. jbuchner ät astro.puc.cl) rather than the github issue.