Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JohannesBuchner/PyMultiNest
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed Jul 27, 2023
2 parents 377f9b2 + c8eba95 commit 83fc0f4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build
dist
doc/_build
*.egg-info
.eggs
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The plotting can also be run on existing MultiNest output, and when not using Py

Citing PyMultiNest
--------------------------------------------
See http://johannesbuchner.github.com/PyMultiNest/index.html#citing-pymultinest
See http://johannesbuchner.github.io/PyMultiNest/index.html#citing-pymultinest

Plotting results, corner and trace plots
--------------------------------------------
Expand Down Expand Up @@ -88,7 +88,7 @@ This helps other people google the same question.

Using MultiNest with Python?
--------------------------------------------
Look at the documentation available at http://johannesbuchner.github.com/PyMultiNest/index.html
Look at the documentation available at http://johannesbuchner.github.io/PyMultiNest/

What is PyCuba?
--------------------------------------------
Expand Down
29 changes: 19 additions & 10 deletions pymultinest/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, unicode_literals, print_function
from ctypes import cdll
from ctypes.util import find_library
import sys, os
import sys, os, threading

def _load_library(libname):
libname = {
Expand All @@ -21,20 +21,20 @@ def _load_library(libname):
print('ERROR: Could not load MultiNest library "%s"' % libname)
print('ERROR: You have to build it first,')
print('ERROR: and point the LD_LIBRARY_PATH environment variable to it!')
print('ERROR: manual: http://johannesbuchner.github.com/PyMultiNest/install.html')
print('ERROR: manual: https://johannesbuchner.github.io/PyMultiNest/install.html')
print()
if message.endswith('cannot open shared object file: No such file or directory'):
print()
print('ERROR: Could not load MultiNest library: %s' % message.split(':')[0])
print('ERROR: You have to build MultiNest,')
print('ERROR: and point the LD_LIBRARY_PATH environment variable to it!')
print('ERROR: manual: http://johannesbuchner.github.com/PyMultiNest/install.html')
print('ERROR: manual: https://johannesbuchner.github.io/PyMultiNest/install.html')
print()
if 'undefined symbol: mpi_' in message:
print()
print('ERROR: You tried to compile MultiNest linked with MPI,')
print('ERROR: but now when running, MultiNest can not find the MPI linked libraries.')
print('ERROR: manual: http://johannesbuchner.github.com/PyMultiNest/install.html')
print('ERROR: manual: https://johannesbuchner.github.io/PyMultiNest/install.html')
print()
# the next if is useless because we can not catch symbol lookup errors (the executable crashes)
# but it is still there as documentation.
Expand All @@ -43,7 +43,7 @@ def _load_library(libname):
print('ERROR: You are trying to get MPI to run, but MPI failed to load.')
print('ERROR: Specifically, mpi symbols are missing in the executable.')
print('ERROR: Let me know if this is a problem of running python or a compilation problem.')
print('ERROR: manual: http://johannesbuchner.github.com/PyMultiNest/install.html')
print('ERROR: manual: https://johannesbuchner.github.io/PyMultiNest/install.html')
print()
# what if built with MPI, but don't have MPI
print('problem:', e)
Expand Down Expand Up @@ -201,11 +201,18 @@ def Loglike(cube, ndim, nparams, lnew):
dumper_type = CFUNCTYPE(c_void_p, c_int, c_int, c_int,
POINTER(c_double),POINTER(c_double),POINTER(c_double),
c_double,c_double,c_double,c_void_p)

# check if threads are involved
# in that case we can't use the signal handler
is_thread = threading.active_count() > 1

# check if lnew is supported by user function
nargs = 3
try:
nargs = len(inspect.getargspec(LogLikelihood).args) - inspect.ismethod(LogLikelihood)
if sys.version_info[0] == 3:
nargs = len(inspect.getfullargspec(LogLikelihood).args) - inspect.ismethod(LogLikelihood)
else:
nargs = len(inspect.getargspec(LogLikelihood).args) - inspect.ismethod(LogLikelihood)
except:
pass

Expand Down Expand Up @@ -234,7 +241,8 @@ def dumper(nSamples,nlive,nPar,
as_array(posterior,shape=(nPar+2,nSamples)).T,
(pc[:,0],pc[:,1],pc[:,2],pc[:,3]), # (mean,std,bestfit,map)
maxLogLike,logZ,logZerr, 0)
prev_handler = signal.signal(signal.SIGINT, interrupt_handler)
if not is_thread:
prev_handler = signal.signal(signal.SIGINT, interrupt_handler)

# to avoid garbage collection of these ctypes, which leads to NULLs
# we need to make local copies here that are not thrown away
Expand Down Expand Up @@ -275,7 +283,8 @@ def dumper(nSamples,nlive,nPar,
MPI.COMM_WORLD.Barrier()
else:
lib.run(*args_converted)
signal.signal(signal.SIGINT, prev_handler)
if not is_thread:
signal.signal(signal.SIGINT, prev_handler)
assert len(args) == len(argtypes) # to make sure stuff is still here

def _is_newer(filea, fileb):
Expand All @@ -290,9 +299,9 @@ def multinest_complete(outputfiles_basename = "chains/1-"):
"""
names = ['stats.dat', 'post_equal_weights.dat', '.txt', 'resume.dat', 'params.json']
for n in names:
if not os.path.exists(basename + n):
if not os.path.exists(outputfiles_basename + n):
return False
# if stats.dat and post_equal_weights.dat are newer than .txt and resume.dat exists
if not _is_newer(basename + 'post_equal_weights.dat', basename + '.txt'):
if not _is_newer(outputfiles_basename + 'post_equal_weights.dat', outputfiles_basename + '.txt'):
return False
return True
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
author_email = "[email protected]",
maintainer = "Johannes Buchner",
maintainer_email = "[email protected]",
url = "http://johannesbuchner.github.com/PyMultiNest/",
url = "https://johannesbuchner.github.io/PyMultiNest/",
license = "GPLv3",
packages = ["pymultinest", "pycuba"],
provides = ["pymultinest", "pycuba"],
Expand Down

0 comments on commit 83fc0f4

Please sign in to comment.