Skip to main content

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.


Metadata

Release files for ptmcmcsampler 2.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ptmcmcsampler 2.1.4
File Size Uploaded
ptmcmcsampler-2.1.4.tar.gz 1.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for ptmcmcsampler 2.1.4
File Interpreter ABI Platform
ptmcmcsampler-2.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 1.9 MB

Release files / ptmcmcsampler-2.1.4.tar.gz

Download URL ptmcmcsampler-2.1.4.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
80d0d0b616a7170de2e0e3ac45fed31ff482da8a66de9ef646ed02b42da7fee9
BLAKE2b-256 checksum
How to use checksums
d19774caab69b443bc16ae95ff3f4a1ff54abeba67505140c2b86893e865b624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.18

Release files / ptmcmcsampler-2.1.4-py3-none-any.whl

Download URL ptmcmcsampler-2.1.4-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
954892f4d1e24fb0b412cc437dd0b210faaa1500e147ae99b2217956de8a2943
BLAKE2b-256 checksum
How to use checksums
e5bdedd11ec96eb69e20c40f1b4b2afe60a96bc0c69b5c37b48a602477017462
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.18

Release history Release notifications | RSS feed

This release

2.1.4 This release

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page