PyMatching is a high-performance Python package for decoding quantum error correcting codes using minimum-weight perfect matching algorithms. It provides an efficient C++ implementation of the blossom algorithm, significantly speeding up decoding for large codes. The library is actively maintained with frequent minor releases for bug fixes and feature additions, and major updates approximately every 1-2 years introducing significant architectural changes or performance improvements. The current version is 2.3.1.
pip install pymatchingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `Matching` object from a `scipy.sparse` matrix representing a parity check matrix, simulate a syndrome, and decode it to find the most likely error pattern.
Upgrade to v2.0.0+ and verify decoding logic and performance. The public API generally remained stable, but internal behavior for large codes changed significantly.
Migrate to `rustworkx` and use `Matching.load_from_rustworkx` and `Matching.to_rustworkx` methods instead. `rustworkx` is not a direct dependency, so install it explicitly if needed (`pip install rustworkx`).
Ensure you are using PyMatching v2.2.2 or later if you wish to use `numpy` v2.0.0+. Alternatively, downgrade `numpy` to a v1.x version for older PyMatching releases.
When processing multiple syndrome measurements, use `matching.decode_batch(syndromes_batch)` where `syndromes_batch` is a 2D array of syndromes, typically `(num_shots, num_stabilizers)`.
If using correlated matching, ensure you upgrade to PyMatching v2.3.1 or later to avoid potential segmentation faults and incorrect behavior.
Install the package using pip: `pip install pymatching`
Change your code to use `matching.load_from_rustworkx()` or `matching.to_rustworkx()`. Ensure `rustworkx` is installed (`pip install rustworkx`).
Convert your graph representation to a `scipy.sparse` matrix (e.g., `scipy.sparse.csc_matrix`), `networkx.Graph`, or `rustworkx.PyGraph` before passing it to the `Matching` constructor.
Upgrade PyMatching to v2.3.1 or later. This bug was specifically addressed and fixed in that release.