Skip to main content

Logical observable decoder for transversal logical gates in surface codes based on pymatching.

Project description

lomatching

example workflow Code style: black PyPI

Decoder for (fold-)transversal logical gates in surface codes based on MWPM.

Installation

This package is available in PyPI, thus it can be installed using

pip install lomatching

or alternatively, it can be installed from source using

git clone git@github.com:MarcSerraPeralta/lomatching.git
pip install lomatching/

Example

import numpy as np
import stim

from surface_sim.models import CircuitNoiseModel
from surface_sim import Detectors
from surface_sim.experiments import experiment_from_circuit
from surface_sim.circuit_blocks.unrot_surface_code_css import gate_to_iterator
from surface_sim.layouts import unrot_surface_codes

from lomatching import MoMatching

# circuit considered
circuit = stim.Circuit(
    """
    RX 0
    RZ 1
    TICK
    CNOT 0 1
    MX 0 1
    OBSERVABLE_INCLUDE(0) rec[-1] rec[-2]
    """
)

# generate encoded circuit
layouts = unrot_surface_codes(2, distance=3)
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
model = CircuitNoiseModel.from_layouts(*layouts)
model.setup.set_var_param("prob", 1e-3)

encoded_circuit = experiment_from_circuit(
    circuit, layouts, model, detectors, gate_to_iterator, anc_reset=True
)

# prepare inputs for MoMatching
stab_coords = [{} for _ in layouts]
for l, layout in enumerate(layouts):
    coords = layout.anc_coords
    stab_coords[l][f"Z"] = [v for k, v in coords.items() if k[0] == "Z"]
    stab_coords[l][f"X"] = [v for k, v in coords.items() if k[0] == "X"]

decoder = MoMatching.from_circuit(encoded_circuit, stab_coords)

# run MoMatching
sampler = encoded_circuit.detector_error_model().compile_sampler()
syndromes, log_flips, _ = sampler.sample(shots=10)

predictions = decoder.decode_batch(syndromes)
log_errors = (predictions != log_flips).any(axis=1)

print("Logical error probability:", np.average(log_errors))

How do I cite lomatching?

When using lomatching for research, please cite:

@article{lomatching,
  title = {Decoding across Transversal Clifford Gates in the Surface Code},
  author = {Serra-Peralta, Marc and Shaw, Mackenzie H. and Terhal, Barbara M.},
  journal = {PRX Quantum},
  volume = {7},
  issue = {1},
  pages = {010335},
  numpages = {41},
  year = {2026},
  month = {Feb},
  publisher = {American Physical Society},
  doi = {10.1103/sk5y-25b1},
  url = {https://link.aps.org/doi/10.1103/sk5y-25b1}
}

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

lomatching-0.3.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lomatching-0.3.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file lomatching-0.3.0.tar.gz.

File metadata

  • Download URL: lomatching-0.3.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for lomatching-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0fa8d1c8dfa4c3b91f252b0bc1b36530682bd49f7803811acb8a4749bbaa4e69
MD5 1e4990ce2ed42c5ac5b3cc06bbeb49d5
BLAKE2b-256 9e48a26a68c1d10ad4f05c64d9e8e9223b3ddea1dbec09f4b85840a59261c915

See more details on using hashes here.

File details

Details for the file lomatching-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lomatching-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for lomatching-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78c042dce88796ff41af4c03deb7a22739494930e6b97719d84cb18c8db4e63d
MD5 d328a9266fdd5c0e631ccff673700c6e
BLAKE2b-256 651a1b21639a07d5ae0a191f57f0f99e54bb39787f24df673153fbee04dd6cd4

See more details on using hashes here.

Supported by

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