A package for decoding quantum error correcting codes using minimum-weight perfect matching.
Project description
PyMatching
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.
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:
@article{higgott2021pymatching,
title={{PyMatching}: A fast implementation of the minimum-weight perfect matching decoder},
author={Higgott, Oscar},
journal={arXiv preprint arXiv:2105.13082},
year={2021}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for PyMatching-0.3.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2326aa9a39144cac3f245ae5c422b9c00c5101edad614d302f5a764623fc1e3d |
|
MD5 | 686ecc2e3a106874ead3b5fdbb70b5a8 |
|
BLAKE2b-256 | 52183f2e5be52e9bd77c9084f438413172f5b4c453fe28bbc71a1ce8d0d5b799 |
Hashes for PyMatching-0.3.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65dadd96ea23f44a13cd9dbb7fc49ed779697d12cd91ce3905687134195a4bfc |
|
MD5 | 686ff003c875ad093053ebddad85d2f0 |
|
BLAKE2b-256 | 56bbc67591decff73ac39d8b75ce7dd54a12db76e8240e5d418bd6f58d5f2fc4 |
Hashes for PyMatching-0.3.1-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 521976d77022ac48efea33c53b4bb78c38818e2fa7d46c75aaccf0fcdf69d790 |
|
MD5 | 5a5c693e0c6ce7fb59433af71745483e |
|
BLAKE2b-256 | 99555f92e7de3776eeae60b85caa71854557a348d9a31aa0bf38fd9c6baf10a1 |
Hashes for PyMatching-0.3.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a11734bc4628821cd0a4c9fd5c43c8f27177e6201b8f7992fddb69162c963bff |
|
MD5 | ee9f2efd12cf65e7eb56956968272c44 |
|
BLAKE2b-256 | eb37fc1ade62ae7f5dbd06a140a3719d32b1044673ac4d3e78dd43d9a5742207 |
Hashes for PyMatching-0.3.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a63ea5b1aaac16a47726c6b9ae994dab750940f3a289ef597f2ead7dd061a059 |
|
MD5 | c4b19e285735bb4f6cfcc06e7ee0e8b9 |
|
BLAKE2b-256 | 1d35604125f83898ae58c9a0fc37e729669ef149c4e68ae107d1184860bebd09 |
Hashes for PyMatching-0.3.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6135023144f7612f0ad35016961a3f279b621e2bfbbbe819ba4720b2604416ab |
|
MD5 | fc90f830fc7f8a1f7934d199db162042 |
|
BLAKE2b-256 | 0557e6751f64a53583bae113cdb7a5eb1eebc76eb638da7c6b8cbcdd4b46436f |
Hashes for PyMatching-0.3.1-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3799cd3e4290e9da86d92d739d02643f851957ede2bd352aae3ef3a342973576 |
|
MD5 | 6ddc26992e912fefe472b049f9206907 |
|
BLAKE2b-256 | 5dd014663b153a5578c764352fd1f84f493fca9c8d7b62f4e92c481d77c31d7c |
Hashes for PyMatching-0.3.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 499cc393d739336a3fe4bc7b61a7cb80b1fb2ff4996afbdda112d9a7cecab4ba |
|
MD5 | 94b61d2732da7262db6f6bb8be83d788 |
|
BLAKE2b-256 | 30a505714fd51cfff3a235eda71ee7ecc6b8a94082aa462297431ae81bc0f832 |
Hashes for PyMatching-0.3.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a3c719bf325fb95dee71e3a3d594542206b1ba3904f73477e811ef8c2616dea |
|
MD5 | f2eb25c749afa799250f083ce91435a5 |
|
BLAKE2b-256 | bb2e8a419b7558fbca066322d8f36a1891b93b9d2efc1a168697c759dfd670a5 |
Hashes for PyMatching-0.3.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46256afd288c8ab0e68d0fa415bc9e9e5e8c89671167a5a1e39f727894209ea0 |
|
MD5 | edaf387c9ca70e1a785b6fa2838aa5c6 |
|
BLAKE2b-256 | de16ec83f6894d853cc2c4dd965ad821699e3f68b3df29d10ec58eaf70c9237f |
Hashes for PyMatching-0.3.1-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 016225e6b70b435dbdb129fcae56536eb0fa0bea803ccecaf47b5f0a06db0d2e |
|
MD5 | 14a33d451c255fa238022b4975467e9f |
|
BLAKE2b-256 | e84d6e3f667b5db07b210093c7d25698a9933339d45d22a4736bf1ef3181194c |
Hashes for PyMatching-0.3.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f698207248a2645d4e751a9f1144568e8562265d1fd9dd86b59dff3fbd6387d8 |
|
MD5 | 728844a375588cce66e9fc424cbf2099 |
|
BLAKE2b-256 | c67fca4ca2529ae4224fa71bae986d70a514335fdbedcaa24766af4f95bb8f74 |
Hashes for PyMatching-0.3.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14975162fbe975639d9ee6fcdcd18d6ecc7cbaebd2180fbe97c5b9d608b13017 |
|
MD5 | 8cfe7d68b45a3ca2e48a8dde263eef4a |
|
BLAKE2b-256 | 9ed8cda7c0bae1f137ee82b753407e808151a5027928f88dc40e955b88b49d3f |
Hashes for PyMatching-0.3.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2afedd388108bb64d4e59b1ecbf7d4e3efa728b8457ab3c9e3c0b32828d046a6 |
|
MD5 | 600efa4df95b9cde555dfcac95688616 |
|
BLAKE2b-256 | a7ce8c6505f15c75154ef1c1fcacbbca5a034ac63b80b238b63ba5bab0b414fc |
Hashes for PyMatching-0.3.1-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e7f8b09f0e8083f99d82350ffe4b64af956436629c479dfd98ab2cce3c1028b |
|
MD5 | f05aa6671452fc8a6e63a46802c85e2b |
|
BLAKE2b-256 | ee62d14cfdf11c4552ec1acfb1c37198931699f1601bdbc45d7a9533a6cb5101 |
Hashes for PyMatching-0.3.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd520b4d78512fd365ca053947608dbaf414129a71bba5c85844c840826a26aa |
|
MD5 | 526986110a2241cf20563ea529f50bbe |
|
BLAKE2b-256 | 004d73da763c2bf6e40eec364eae9d575605fd4f807d81a8c7f1c69f3166153e |
Hashes for PyMatching-0.3.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fef114577ec4ebd4bed64bef374ea7967365436bd4b1c2d304a3e98f88da319e |
|
MD5 | 417bb44d34aa08b2de80ce854a04463d |
|
BLAKE2b-256 | 3eae90b707bb5ed9903b0911010f6bef2ce15068527c4f32fadb917d897e62f2 |
Hashes for PyMatching-0.3.1-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01671d2782fc52af841ab4b23e18ef2086482d65696f6ad910a34a2e82ac2b5c |
|
MD5 | fbd9e67b83b045a49911f69631ec0119 |
|
BLAKE2b-256 | 01ad63ff2e6e2b4042533a0e2240107cb4f88e31920f63cca766308682b985eb |
Hashes for PyMatching-0.3.1-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e06e4d6ffac908a283ff964dc9886d72e5ac2369daef44b9661e5a8ce1192d7 |
|
MD5 | e7d11c21bbc27872f3113779cc9880e3 |
|
BLAKE2b-256 | d0fce18a3f2a917cb01c0719573348772d5d5047f0babf5a224f81fef80b6e0c |
Hashes for PyMatching-0.3.1-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9ace743f51c612f63c8938931b2ef1352fdde115884ef53f9fd8e873c5372b4 |
|
MD5 | 3ec5ad67b3635aa53adf8b3507a76e1c |
|
BLAKE2b-256 | 6f7af167c982f6649314f87b33eeb06c96dffa58795369464a0babc13f8bacb7 |