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.2.tar.gz (15.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.2.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lomatching-0.2.2.tar.gz
  • Upload date:
  • Size: 15.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.2.2.tar.gz
Algorithm Hash digest
SHA256 68b271db3ea774c57e01993ca7ff7d727b6dcfed8e9806ea38a648f5ce73bb8e
MD5 b84f8553a8954d582b9c3117f293b1ec
BLAKE2b-256 95154d41ff05e0c1a02d051541b174bf17fa600c587f39dac4d53773c6a636fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lomatching-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 12.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.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4ec8ea10765c700fafde83d38d733130a997974d6274ffc28c02bc9b9c637648
MD5 e6cd1a5ec0e3d4d0db66e0684147d3ad
BLAKE2b-256 1353e97742a55a41506ea6dd7cd7181f8f32f31be10d264bab5e2ee8bd0d2c98

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