Giter Club home page Giter Club logo

ptmpi's Introduction

ptmpi

A python class that carries out an MPI implementation of parallel tempering. Communication costs is kept minimal by exchanging temperatures rather than the state of the modelled system

Setup

Clone the repository onto your machine. The package requires the python package mpi4py and an MPI library such as MPICH. These can both be installed through anaconda. If you are using pip instead, then MPICH must be installed separately.

The package is called ptmpi and is in the packages folder. To make the package accessible from anywhere add the package to your python path environment variable. This can be done to putting the following in your ~/.bash_profile file: export PYTHONPATH="$PYTHONPATH:/path/to/repository/packages"

Compatibility

Currently the package only works in python 2.7, it does not work for me in python 3.

Usage

Parallel tempering is a monte-carlo method used to obtain equilibrium statistics for a physical system over a range of temperatures. When the energy landscape of the system is complex it can hugely speed up the convergence of ensemble averages, especially at low temperatures. It works by simulating N copies of the system (replicas) evolving independently at different temperatures [T1, T2, T3, ... ]. Periodically replicas at different temperatures are exchanged with some probability.

The main class (ptmpi.swaphandler) supports a fully parallelised implementation of parallel tempering using mpi4py (message passing interface for python). Each replica runs as a separate parallel process and they communicate via an mpi4py object. To minimise message passing the replicas stay in place and only the temperatures are exchanged between the processes at swaps. It is this exchange of temperatures that ptmpi handles. Another class (ptmpi.filehandler) provides a context manager that makes it easy for the processes to share a set of output files. This is useful since we will typically want the MCMC timeseries generated to be at fixed temperature.

The class is independent of the system being simulated or any details of the simulation. During regular MCMC update steps each replica queries ptmpi to obtain its current temperature index. At parallel tempering swap steps the replicas pass the information needed to decide whether a swap will occur to ptmpi.

example code

A fully worked example, using the two-dimensional Ising model, is given in the examples folder. It can be run using the shell script run_2d-ising_example.sh and the main python script is 2d-ising.py. An annotated version of 2d-ising.py is also provided, highlighting the important parts of the code. The subfolder notebooks has some Jupyter notebooks that give an example of opening the output data files and carrying out a simple analysis of the Monte Carlo timeseries.

ptmpi's People

Contributors

chris-n-self avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ptmpi's Issues

Adapting ptmpi for phylogenetics

Hi,
I am Taraka a post-doc working with linguistic phylogenetics. I implemented my MH sampler for sampling trees and other model parameters.

My code which runs mcmc process is here:
https://github.com/PhyloStar/CyBayes/blob/master/mat_mcmc_gamma.py

I write a state to file every t iterations. I am wondering how your program handles this. Does your class access the mcmc state in the child process and then perform swaps? I do not have much experience with mpi with python. I did mpi programming ages ago and don't remember much of the library. I need to run 4 chains (1 cold, 3 hot).

-Taraka

Installation issues

Hi Chris,

I am trying to download the ptmpi package that you shared here. I have installed mpi4py and mpich. But after running the Ising code I am getting as error in the very beginning itself, where it says: "ModuleNotFoundError: No module named 'ptmpi' ".
Is there something I am missing here? Apart from installing the above packages do I need to install something else?

-Best,
Sayonee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.