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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lomatching-0.2.0.tar.gz
  • Upload date:
  • Size: 12.8 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.0.tar.gz
Algorithm Hash digest
SHA256 42b346eef01a5580a0fdfcd036d93fb37e882cce74e598000fac8c6c24bc8a63
MD5 b05f7682d9e3e28d12aa9ae3d4e67d44
BLAKE2b-256 1e5f89480cdba8d010dbeda188ece5972202ccb70cb70a2c4f63527b6d829f25

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lomatching-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af6130b5a5dc02ceb03baddb6090c2af760d571aab3bf4ea480393ef0cd1dd06
MD5 f916b8ff085f5bc0f1c182483d505109
BLAKE2b-256 545158de2c96177b5560009dc1263addebb8f6a964dd014828d869004c318fa4

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