Skip to main content

A C++ implementation of the Minimum Weight Perfect Matching decoder, with Python bindings.

Project description

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. 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 it does not require you to build the C++ extension. 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}}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyMatching-0.2.3.tar.gz (10.6 MB view details)

Uploaded Source

Built Distributions

PyMatching-0.2.3-cp39-cp39-win_amd64.whl (142.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

PyMatching-0.2.3-cp39-cp39-manylinux2010_x86_64.whl (169.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

PyMatching-0.2.3-cp39-cp39-manylinux2010_i686.whl (177.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

PyMatching-0.2.3-cp39-cp39-macosx_10_9_x86_64.whl (145.6 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

PyMatching-0.2.3-cp38-cp38-win_amd64.whl (142.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

PyMatching-0.2.3-cp38-cp38-manylinux2010_x86_64.whl (169.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

PyMatching-0.2.3-cp38-cp38-manylinux2010_i686.whl (177.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

PyMatching-0.2.3-cp38-cp38-macosx_10_9_x86_64.whl (145.6 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

PyMatching-0.2.3-cp37-cp37m-win_amd64.whl (143.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

PyMatching-0.2.3-cp37-cp37m-manylinux2010_x86_64.whl (171.2 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

PyMatching-0.2.3-cp37-cp37m-manylinux2010_i686.whl (180.2 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

PyMatching-0.2.3-cp37-cp37m-macosx_10_9_x86_64.whl (144.6 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

PyMatching-0.2.3-cp36-cp36m-win_amd64.whl (143.0 kB view details)

Uploaded CPython 3.6m Windows x86-64

PyMatching-0.2.3-cp36-cp36m-manylinux2010_x86_64.whl (171.1 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

PyMatching-0.2.3-cp36-cp36m-manylinux2010_i686.whl (180.1 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

PyMatching-0.2.3-cp36-cp36m-macosx_10_9_x86_64.whl (144.5 kB view details)

Uploaded CPython 3.6m macOS 10.9+ x86-64

File details

Details for the file PyMatching-0.2.3.tar.gz.

File metadata

  • Download URL: PyMatching-0.2.3.tar.gz
  • Upload date:
  • Size: 10.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3.tar.gz
Algorithm Hash digest
SHA256 f2e0087f6e34cb2b35f32e5c6703125f647e7ce3cffd4d010bf9c68574f5839b
MD5 69edb4bb8955b856fcdfff7d3002c045
BLAKE2b-256 badc718658c329d7c00a73b4fa043a1155bf074da785a706720b5602d60dc985

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 142.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 aa41150b122e2e6a30cc36d0dfa6c8f648352f9ea860997a46af773368c870f3
MD5 9e31ac1bd1bac720bc9d5659da20e02e
BLAKE2b-256 be9dc65164a4e53d26c4286e1e3a599b611a5416db1d8389bdba97794b9386cb

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 169.8 kB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 29110b8338a5edec731baa7248b8fce290cdb529fb649b07e8d9ff71edb44aa8
MD5 3c8352c4b74c30c6408fee2662e85325
BLAKE2b-256 d015445b75693a367a2d9ae0d0dc02dc8d92002120155ca5e04b618882bfca86

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp39-cp39-manylinux2010_i686.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp39-cp39-manylinux2010_i686.whl
  • Upload date:
  • Size: 177.4 kB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ i686
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp39-cp39-manylinux2010_i686.whl
Algorithm Hash digest
SHA256 11085f2db869cb9ed5960de90094dd3d95b15567190c7c1acf5cadbc89cc2dcd
MD5 88d650f3eb7231684ad35692f28cfd3f
BLAKE2b-256 e4df7c255d8bc0bf3d118bef0e20a8b274ea6ba24437db5db3a090bd9934a87f

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 145.6 kB
  • Tags: CPython 3.9, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8c6e53748643fb2c579fe23d3ab614cc5074b1ea010a0b47ea337d5db4416715
MD5 583c5e09cda9572bf71270671dea464a
BLAKE2b-256 acf6f1d6917dfb1312cb7c066dd34cc80cf7833caf8dc1712deb461b72499d24

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 142.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ffe13441e80b76e04c9f1f4c86c05fd4fdbbea6cb8070bf86cc800d22515c6e1
MD5 86a346f2e46f0be8c97410e988f839e7
BLAKE2b-256 d36b147f56fa5d7744eb0eec0f6fddd0f6d2e437484453fb216d35f9e4785b13

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 169.9 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5a8aee5760c4afb0856b18b521a9918763c83a47f26482ff350453e9f52bef06
MD5 31d75f0924c43c1d6078fad53d4fa32d
BLAKE2b-256 c899cc1ab251cf772e5f162e9ca73855e8031c75d480b509cf0de41a5e61505d

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp38-cp38-manylinux2010_i686.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp38-cp38-manylinux2010_i686.whl
  • Upload date:
  • Size: 177.2 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ i686
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp38-cp38-manylinux2010_i686.whl
Algorithm Hash digest
SHA256 11d89ed5370bccc85b42ff43e66fbe945252fe727e8027a41cb9ab2a41a54fc2
MD5 8d14b779ddd085a238411fd69e3a0660
BLAKE2b-256 a1ce9369d21ccea9caf4282ce20673e3e8850700b51132f708cae17096cb6c95

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 145.6 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0742bd452f5394e5efcbe9d5b4be0eca505b19cbefdc9a966cb9e5489e76f9dc
MD5 6e34123e06f563b5435b2e5d12e341c7
BLAKE2b-256 b813d7d382e010f4cc945ecc11ea8b809491be35ac69cc0cb8704bef83a30dc5

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 143.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 eeb66bc9907339191cd7f507453f8e41e96bdbc4602641d5640e0879b15112d1
MD5 cac545d84e4181b731f19f79ab7fc0da
BLAKE2b-256 a74efd2c176534fd94df458327a6d1f2bca988d5f888bcf949365daa4bf95269

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 171.2 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 f3a8a92896a355c16c9bd4e1ea97d5a828506a4fa581fc7498b5a16059ab2942
MD5 3458485018a5f504ee5d1fcbf690808b
BLAKE2b-256 9d17a2d2fc8420ee832ae6ab5e958e8993c43ad255311c631d1c81d8a1529b33

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp37-cp37m-manylinux2010_i686.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp37-cp37m-manylinux2010_i686.whl
  • Upload date:
  • Size: 180.2 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ i686
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp37-cp37m-manylinux2010_i686.whl
Algorithm Hash digest
SHA256 4e664ccc708698866a1582cdaba68b2f7f1fd44afdb4a2e86cddbfbc4ab15922
MD5 80b4a92e57b68e8a2c3e865645450f61
BLAKE2b-256 adf88fd897aa69fc2a69e875134df59212d7647b78017eda0f0317e086dcc9e2

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 144.6 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b24ca39788b126a2fb6a469228f4d28b2a4faf4c2198e145dd452b1de0f4be82
MD5 7671c5c2ab3cdb9426b83bded3127437
BLAKE2b-256 b1d151fe0497bccd1daa9072e07593b5106e3e3b2d9b3b2e2979ac8fac010fc0

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 143.0 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 763cbd0a211b552ddba90b013d4f281977b2e53537836779ded66404b4bdc102
MD5 41b4b3651e01e07ae5c4fcc7052e7eb7
BLAKE2b-256 81cc9fb9623062a15accbb4a023495dd787d0cba725f2ba55b28fb0591c60b95

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 171.1 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0c5ab0b45fb1ebbf14d32510ac87facb2b3bf3a6d8866219d42e3ab0dc6af3e2
MD5 fc3139c7864908f7a6bcdd7c586b8055
BLAKE2b-256 0f13ccfb3fab317e66d2abbc29d5495111a756a0c6124ca96d729419f14a54e7

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp36-cp36m-manylinux2010_i686.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp36-cp36m-manylinux2010_i686.whl
  • Upload date:
  • Size: 180.1 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ i686
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp36-cp36m-manylinux2010_i686.whl
Algorithm Hash digest
SHA256 8dbf8d4d93882c7905f06f17835f2cd5c6d44503fa06fcf3e5e19956cd88308c
MD5 ce27977808a812423a90be0b5de625d5
BLAKE2b-256 af2282ecc4c7d41ee5eac919ce008262fe45e51fe85d017054b8798a12a6df62

See more details on using hashes here.

File details

Details for the file PyMatching-0.2.3-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: PyMatching-0.2.3-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 144.5 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for PyMatching-0.2.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 80bd6fabd993f578f26b914c90def4e1cb736034034cf7ab9724c3ec305771c4
MD5 8b7788da2cbb6fb98222283d77f6cb33
BLAKE2b-256 56aa6ebffb00c0a2c64c6a462714451a21424487dc0642d18258a6c002b4ba8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page