Skip to main content

PyMatching

Continuous Integration codecov docs PyPI version Unitary Fund

PyMatching is a fast Python/C++ library for decoding quantum error correcting codes (QECC) using the Minimum Weight Perfect Matching (MWPM) decoder. PyMatching can decode codes for which each error generates a pair of syndrome defects (or only a single defect at a boundary). Codes that satisfy these properties include two-dimensional topological codes such as the toric code, the surface code and 2D hyperbolic codes, amongst others. PyMatching can also be used as a subroutine to decode other codes, such as the 3D toric code and the color code. PyMatching can handle boundaries, measurement errors and weighted edges in the matching graph. Since the core algorithms are written in C++, PyMatching is much faster than a pure Python NetworkX implementation.

Documentation for PyMatching can be found at: pymatching.readthedocs.io

Installation

PyMatching can be downloaded and installed from PyPI with the command:

pip install pymatching

This is the recommended way to install PyMatching since pip will fetch the pre-compiled binaries, rather than building the C++ extension from source on your machine. Note that PyMatching requires Python 3.6 or later.

If instead you would like to install PyMatching from source, clone the repository (using the --recursive flag to include the lib/pybind11 submodule) and then use pip to install:

git clone --recursive https://github.com/oscarhiggott/PyMatching.git
pip install -e ./PyMatching

The installation may take a few minutes since the C++ extension has to be compiled. If you'd also like to run the tests, first install pytest, and then run:

pytest ./PyMatching/tests

Usage

In order to decode a parity check matrix H (a scipy.sparse matrix) with syndrome vector z (a bitstring which is a numpy array of dtype int), first construct the Matching object after importing it:

from pymatching import Matching
m = Matching(H)

Now to decode, simply run:

c = m.decode(z)

which outputs a bitstring c, which is a numpy array of ints corresponding to the minimum-weight correction. Note that the m by n parity check matrix H should correspond to the Z (or X) stabilisers of a CSS code with n qubits, m Z (or X) stabilisers, and with either one or two non-zero entries per column.

To decode instead in the presence of measurement errors, each stabiliser measurement is repeated L times, and decoding then takes place over a 3D matching graph (see Section IV B of this paper), which can be constructed directly from the check matrix H using:

m = Matching(H, repetitions=L)

and then decoded from an m by L numpy array syndrome z using:

c = m.decode(z)

The Matching object can also be constructed from a NetworkX graph instead of a check matrix, and can handle weighted edges. For full details see the documentation.

Performance

While all the functionality of PyMatching is available via the Python bindings, the core algorithms and data structures are implemented in C++, with the help of the Lemon and Boost Graph libraries. PyMatching also uses a local variant of the MWPM decoder (explained in the Appendix of this paper) that has a runtime that is approximately linear, rather than quadratic, in the number of nodes. As a result, PyMatching is orders of magnitude faster than a standard pure Python NetworkX implementation, as shown here for decoding the toric code under an independent noise model with p=0.05 and noiseless syndrome measurements:

Attribution

When using PyMatching for research, please cite:

@misc{higgott2020pymatching,
  author = {Higgott, Oscar},
  title = {{PyMatching}: A Python package for decoding quantum error correcting codes using minimum-weight perfect matching},
  year = {2020},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/oscarhiggott/PyMatching}}
}

Metadata

Release files for PyMatching 0.2.5

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

Source distribution (sdist)

Source distribution for PyMatching 0.2.5
File Size Uploaded Provenance Actions
PyMatching-0.2.5.tar.gz 10.7 MB Without provenance Details for PyMatching-0.2.5.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for PyMatching 0.2.5
File Actions
PyMatching-0.2.5-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for PyMatching-0.2.5-cp39-cp39-win_amd64.whl
PyMatching-0.2.5-cp39-cp39-manylinux2010_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.12+ x86-64 Details for PyMatching-0.2.5-cp39-cp39-manylinux2010_x86_64.whl
PyMatching-0.2.5-cp39-cp39-manylinux2010_i686.whl CPython 3.9 CPython 3.9 Linux glibc 2.12+ x86-32 Details for PyMatching-0.2.5-cp39-cp39-manylinux2010_i686.whl
PyMatching-0.2.5-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details for PyMatching-0.2.5-cp39-cp39-macosx_10_9_x86_64.whl
PyMatching-0.2.5-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for PyMatching-0.2.5-cp38-cp38-win_amd64.whl
PyMatching-0.2.5-cp38-cp38-manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64 Details for PyMatching-0.2.5-cp38-cp38-manylinux2010_x86_64.whl
PyMatching-0.2.5-cp38-cp38-manylinux2010_i686.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-32 Details for PyMatching-0.2.5-cp38-cp38-manylinux2010_i686.whl
PyMatching-0.2.5-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details for PyMatching-0.2.5-cp38-cp38-macosx_10_9_x86_64.whl
PyMatching-0.2.5-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for PyMatching-0.2.5-cp37-cp37m-win_amd64.whl
PyMatching-0.2.5-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details for PyMatching-0.2.5-cp37-cp37m-manylinux2010_x86_64.whl
PyMatching-0.2.5-cp37-cp37m-manylinux2010_i686.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-32 Details for PyMatching-0.2.5-cp37-cp37m-manylinux2010_i686.whl
PyMatching-0.2.5-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details for PyMatching-0.2.5-cp37-cp37m-macosx_10_9_x86_64.whl
PyMatching-0.2.5-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for PyMatching-0.2.5-cp36-cp36m-win_amd64.whl
PyMatching-0.2.5-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details for PyMatching-0.2.5-cp36-cp36m-manylinux2010_x86_64.whl
PyMatching-0.2.5-cp36-cp36m-manylinux2010_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-32 Details for PyMatching-0.2.5-cp36-cp36m-manylinux2010_i686.whl
PyMatching-0.2.5-cp36-cp36m-macosx_10_9_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64 Details for PyMatching-0.2.5-cp36-cp36m-macosx_10_9_x86_64.whl

Total release size: 13.4 MB

Release files / PyMatching-0.2.5.tar.gz

Download URL PyMatching-0.2.5.tar.gz
Size 10.7 MB
Tags Source
SHA-256 checksum
How to use checksums
09331fc70f51462fe5b1fad0b92ee8f0cb74a4310e33f818107b3367222906d0
BLAKE2b-256 checksum
How to use checksums
5324cb7410a8276911230b10c14fef770d0d31058bf997fc20645216e5358212
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp39-cp39-win_amd64.whl

Download URL PyMatching-0.2.5-cp39-cp39-win_amd64.whl
Size 148.0 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
cd750a4381e09330cc035d807e8ecd3319c2aec285dc58de5ee63b3c9e5f0437
BLAKE2b-256 checksum
How to use checksums
4f02d0083bed5aec97d2e71a5a1cc72d532abcf076ff7fe2a8c77be65ba3567e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp39-cp39-manylinux2010_x86_64.whl

Download URL PyMatching-0.2.5-cp39-cp39-manylinux2010_x86_64.whl
Size 175.6 kB
Tags CPython 3.9 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
32f9933ebb91a6b445555fce718c1cfe13b1cc25f4cff26402ef54fb227132c0
BLAKE2b-256 checksum
How to use checksums
d9b2afe77e185f0adcf7cd0827d48cdc97a121b8aed975da7a75d72e87baf90b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp39-cp39-manylinux2010_i686.whl

Download URL PyMatching-0.2.5-cp39-cp39-manylinux2010_i686.whl
Size 183.3 kB
Tags CPython 3.9 Linux glibc 2.12+ x86-32
SHA-256 checksum
How to use checksums
40b2a3c8d9e9a2d5ef3d6cbc500ccd8bea843dfe7546fabb735013a09ad75236
BLAKE2b-256 checksum
How to use checksums
0dabbf99e27b0f981308b3c8db767caecb53e7cc5863132f172e253abd8c60e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp39-cp39-macosx_10_9_x86_64.whl

Download URL PyMatching-0.2.5-cp39-cp39-macosx_10_9_x86_64.whl
Size 150.8 kB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
b42ef0e8083fb0606a6a6718c4cf1774527be0870c46516400cc557896b2e484
BLAKE2b-256 checksum
How to use checksums
7d319b8c119b0f98b7e19f4a4f22aeb2c5e21613801ed151cb87a1feae1a2321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp38-cp38-win_amd64.whl

Download URL PyMatching-0.2.5-cp38-cp38-win_amd64.whl
Size 147.9 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
338a0e809f10c590f2b259d0dd88110468b63918e9d7470be1b17262db53bab9
BLAKE2b-256 checksum
How to use checksums
d3ebb6d4a3a5fd2d587bc9e15e2e0d146b5a0387b318fe76f21335be36c695a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp38-cp38-manylinux2010_x86_64.whl

Download URL PyMatching-0.2.5-cp38-cp38-manylinux2010_x86_64.whl
Size 175.8 kB
Tags CPython 3.8 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
fd954c62337e59aec0d14e25b996c250d406363d1a2d3354d919274575d003e7
BLAKE2b-256 checksum
How to use checksums
99638ed688a3b37ca6c19f2cd6abf0ae6ae91932ead40350efa170c17120cee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp38-cp38-manylinux2010_i686.whl

Download URL PyMatching-0.2.5-cp38-cp38-manylinux2010_i686.whl
Size 183.1 kB
Tags CPython 3.8 Linux glibc 2.12+ x86-32
SHA-256 checksum
How to use checksums
fb4a3223fa75e107b03205fb366b0fcaff0fbb4f6d232e3078043404bfa469e1
BLAKE2b-256 checksum
How to use checksums
b077cf6c504b4afb42b96827be05764060d7d1ac51a425c2072359172a4c5378
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp38-cp38-macosx_10_9_x86_64.whl

Download URL PyMatching-0.2.5-cp38-cp38-macosx_10_9_x86_64.whl
Size 150.7 kB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
5e02048c81a86d5f7a09746396153d336fe57052a51dfac745af2c21f66a6a0b
BLAKE2b-256 checksum
How to use checksums
9f6c317534007e7eb7cd6995ae86ed2ce9c3af28964b9a172a4e5fdd3a5d9e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp37-cp37m-win_amd64.whl

Download URL PyMatching-0.2.5-cp37-cp37m-win_amd64.whl
Size 148.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
a0d68edad3e9d3397aa02527166d078ab740285894bd20f1dc3409e8fddcebbc
BLAKE2b-256 checksum
How to use checksums
d7c20038e7b8295c9f80c81040a4a3637e63ed7c8a2a5b71cf004a93ebe16b3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp37-cp37m-manylinux2010_x86_64.whl

Download URL PyMatching-0.2.5-cp37-cp37m-manylinux2010_x86_64.whl
Size 177.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
17fbad194a7f6f1f50387f866de6f85d09a83ff72c6c81d1b74b7b545a9d07ed
BLAKE2b-256 checksum
How to use checksums
db565b6407fb4fc8737f2a0589ca6a0e99f3d9c21439f9cf1c6117bb8dc403cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp37-cp37m-manylinux2010_i686.whl

Download URL PyMatching-0.2.5-cp37-cp37m-manylinux2010_i686.whl
Size 186.0 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-32
SHA-256 checksum
How to use checksums
567eea45ec0e497aaa5d3453c812c8ba0729c39d294c61386b7188a59f8f4ca3
BLAKE2b-256 checksum
How to use checksums
12a5c4435f740337218314f9c399dca98141403c504b82dfd5f86edad37df707
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL PyMatching-0.2.5-cp37-cp37m-macosx_10_9_x86_64.whl
Size 149.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
e6574eb5ab74181ffa14fb8bccbe6e412fb7137ebdbf6be6b2506c3fb5ad1b00
BLAKE2b-256 checksum
How to use checksums
685f109be3cb21fc459f8fb19bae8660c176879305ce6aa411fda954397bdc22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp36-cp36m-win_amd64.whl

Download URL PyMatching-0.2.5-cp36-cp36m-win_amd64.whl
Size 148.4 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
7a4c778a260e5a705f726082ae8411ec4427e45653f3ef50de8ac69b2bcc0fbb
BLAKE2b-256 checksum
How to use checksums
7908799262b87e1c4eb1b0baac1ea2b230357629675e8488d188eacff6a573f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp36-cp36m-manylinux2010_x86_64.whl

Download URL PyMatching-0.2.5-cp36-cp36m-manylinux2010_x86_64.whl
Size 177.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
e4fcecab208ca78ae059bf38a1bd7f766a060d6f0619b048aa048b4162b0fd8e
BLAKE2b-256 checksum
How to use checksums
eac51b573f84ea684efd26524ff2421c9cc4fb13de82d6a202f0be6ebfdb13a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp36-cp36m-manylinux2010_i686.whl

Download URL PyMatching-0.2.5-cp36-cp36m-manylinux2010_i686.whl
Size 185.9 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-32
SHA-256 checksum
How to use checksums
2bbcf17d106586080bfc8c79680a86c882a7a95c19542f7739d074ce1f40d2a5
BLAKE2b-256 checksum
How to use checksums
533bb33d717d1defdc84aeb0acda235d0d53500461e4a4fe39dd2f1f8c73d726
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Release files / PyMatching-0.2.5-cp36-cp36m-macosx_10_9_x86_64.whl

Download URL PyMatching-0.2.5-cp36-cp36m-macosx_10_9_x86_64.whl
Size 149.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
b6f9a6a22ebdc66ad6319de060d11ed9bf78d7e9eefed7b59d9b5771ca27f133
BLAKE2b-256 checksum
How to use checksums
51f5deb5866dd5fcbcb86096b631d2c6b9c234222a889ecfbb7c090628c6d63c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

Security for PyMatching 0.2.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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