Skip to main content

mpiarray

Tests Static analysis Docs codecov PyPI Python

Distributed NumPy/CuPy arrays over MPI, with halo exchange, that you create like NumPy arrays:

import numpy as np

import mpiarray as mpa

a = mpa.array([1, 2, 3, 4])  # mpiexec -n 2: rank 0 holds [1, 2], rank 1 holds [3, 4]
b = mpa.zeros((64, 48), split=(0, 1), halo=1, periodic=(True, False))
c = 2 * a + np.sin(a)  # elementwise: no communication

total = c.sum()  # collective: the same value on every rank
full = c.gather()  # collective: the whole array on every rank
print(c)  # this rank's block; printing never communicates
mpiexec -n 2 python example.py   # or just: python example.py
  • Creation like NumPy: array, zeros, ones, full, empty, the *_like versions, arange, linspace and fromfunction, which compute only the local block. Arrays are split along their first axis by default; split= chooses other axes, split=None gives every rank the whole array.
  • Halo cells per axis: update_halos() before a stencil, accumulate_halos() after depositing particles near block edges.
  • Operators, ufuncs and reductions as in NumPy (sum, max, mean, norm, vdot, …); global reductions return the same host scalar on every rank.
  • NumPy or CuPy: arrays come from cunumpy, so the same code runs on the GPU. Without a CUDA-aware MPI, device buffers are copied through host memory; tell cunumpy once with xp.mpi.mpi_is_cuda_aware(comm) or xp.mpi.set_mpi_cuda_aware(False).
  • With or without MPI: without an MPI launcher the script runs as one rank on cunumpy’s stand-in for mpi4py.MPI, without importing mpi4py.
  • Data in and out: from_local builds an array from the pieces the ranks hold; save/load write and read ordinary .npy files in parallel with MPI-IO.
  • Halo boundary conditions at walls: constant, "edge", "symmetric", "reflect".
  • Debugging: with MPIARRAY_DEBUG=1, a collective called on only some ranks raises an error instead of hanging.

Each array has a layout (a mpa.Layout) with its process grid, neighbours and owned index ranges; most code only reads it.

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

Install

pip install "mpiarray[mpi]"   # with mpi4py, for runs under mpiexec
pip install mpiarray          # serial only, no MPI library needed

The mpi extra installs mpi4py, which needs an MPI library, e.g. brew install open-mpi or sudo apt-get install libopenmpi-dev openmpi-bin. Without it, mpiarray runs on cunumpy’s serial stand-in for mpi4py.MPI, as one rank holding the whole array. Starting such an installation with mpiexec gives a warning, and every process then computes the whole problem on its own.

For development, with uv:

make install    # uv sync --extra dev, plus the pre-commit hooks

or with pip, in a Python 3.10+ environment:

pip install -e ".[dev]"

The test, docs and dev extras install the test runner, the documentation tooling and the linters; dev includes mpi.

Development

Formatting and linting use ruff, type checking pyright and ty, run by pre-commit and in CI:

make lint     # ruff check, ruff format --check, pyright, ty
make test     # pytest with coverage

The tests run serially and under MPI; some only run on 2 or 6 ranks:

mpiexec -n 2 .venv/bin/python -m pytest
mpiexec -n 6 .venv/bin/python -m pytest
make coverage   # serial and 2, 3, 4, 6 ranks, combined; fails below 100% line coverage

Commit messages follow Conventional Commits; see CONTRIBUTING.md.

Build docs

The documentation in docs/ is an Astro + Starlight site: hand-written pages, the notebooks in tutorials/ executed and published as pages, and the API reference generated from the docstrings with starlight-pydocs. 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/mpiarray/
make docs-build       # the static site in docs/dist

Build the README

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/mpiarray/__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). The one-time PyPI and GitHub configuration is described in the publishing guide.

Metadata

Release files for mpiarray 0.1.0

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

Source distribution (sdist)

Source distribution for mpiarray 0.1.0
File Size Uploaded
mpiarray-0.1.0.tar.gz 60.9 kB Details

Built distribution (wheel)

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

Total release size: 128.5 kB

Release files / mpiarray-0.1.0.tar.gz

Download URL mpiarray-0.1.0.tar.gz
Size 60.9 kB
Tags Source
SHA-256 checksum
How to use checksums
894491cf096a303cf3314821a076c7da7fb0f7ba98aa332eb8e18a75507e80b1
BLAKE2b-256 checksum
How to use checksums
a27b69a0f757f91d022c36df8a170b90d501f3fe9bfe88f65b30d69a51c9f81a
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 / mpiarray-0.1.0-py3-none-any.whl

Download URL mpiarray-0.1.0-py3-none-any.whl
Size 67.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ed5623d8b78f8aba29fa4f21e9c0847e656c554e372a2125ac1b5df35e2e70f
BLAKE2b-256 checksum
How to use checksums
3d47a3c6152a4ec4f27be7e5fd39d4ec3602968368e319cf9897fd1e4bbc49af
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

This release

0.1.0 This release

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