Skip to main content

maybempi

Tests Static analysis Docs codecov PyPI Python

Use MPI only when the process was launched under MPI, and a serial stand-in for mpi4py otherwise. The same code runs under mpirun/srun and as a plain python script.py, and the serial run never starts MPI.

Documentation: https://max-models.github.io/maybempi/

from maybempi import MPI  # instead of: from mpi4py import MPI

# mpi4py.MPI under mpirun/mpiexec/srun, a serial stand-in otherwise
comm = MPI.COMM_WORLD
total = comm.allreduce(local_total, op=MPI.SUM)  # local_total in a serial run

Why

Importing mpi4py.MPI calls MPI_Init, which costs close to a second and makes every collective cost something, even on one process. maybempi decides from the environment variables that MPI launchers export (Open MPI, MPICH, Intel MPI, PMIx/srun, MVAPICH2, Cray), without importing mpi4py. In a serial run it returns a stand-in with the module constants and communicator methods of mpi4py, which give the results MPI gives on one process: allreduce(x) is x, gather(x) is [x], Allreduce(send, recv) copies. Methods it does not implement raise AttributeError instead of silently doing nothing.

  • MAYBEMPI=0/1 overrides the decision.
  • maybempi.is_serial(MPI) tells the stand-in from mpi4py.
  • maybempi.local_rank() gives the node-local rank before MPI_Init, e.g. to pick a GPU.
  • The maybempi command prints what it decides, and why: mpirun -n 2 maybempi --init.

maybempi is pure Python and has no dependencies.

Install

pip install maybempi            # serial runs only
pip install "maybempi[mpi]"     # with mpi4py, for MPI runs

Development

With uv:

make install    # uv sync --extra dev, plus the pre-commit hooks
make lint       # ruff check, ruff format --check, pyright
make test       # pytest with coverage
mpiexec -n 2 .venv/bin/python -m pytest src/maybempi/tests/mpi   # tests under a real launcher

Commit messages follow Conventional Commits; see CONTRIBUTING.md.

The documentation in docs/ is an Astro + Starlight site with the executed notebooks from tutorials/ and an API reference generated from the docstrings. It needs Node 22 or newer:

make docs-install     # npm packages and the Python docs extra
make docs-notebooks   # execute tutorials/*.ipynb and convert them to pages
make docs-dev         # live preview at http://localhost:4321/maybempi/

README.md is rendered from README.qmd with Quarto: make readme.

Releases

Before merging a release to main, update the version in pyproject.toml, src/maybempi/__init__.py and CITATION.cff (including its release date), and add the release notes to CHANGELOG.md. The push to main creates a GitHub release with a vX.Y.Z tag and publishes the package to PyPI with trusted publishing (OIDC). See the publishing guide.

Metadata

Release files for maybempi 0.1.2

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

Source distribution (sdist)

Source distribution for maybempi 0.1.2
File Size Uploaded
maybempi-0.1.2.tar.gz 42.9 kB Details

Built distribution (wheel)

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

Total release size: 90.3 kB

Release files / maybempi-0.1.2.tar.gz

Download URL maybempi-0.1.2.tar.gz
Size 42.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0b0fadd2897281df50a2cf3f08ddf080d1ca00c9d2e4e5aee2af7cf5222ba04d
BLAKE2b-256 checksum
How to use checksums
c40ded782142085f56da45eb4511dd3fb2a7b1ed167fe5495dd429c61272774e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / maybempi-0.1.2-py3-none-any.whl

Download URL maybempi-0.1.2-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fc9a2eb7e4f55a6b91da32e8e77bade35df157e6ce5de3b228cdf799e99970b
BLAKE2b-256 checksum
How to use checksums
88d3b161669937ee87dba4c61a6ac2be70bd1399269c76c66524e3f8be071839
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.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