PyMatching
A package for decoding quantum error correcting codes using minimum-weight perfect matching.
What it is and what it does
PyMatching decodes quantum error correcting codes by solving the minimum-weight perfect matching problem on detector graphs derived from syndrome measurements. It is built on a sparse blossom algorithm that directly finds minimum-weight paths between detection events, avoiding the computational cost of all-to-all shortest-path searches. The library works with arbitrary weighted graphs (with or without boundaries) and can load matching graphs from check matrices, networkx graphs, or by adding edges individually using scipy, numpy, networkx, and matplotlib for numerical and graph operations.
The package is designed to decode surface codes and other code families (subsystem codes, honeycomb codes, 2D hyperbolic codes) in quantum error correction simulations. It can be configured with custom weighted graphs and integrates with external libraries for circuit-level noise simulation. As of v2.3, it also supports correlated matching to handle errors more accurately. Version 2 includes a substantially faster blossom implementation than earlier releases.
Use it for:
- Decode surface code circuits in quantum error correction simulations by configuring matching graphs from syndrome data.
- Estimate the threshold of an error correcting code by running multiple decoding trials with varying noise levels.
- Decode subsystem codes, honeycomb codes, or 2D hyperbolic codes by configuring custom weighted graphs.
- Perform correlated matching on circuits where error correlations are present between graphlike errors.
- Build custom quantum error correction workflows by adding edges individually to a matching graph.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
PyMatching is a fast Python/C++ library for decoding quantum error correcting codes using the Minimum Weight Perfect Matching (MWPM) decoder, designed to find the most probable set of errors from syndrome measurements.
Yes. PyMatching is actively maintained, has no known vulnerabilities, uses a permissive Apache 2 license, and is the standard decoder for surface codes in quantum error correction research. Install friction is moderate but manageable with prebuilt wheels. Choose it if you are working with quantum error correction; skip it if you have no quantum computing workflow.
Install
pymatching on PyPI
pip
pip install pymatchinguv
uv add pymatchingpoetry
poetry add pymatchingInstalling PyMatching
Before you install
Medium install friction due to compiled wheels for multiple Python versions and platforms (cp310–cp314 across macOS, Linux, Windows). Active maintenance with recent release (84 days old) and steady repository activity. Four runtime dependencies (scipy, numpy, networkx, matplotlib) are standard scientific stack packages.
License in practice
Apache 2 permissive license allows use in commercial and proprietary projects with minimal restrictions; you must include a copy of the license and note any modifications.
Quickstart
pip install pymatching
import pymatching
import numpy
import networkx
matching = pymatching.Matching()
matching.add_edge(0, 1, weight=1.0)
matching.add_boundary_edge(0, weight=0.5)
syndrome = numpy.array([1, 0, 1])
prediction = matching.decode(syndrome)
Verify before relying
- Whether the 100–1000x speedup claim in v2 applies to all use cases or primarily surface codes.
- Exact performance characteristics on different hardware architectures beyond M1 processor benchmarks.
- Whether correlated matching (v2.3+) is enabled by default or requires explicit configuration.
- Integration workflow and API details for use with external quantum simulation frameworks.
Package facts
| License | Apache 2 (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 4 — scipy, numpy, networkx, matplotlib |
| Maintenance | actively maintained — 84 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 184,387/month — #10,039 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pymatching-2.4.0-cp310-cp310-macosx_11_0_arm64.whl; pymatching-2.4.0-cp310-cp310-macosx_11_0_x86_64.whl; pymatching-2.4.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pymatching-2.4.0-cp310-cp310-win_amd64.whl; pymatching-2.4.0-cp311-cp311-macosx_11_0_arm64.whl; pymatching-2.4.0-cp311-cp311-macosx_11_0_x86_64.whl; pymatching-2.4.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pymatching-2.4.0-cp311-cp311-win_amd64.whl; pymatching-2.4.0-cp312-cp312-macosx_11_0_arm64.whl; pymatching-2.4.0-cp312-cp312-macosx_11_0_x86_64.whl; pymatching-2.4.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pymatching-2.4.0-cp312-cp312-win_amd64.whl; pymatching-2.4.0-cp313-cp313-macosx_11_0_arm64.whl; pymatching-2.4.0-cp313-cp313-macosx_11_0_x86_64.whl; pymatching-2.4.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pymatching-2.4.0-cp313-cp313-win_amd64.whl; pymatching-2.4.0-cp314-cp314-macosx_11_0_arm64.whl; pymatching-2.4.0-cp314-cp314-macosx_11_0_x86_64.whl; pymatching-2.4.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pymatching-2.4.0-cp314-cp314-win_amd64.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
ldpcProvides decoders for low-density parity check…
permissive · top 15,000 on PyPI
pytketPytket is a Python interface to TKET, a quantum…
permissive · top 15,000 on PyPI
sinterSinter performs fast Monte Carlo sampling of…
permissive · top 15,000 on PyPI
samplomaticSamplomatic generates randomized variants of…
permissive · top 15,000 on PyPI
qiskit-ibm-runtimeProvides a Python client to access IBM Quantum…
permissive · top 15,000 on PyPI
mqt.qcecVerifies whether two quantum circuits are…
permissive · top 15,000 on PyPI
correctionlibProvides a JSON-based format and evaluator for…
permissive · top 15,000 on PyPI
empirical-calibrationComputes empirical calibration weights to…
permissive · top 15,000 on PyPI
stimStim is a fast simulator for quantum stabilizer…
permissive · top 15,000 on PyPI
cirqCirq is a Python framework for writing,…
permissive · top 15,000 on PyPI