跳转到主要内容

用Python编写的并行温度MCMC采样器

项目描述

PTMCMCSampler

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

DOI Python Versions GitHub license

注意:该项目于2023年11月迁移到了[NANOGrav][https://github.com/nanograv] github组织

MPI启用并行温度MCMC代码,用Python编写。

请参阅示例了解一些简单的用法。

对于MPI支持,您需要A功能性的MPI 1.x/2.x/3.x实现,例如

  • MPICH

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

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

要使用MPI支持运行,您可以运行包含采样器的脚本

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

这将启动np个在不同温度下运行的链。温度梯度和采样方案可以在PTMCMCSampler.sample()方法中设置。

安装

开发

对于开发,克隆此存储库并运行

make init
source venv/bin/activate

通过pip

pip install ptmcmcsampler

对于MPI支持使用

pip install ptmcmcsampler[mpi]

通过conda

conda install -c conda-forge ptmcmcsampler

对于MPI支持使用

conda install -c conda-forge ptmcmcsampler mpi4py

通过Docker

生产:

对于生产使用,PTMCMCSampler的最新版本可以直接从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

开发:

对于PTMCMCSampler的开发,依赖项从requirements.txtrequirements_dev.txt中安装。构建的镜像中不省略任何PTMCMCSampler代码,其目的是为了测试新代码。您还可以在构建命令中添加--build-arg "ACOR=1"来包含可选的acor依赖项(通过requirements.txt始终包含MPI)。

# 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

归属

如果您使用了此代码,请引用

@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}
}

相关长度

为了使采样器能够在Python 3内核中使用acor正确运行,需要安装GitHub版本的acor。 (目前PyPI版本落后于GitHub版本。)它可以很容易地安装。

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

请注意,acor不是运行采样器所必需的,它只是简单地计算链文件中输出的有效链长。


项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

ptmcmcsampler-2.1.2.tar.gz (1.8 MB 查看哈希值)

上传时间 源代码

构建分发

ptmcmcsampler-2.1.2-py3-none-any.whl (21.4 kB 查看哈希值)

上传时间 Python 3

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面