PyMatching

2.3.1 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import pymatching
import numpy as np
import scipy.sparse

# Example: Parity check matrix (H) for a simple [3,1,2] repetition code
# This H matrix represents two stabilizers: qubit0^qubit1 and qubit1^qubit2
H = scipy.sparse.csc_matrix(np.array([
    [1, 1, 0],
    [0, 1, 1]
]))

# Initialize the Matching object from the parity check matrix
matching = pymatching.Matching(H)

# Simulate a syndrome measurement (e.g., after an error on qubit 1)
# An error on qubit 1 flips both stabilizers (syndrome = [1, 1])
syndrome = np.array([1, 1])

# Decode the syndrome to find the most likely error pattern
# The result 'correction' is a binary vector indicating the predicted error locations
correction = matching.decode(syndrome)

print(f"Input syndrome: {syndrome}")
print(f"Predicted error pattern: {correction}")
# Expected output for syndrome [1,1]: [0, 1, 0] (error on qubit 1)

view raw JSON →