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.setups import CircuitNoiseSetup
from surface_sim.models import CircuitNoiseModel
from surface_sim import Detectors
from surface_sim.experiments import schedule_from_circuit, experiment_from_schedule
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, get_reliable_observables, remove_obs_except

# circuit considered
circuit = stim.Circuit(
    """
    RX 0
    RZ 1
    TICK
    CNOT 0 1
    MX 0 1
    """
)

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

schedule = schedule_from_circuit(circuit, layouts, gate_to_iterator)
encoded_circuit = experiment_from_schedule(
    schedule, model, detectors, anc_reset=True, anc_detectors=None
)

# 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"]

reliable_obs = get_reliable_observables(encoded_circuit)
encoded_circuit = remove_obs_except(encoded_circuit, reliable_obs)

decoder = MoMatching(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:

@misc{serraperalta2025decoding,
      title={Decoding across transversal Clifford gates in the surface code}, 
      author={Marc Serra-Peralta and Mackenzie H. Shaw and Barbara M. Terhal},
      year={2025},
      eprint={2505.13599},
      archivePrefix={arXiv},
      primaryClass={quant-ph},
      url={https://arxiv.org/abs/2505.13599}, 
}

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.2.1.tar.gz (12.9 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.2.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lomatching-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5aa3e50eedf3f3f613f2a081a8a79d08e0c85399d79aa38ec447e094af4629a1
MD5 84086aa2070d8c1a996c558fe0161f02
BLAKE2b-256 2671411fbf4548fc46a9586c96f70e3f2faa83f39a8150f78eb1808a8bf31c55

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for lomatching-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4c4cde0e19a4fbc41235be436d29b17ee33a48b9e8b8fca2242cdfcea853cd83
MD5 a41e422def8546f19f8200ea285105ab
BLAKE2b-256 a5e097676dfb71e229d8a6d21e7ca1318ddff4483c89c9e584481716583d293a

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