PyMultiNest - shawfdong/hyades GitHub Wiki

MultiNest is a Bayesian inference tool which calculates the evidence and explores the parameter space which may contain multiple posterior modes and pronounced (curving) degeneracies in moderately high dimensions.

Table of Contents

MultiNest

Download MultiNest source code:

$ cd /scratch
$ git clone https://github.com/JohannesBuchner/MultiNest.git

MultiNest uses the CMake build system. MultiNest requires LAPACK – see MultiNest/src/CMakeLists.txt:

>
FIND_PACKAGE(LAPACK REQUIRED)

CMake uses the module /usr/share/cmake/Modules/FindLAPACK.cmake to find LAPACK, and /usr/share/cmake/Modules/FindBLAS.cmake to find BLAS (required by LAPACK).

MKL

On Hyades, it will find Intel MKL by default:

$ cd MultiNest
$ mkdir mkl
$ cd mkl
$ cmake -DCMAKE_INSTALL_PREFIX=/pfs/sw/parallel/impi_gcc/MultiNest_mkl ..

One can run the following command to list CMake cached variables

$ cmake -LAH ..

BLAS_iomp5_LIBRARY:FILEPATH=/opt/intel/composer_xe_2013_sp1.1.106/compiler/lib/intel64/libiomp5.so
BLAS_mkl_core_LIBRARY:FILEPATH=/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_core.so
BLAS_mkl_intel_LIBRARY:FILEPATH=BLAS_mkl_intel_LIBRARY-NOTFOUND
BLAS_mkl_intel_lp64_LIBRARY:FILEPATH=/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_lp64.so
BLAS_mkl_intel_thread_LIBRARY:FILEPATH=/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so

or inspect the file CMakeCache.txt. One can see that it does use Intel MKL. MultiNest compiles fine with Intel MKL:

$ make
$ make install

However, when testing some PyMultiNest demo code:

$ export LD_LIBRARY_PATH=/pfs/sw/parallel/impi_gcc/MultiNest_mkl/lib:$LD_LIBRARY_PATH
$ python pymultinest_demo.py
we got the following error:
Intel MKL FATAL ERROR: Cannot load libmkl_avx.so or libmkl_def.so.

There is a workaround though. If I preload some Intel MKL shared libraries, the demo script seems to run OK:

$ export LD_PRELOAD=$MKLROOT/lib/intel64/libmkl_core.so:$MKLROOT/lib/intel64/libmkl_sequential.so
$ python pymultinest_demo.py

Note that CMake automatically selected the multi-threaded version of Intel MKL for building MultiNest; but in the above workaround, we preloaded the sequential version. It seems to work; but I am not sure whether there is any unintended consequences. Which made me uneasy!

ATLAS

So I decided to build MultiNest against ATLAS. However, I had to fix a bug in CMake first. When using ATLAS, a LAPACK program must link with all the following libraries: lapck, f77blas, cblas, and atlas. But the stock /usr/share/cmake/Modules/FindBLAS.cmake omits cblas:

if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
 if(NOT BLAS_LIBRARIES)
  # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  check_fortran_libraries(
  BLAS_LIBRARIES
  BLAS
  dgemm
  ""
  "f77blas;atlas"
  ""
  )
 endif()
endif ()

This bug can be easily fixed once we've spotted it. Here is the new version:

if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
 if(NOT BLAS_LIBRARIES)
  # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  check_fortran_libraries(
  BLAS_LIBRARIES
  BLAS
  dgemm
  ""
  "f77blas;cblas;atlas"
  ""
  )
 endif()
endif ()

Configure CMake to use ATLAS to build MultiNest:

$ cd /scratch/MultiNest/build
$ cmake \
    -DBLA_VENDOR=ATLAS \
    -DCMAKE_PREFIX_PATH=/pfs/sw/serial/gcc/atlas-3.10.2/lib \
    -DCMAKE_INSTALL_PREFIX=/pfs/sw/parallel/impi_gcc/MultiNest \
    ..

One can confirm that it does use ATLAS, instead of the Intel MKL:

$ cmake -LA ..

BLAS_atlas_LIBRARY:FILEPATH=/pfs/sw/serial/gcc/atlas-3.10.2/lib/libatlas.a
BLAS_cblas_LIBRARY:FILEPATH=/pfs/sw/serial/gcc/atlas-3.10.2/lib/libcblas.a
BLAS_f77blas_LIBRARY:FILEPATH=/pfs/sw/serial/gcc/atlas-3.10.2/lib/libf77blas.a
LAPACK_lapack_LIBRARY:FILEPATH=/pfs/sw/serial/gcc/atlas-3.10.2/lib/liblapack.a

MultiNest compiles fine with ATLAS:

$ make
$ make install

PyMultiNest

PyMultiNest is the Python interface for MultiNest.

Install PyMultiNest:

$ module load MultiNest
$ module load python
$ pip install pymultinest
⚠️ **GitHub.com Fallback** ⚠️