Skip to main content

Parallel tempering MCMC sampler written in Python

Project description

PTMCMCSampler

GitHub release (latest by date) PyPI Conda Version GitHub Workflow Status (event)

DOI Python Versions GitHub license

NOTE: This project was moved under the [NANOGrav][https://github.com/nanograv] github organization in November 2023

MPI enabled Parallel Tempering MCMC code written in Python.

See the examples for some simple use cases.

For MPI support you will need A functional MPI 1.x/2.x/3.x implementation like:

  • MPICH

    # mac
    brew install mpich
    
    # debian
    sudo apt install mpich
    
  • Open MPI

    # mac
    brew install open-mpi
    
    # debian
    sudo apt install libopenmpi-dev
    

To run with MPI support you can run your script containing a sampler with:

mpirun -np <number of temperature chains> script.py

This will kick off np chains running at different temperatures. The temperature ladder and sampling schemes can be set in the PTMCMCSampler.sample() method.

Installation

Development

For development clone this repo and run:

make init
source venv/bin/activate

Via pip

pip install ptmcmcsampler

for MPI support use

pip install ptmcmcsampler[mpi]

Via conda

conda install -c conda-forge ptmcmcsampler

for MPI support use

conda install -c conda-forge ptmcmcsampler mpi4py

Via Docker

Production:

For production use, the latest release of PTMCMCSampler is installed directly from PyPi.

# Build the image, tagging it as `ptmcmc:latest`.  
# 
# This example includes both optional MPI support and the optional `acor` library 
# (you can omit either / both).
docker build --pull --build-arg "MPI=1" --build-arg "ACOR=1" -t ptmcmc --no-cache .

# Run the image, mounting the `data/` subdirectory on your computer 
# to `/code/data/` inside the Docker container. Note that MPI won't work 
# if we run as the root user (the default).
docker run -it --rm --user mcmc_user -v $(pwd)/data:/code/data ptmcmc

# When finished with the container, exit back to the host OS
CTRL^D

Development:

For PTMCMCSampler development, dependencies are installed from requirements.txt and requirements_dev.txt. No PTMCMCSampler code is omitted from the built image, whose purpose is for testing new code. You can also add --build-arg "ACOR=1" to the build command to include the optional acor dependency (MPI is always included via requirements.txt).

# Build the image
docker build --pull -t ptmcmc --build-arg "TARGET_ENV=dev" --no-cache .

# Run the image, mounting the working directory on the host OS to /code/ inside the container.
# MPI won't work if we run as the root user (the default).
docker run -it --rm --user mcmc_user -v $(pwd)/:/code ptmcmc

# Exit back to host OS
CTRL-D

Attribution

If you make use of this code, please cite:

@misc{justin_ellis_2017_1037579,
  author       = {Justin Ellis and
                  Rutger van Haasteren},
  title        = {jellis18/PTMCMCSampler: Official Release},
  month        = oct,
  year         = 2017,
  doi          = {10.5281/zenodo.1037579},
  url          = {https://doi.org/10.5281/zenodo.1037579}
}

Correlation Length

In order for the sampler to run correctly using acor with Python 3 kernels the GitHub version of acor needs to be installed. (Currently the PyPI version is behind the GitHub version.) It can be easily installed with:

pip install git+https://github.com/dfm/acor.git@master

Note that acor is not required to run the sampler, it simply calculates the effective chain length for output in the chain file.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ptmcmcsampler-2.1.2.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

ptmcmcsampler-2.1.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file ptmcmcsampler-2.1.2.tar.gz.

File metadata

  • Download URL: ptmcmcsampler-2.1.2.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for ptmcmcsampler-2.1.2.tar.gz
Algorithm Hash digest
SHA256 3570c062abb849b0bd1e80c9d35a5cd13f88da7f5006aac98a5dfc0abdcc15bb
MD5 5f28f00304c9d42ef53959458cc8af3b
BLAKE2b-256 1d9cd0dec337710b6a81873bfa030ca32b5c02a8a1835eb14ff8107ab3b2d12c

See more details on using hashes here.

File details

Details for the file ptmcmcsampler-2.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ptmcmcsampler-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3162c14ec5b9504bf944fffd29d78579b77bea037241b2904531906c62adf654
MD5 0287a5915cc9a222eca0cf9e92a45424
BLAKE2b-256 98fffaa4ad4e28f8b25312da7e897cbb3f199f5198a3c22a6c6df0f281517bd7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page