Skip to main content

Python interface to PartMC

Project description

logo

PyPartMC

PyPartMC is a Python interface to PartMC, a particle-resolved Monte-Carlo code for atmospheric aerosol simulation. PyPartMC is implemented in C++ and it also constitutes a C++ API to the PartMC Fortran internals. The Python API can facilitate using PartMC from other environments - see, e.g., Julia example below.

US Funding License: GPL v3 Copyright Maintenance Github Actions Build Status API docs

TL;DR (try in a Jupyter notebook)

Python 3 Linux OK macOS OK Windows OK Jupyter

! pip install PyPartMC
import PyPartMC

Jupyter notebooks with examples

  • Urban plum scenario demo (as in PartMC):
    nbviewer Open In Colab Binder
  • Dry-Wet Particle Size Equilibration with PartMC and PySDM:
    nbviewer Open In Colab Binder Voila

Features

  • works on Linux, macOS and Windows (compatibility assured with CI builds)
  • hassle-free installation using pip (prior PartMC installation not needed)
  • works out of the box on mybinder.org, Google Colab and alike
  • ships with a set of examples maintained in a form of Jupyter notebooks
  • Pythonic API (but retaining PartMC jargon) incl. Python GC deallocation of Fortran objects
  • specification of parameters using native Python datatypes (lists, dicts) in place of PartMC spec files
  • code snippets in README depicting how to use PyPartMC from Julia (also executed on CI)
  • auto-generated API docs on the web
  • support for [de]serialization of selected wrapped structures using JSON
  • based on unmodified PartMC code
  • does not use or require shell or netCDF Fortran library
  • aiming at 100% unit test coverage

Usage examples

example object instantiation in Python

import PyPartMC as ppmc
print(ppmc.__version__)
gas_data = ppmc.GasData(("H2SO4", "HNO3", "HCl", "NH3", "NO", "NO2"))

example object instantiation in Julia

using Pkg
Pkg.add("PyCall")

using PyCall
ppmc = pyimport("PyPartMC")
print(ppmc.__version__)
gas_data = ppmc.GasData(("H2SO4", "HNO3", "HCl", "NH3", "NO", "NO2"))

usage in other projects

PyPartMC is used within the test workflow of the PySDM project.

Implementation outline

  • PyPartMC is written in C++, Fortran and uses pybind11 and CMake.
  • JSON support is handled with nlohmann::json and pybind11_json
  • PartMC and selected parts of SUNDIALS are statically linked (and compiled in during pip install or python -m build)
  • C (SUNDIALS), C++ (pybind11, ...) and Fortran (PartMC, CAMP) dependencies are linked through git submodules
  • MOSAIC dependency is optionally linked through setting the environmental variable MOSAIC_HOME
  • a mock of Fortran netCDF API and a mock of PartMC spec file API are used for i/o from/to JSON

Troubleshooting

Common installation issues

error: [Errno 2] No such file or directory: 'cmake'

Try rerunning after installing CMake (e.g., apt-get install cmake or brew install cmake)

No CMAKE_Fortran_COMPILER could be found.

Try installing a Fortran compiler (e.g., brew reinstall gcc)

Notes for developers

How to debug

git clone --recursive git+https://github.com/open-atmos/PyPartMC.git
cd PyPartMC
DEBUG=1 VERBOSE=1 pip --verbose install -e .
gdb python 
(gdb) run -m pytest -s -vv -We -p no:unraisableexception tests

Pre-commit hooks

PyPartMC codebase benefits from Pylint, Black and isort code analysis (which are all part of the CI workflows where we also use pre-commit hooks. The pre-commit hooks can be run locally, and then the resultant changes need to be staged before committing. To set up the hooks locally, install pre-commit via pip install pre-commit and set up the git hooks via pre-commit install (this needs to be done every time you clone the project). To run all pre-commit hooks, run pre-commit run --all-files. The .pre-commit-config.yaml file can be modified in case new hooks are to be added or existing ones need to be altered.

Credits

PyPartMC:

authors: PyPartMC developers
funding: US Department of Energy Atmospheric System Research programme
copyright: University of Illinois at Urbana-Champaign
licence: GPL v3

PartMC:

authors: Nicole Riemer, Matthew West, Jeff Curtis et al.
licence: GPL v2 or later

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

PyPartMC-0.2.0.tar.gz (1.6 MB view hashes)

Uploaded Source

Built Distributions

PyPartMC-0.2.0-cp311-cp311-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

PyPartMC-0.2.0-cp311-cp311-manylinux_2_24_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.24+ x86-64

PyPartMC-0.2.0-cp311-cp311-macosx_12_0_universal2.whl (929.1 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ universal2 (ARM64, x86-64)

PyPartMC-0.2.0-cp310-cp310-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

PyPartMC-0.2.0-cp310-cp310-manylinux_2_24_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

PyPartMC-0.2.0-cp310-cp310-macosx_12_0_x86_64.whl (929.1 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

PyPartMC-0.2.0-cp39-cp39-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

PyPartMC-0.2.0-cp39-cp39-manylinux_2_24_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

PyPartMC-0.2.0-cp39-cp39-macosx_12_0_x86_64.whl (929.2 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

PyPartMC-0.2.0-cp38-cp38-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

PyPartMC-0.2.0-cp38-cp38-manylinux_2_24_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

PyPartMC-0.2.0-cp38-cp38-macosx_12_0_x86_64.whl (929.0 kB view hashes)

Uploaded CPython 3.8 macOS 12.0+ x86-64

PyPartMC-0.2.0-cp37-cp37m-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

PyPartMC-0.2.0-cp37-cp37m-manylinux_2_24_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

PyPartMC-0.2.0-cp37-cp37m-macosx_12_0_x86_64.whl (926.5 kB view hashes)

Uploaded CPython 3.7m macOS 12.0+ x86-64

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