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 stim

from surface_sim.setup 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

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

# generate encoded circuit
layouts = unrot_surface_codes(2, distance=3)
qubit_inds = {}
anc_coords = {}
anc_qubits = []
for l, layout in enumerate(layouts):
    qubit_inds.update(layout.qubit_inds())
    anc_qubits += layout.get_qubits(role="anc")
    coords = layout.anc_coords()
    anc_coords.update(coords)

setup = CircuitNoiseSetup()
setup.set_var_param("prob", 1e-3)
model = CircuitNoiseModel(setup=setup, qubit_inds=qubit_inds)
detectors = Detectors(anc_qubits, frame="pre-gate", anc_coords=anc_coords)

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

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

decoder = MoMatching(dem, circuit, [["X0"], ["X1"]], stab_coords, "pre-gate")

# run MoMatching
sampler = dem.compile_sampler()
syndrome, log_flips, _ = sampler.sample(shots=10)

predictions = decoder.decode_batch(syndrome)
log_errors = (predictions != log_flips)

How do I cite lomatching?

When using lomatching for research, please cite:

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.1.0.tar.gz (14.2 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.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lomatching-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for lomatching-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d74f8cec3b06c0548e05535a4817899d53d7362bd29e0e1ca7d21b3199b9c5e
MD5 f0d7a7f749475b169ec5952b100a924e
BLAKE2b-256 4c17feedf1864d53dacd1f316c1d0b6a316a8d6a121b2795fa1e8cb4599e17c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lomatching-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for lomatching-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3cd080826704ec1e3c92a3b762f2bc75a6739f0bb8ff7f6ee05ad71adfc0fad
MD5 ff88297985ae1b884c176c9da23f9132
BLAKE2b-256 b093703dfb5a47d908ce35eb0c9951792628400545703792e6de2c9ad93005b3

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