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

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.1
File Size Uploaded
maybempi-0.1.1.tar.gz 22.8 kB Details

Built distribution (wheel)

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

Total release size: 47.0 kB

Release files / maybempi-0.1.1.tar.gz

Download URL maybempi-0.1.1.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bb1757c98345b9bb6182398fdf69c2e9dd6ba761abb48380825a4e9c6557c0d1
BLAKE2b-256 checksum
How to use checksums
e867a6b9baace877ad6a0efc7ca52323e34d5269e9a3728d486fbc476c46b3fb
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 6, 2026.

Transparency log

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

Download URL maybempi-0.1.1-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9eea52715ca4168fc39d6cea7e7f6a72c3aaab03f35d560273505673d0f8012
BLAKE2b-256 checksum
How to use checksums
64253af615b85ad04b94a13f4a6725b10316361bd0ebccf708d35d20118ea240
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 6, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

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