Skip to main content

A search-based decoder for quantum error correction (QEC).

Project description

Tesseract Decoder

A Search-Based Decoder for Quantum Error Correction.

Licensed under the Apache 2.0 open-source license C++

InstallationUsagePython InterfacePaperHelpCitationContact

Tesseract is a Most Likely Error decoder designed for Low Density Parity Check (LDPC) quantum error-correcting codes. It applies pruning heuristics and manifold orientation techniques during a search over the error subsets to identify the most likely error configuration consistent with the observed syndrome. Tesseract achieves significant speed improvements over traditional integer programming-based decoders while maintaining comparable accuracy at moderate physical error rates.

We tested the Tesseract decoder for:

  • Surface codes
  • Color codes
  • Bivariate-bicycle codes
  • Transversal CNOT protocols for surface codes

Features

  • A* search: deploys A* search while running a Dijkstra algorithm with early stop for high performance.
  • Stim and DEM Support: processes Stim circuit files and Detector Error Model (DEM) files with arbitrary error models. Zero-probability error instructions are automatically removed when a DEM is loaded.
  • Parallel Decoding: uses multithreading to accelerate the decoding process, making it suitable for large-scale simulations.
  • Efficient Beam Search: implements a beam search algorithm to minimize decoding cost and enhance efficiency. Sampling and Shot Range Processing: supports sampling shots from circuits. When a detection error model is provided without an accompanying circuit, Tesseract requires detection events from files using --in. The decoder can also process specific shot ranges for flexible experiment setups.
  • Detailed Statistics: provides comprehensive statistics output, including shot counts, error counts, and processing times.
  • Heuristics: includes flexible heuristic options: --beam, --det-penalty, --beam-climbing, --no-revisit-dets, --at-most-two-errors-per-detector, and --pqlimit to improve performance while maintaining a low logical error rate. To learn more about these options, use ./bazel-bin/src/tesseract --help
  • Visualization tool: open the viz directory in your browser to view decoding results. See viz/README.md for instructions on generating the visualization JSON.

Installation

Tesseract relies on the following external libraries:

  • argparse: For command-line argument parsing.
  • nlohmann/json: For JSON handling (used for statistics output).
  • Stim: For quantum circuit simulation and error model handling.

Build Instructions

Tesseract uses Bazel as its build system. To build the decoder:

bazel build src:all

Running Tests

Unit tests are executed with Bazel. Run the quick test suite using:

bazel test //src:all

By default the tests use reduced parameters and finish in under 30 seconds. To run a more exhaustive suite with additional shots and larger distances, set:

TESSERACT_LONG_TESTS=1 bazel test //src:all

Usage

The file tesseract_main.cc provides the main entry point for Tesseract Decoder. It can decode error events from Stim circuits, DEM files, and pre-existing detection event files.

Basic Usage:

./tesseract --circuit CIRCUIT_FILE.stim --sample-num-shots N --print-stats

To decode pre-generated detection events, provide the input file using --in SHOTS_FILE --in-format FORMAT.

Example with Advanced Options:

./tesseract \
        --pqlimit 1000000 \
        --at-most-two-errors-per-detector \
        --det-order-seed 232852747 \
        --circuit circuit_file.stim \
        --sample-seed 232856747 \
        --sample-num-shots 10000 \
        --threads 32 \
        --print-stats \
        --beam 23 \
        --num-det-orders 1 \
        --shot-range-begin 582 \
        --shot-range-end 583

Example Usage

Sampling Shots from a Circuit:

./tesseract --circuit surface_code.stim --sample-num-shots 1000 --out predictions.01 --out-format 01

Using a Detection Event File:

./tesseract --in events.01 --in-format 01 --dem surface_code.dem --out decoded.txt

Using a Detection Event File and Observable Flips:

./tesseract --in events.01 --in-format 01 --obs_in obs.01 --obs-in-format 01 --dem surface_code.dem --out decoded.txt

Tesseract supports reading and writing from all of Stim's standard output formats.

Performance Optimization

Here are some tips for improving performance:

  • Parallelism over shots: increase --threads to leverage multicore processors for faster decoding.
  • Beam Search: use --beam to control the trade-off between accuracy and speed. Smaller beam sizes result in faster decoding but potentially lower accuracy.
  • Beam Climbing: enable --beam-climbing for enhanced cost-based decoding.
  • At most two errors per detector: enable --at-most-two-errors-per-detector to improve performance.
  • Priority Queue limit: use --pqlimit to limit the size of the priority queue.

Output Formats

  • Observable flips output: predictions of logical errors.
  • DEM usage frequency output: if --dem-out is specified, outputs estimated error frequencies.
  • Statistics output: includes number of shots, errors, low confidence shots, and processing time.

Python Interface

Full Python wrapper documentation

This repository contains the C++ implementation of the Tesseract quantum error correction decoder, along with a Python wrapper. The Python wrapper/interface exposes the decoding algorithms and helper utilities, allowing Python users to leverage this high-performance decoding algorithm.

The following example demonstrates how to create and use the Tesseract decoder using the Python interface.

from tesseract_decoder import tesseract
import stim
import numpy as np


# 1. Define a detector error model (DEM)
dem = stim.DetectorErrorModel("""
    error(0.1) D0 D1 L0
    error(0.2) D1 D2 L1
    detector(0, 0, 0) D0
    detector(1, 0, 0) D1
    detector(2, 0, 0) D2
""")

# 2. Create the decoder configuration
config = tesseract.TesseractConfig(dem=dem, det_beam=50)

# 3. Create a decoder instance
decoder = config.compile_decoder()

# 4. Simulate detector outcomes
syndrome = np.array([0, 1, 1], dtype=bool)

# 5a. Decode to observables
flipped_observables = decoder.decode(syndrome)
print(f"Flipped observables: {flipped_observables}")

# 5b. Alternatively, decode to errors
decoder.decode_to_errors(syndrome)
predicted_errors = decoder.predicted_errors_buffer
# Indices of predicted errors
print(f"Predicted errors indices: {predicted_errors}")
# Print properties of predicted errors
for i in predicted_errors:
    print(f"    {i}: {decoder.errors[i]}")

Good Starting Points for Tesseract Configurations:

The Tesseract paper recommends two setup for starting your exploration with tesseract:

(1) Long-beam setup:

tesseract_config = tesseract.TesseractConfig(
    dem=dem,
    pqlimit=1_000_000,
    det_beam=20,
    beam_climbing=True,
    num_det_orders=21,
    det_order=tesseract_decoder.utils.DetOrder.DetIndex,
    no_revisit_dets=True,
)

(2) Short-beam setup:

tesseract_config = tesseract.TesseractConfig(
    dem=dem,
    pqlimit=200_000,
    det_beam=15,
    beam_climbing=True,
    num_det_orders=16,
    det_order=tesseract_decoder.utils.DetOrder.DetIndex,
    no_revisit_dets=True,
)

For det_order, you can use two other options of DetIndex and DetCoordinate as well. These values balance decoding speed and accuracy across the benchmarks reported in the paper and can be adjusted for specific use cases.

Help

We are committed to providing a friendly, safe, and welcoming environment for all. Please read and respect our Code of Conduct.

Citation

When publishing articles or otherwise writing about Tesseract Decoder, please cite the following:

@misc{beni2025tesseractdecoder,
    title={Tesseract: A Search-Based Decoder for Quantum Error Correction},
    author = {Aghababaie Beni, Laleh and Higgott, Oscar and Shutty, Noah},
    year={2025},
    eprint={2503.10988},
    archivePrefix={arXiv},
    primaryClass={quant-ph},
    doi = {10.48550/arXiv.2503.10988},
    url={https://arxiv.org/abs/2503.10988},
}

Contact

For any questions or concerns not addressed here, please email tesseract-decoder-dev@google.com.

Disclaimer

Tesseract Decoder is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.

Copyright 2025 Google LLC.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

tesseract_decoder-0.1.1.dev20250909234415-py313-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded Python 3.13manylinux: glibc 2.39+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py313-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded Python 3.13manylinux: glibc 2.35+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py313-none-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded Python 3.13macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250909234415-py313-none-macosx_10_13_x86_64.whl (3.1 MB view details)

Uploaded Python 3.13macOS 10.13+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py312-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded Python 3.12manylinux: glibc 2.39+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py312-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded Python 3.12manylinux: glibc 2.35+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py312-none-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded Python 3.12macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250909234415-py312-none-macosx_10_13_x86_64.whl (3.1 MB view details)

Uploaded Python 3.12macOS 10.13+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py311-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded Python 3.11manylinux: glibc 2.39+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py311-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded Python 3.11manylinux: glibc 2.35+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py311-none-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded Python 3.11macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250909234415-py311-none-macosx_10_13_x86_64.whl (3.1 MB view details)

Uploaded Python 3.11macOS 10.13+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py310-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded Python 3.10manylinux: glibc 2.39+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py310-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl (3.6 MB view details)

Uploaded Python 3.10manylinux: glibc 2.35+ x86-64

tesseract_decoder-0.1.1.dev20250909234415-py310-none-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded Python 3.10macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250909234415-py310-none-macosx_10_13_x86_64.whl (3.1 MB view details)

Uploaded Python 3.10macOS 10.13+ x86-64

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py313-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py313-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cab9b3bb9f3294a612c703123d0a8946e0ef8fa020f5ec89b0ca312582fd8dc4
MD5 1eea649e9ab2dc113afb085b4fcdcfce
BLAKE2b-256 8fc22e25651fe5ffed12b337b72cf0eb26fa820a26703501f416988b0dc4471e

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py313-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py313-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60f32dd54df6e83da62480773a2ed7bac69adc3b6b6007b9fb71a840bfa48d32
MD5 ef7b06d3e47f62be7cf0d8af3eb972d0
BLAKE2b-256 68b165bb2b039ee41205ad867f720d773a78314c0a6daf4dceee2ef770c69a22

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py313-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py313-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34668328dd0b5bc5e38707c7128e0f418c85d9f75f3e74b0fe3ec2866ccef425
MD5 6701449bbe3877bc2fa392487efbcc08
BLAKE2b-256 3221cb8a87ee26457d1bb9a9bd3eafed92f95e116d2164b0811b58a9ee5a0759

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py313-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py313-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 80d7235b94e629beb7ed5076385c8bbd66e6c9cbbd99392cfde420c7c5ed854a
MD5 bea2777927191f4e3eb07ff2b29e3454
BLAKE2b-256 e0bae50587e485220f314e49aeeaae736e4b40002cdc653204b535590fa3a4b7

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py312-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py312-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af2b88a2e55f014d3247d6cefbf249fda62764b267aa4b6fd7ec61c103ea2f98
MD5 196c452eb75e7d167ec8961eab4c9452
BLAKE2b-256 17652096f7116b00e55a94c7714424dc099404ef4497b0d6f27a73494de79db0

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py312-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py312-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0bf69c34b4e86049a13e0f4e0c6b65b9f1fac0d88ee2d05f3c0afcce199a6b58
MD5 2ba797ac12f7ab6a4c2d509ee6c5aaab
BLAKE2b-256 7067986d02b788797fa68ef3da58b419345b3459c641f7387a1a955af80165d3

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py312-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py312-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 987aaf6b4c218ad2be3749f4131e8bcb69b99933bfb3c748446b3a1a3b335feb
MD5 2ff12310662f78e6e8237a5cd3f19d16
BLAKE2b-256 ede1b4fb688e5c18b80342db1f3042e29add60aba0fd08a9cfbd9064b865a47c

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py312-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py312-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 eaf1655c561c03aec47d31e1e5814c481a986d24dbb05993e563c8d962c3e135
MD5 7db2ac128edb411f59bcbdef20e1284f
BLAKE2b-256 456a7563f189b6d46917ab65ae0ba6efa576a294e1d6b8e526607986c5f86a00

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py311-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py311-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37a39d781576107f650dcc30ff6ea760804865717ed1688c27deb35cec84ffa8
MD5 b89ecfe0bc8fafc80865c5f70a8835d7
BLAKE2b-256 ec17f888391970a6c1a0ed2b54964c4ded681509b0ac68ec0db8a6900e8a2b6c

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py311-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py311-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b94e9b503d65720a90a3afcc06f2a51ac24112546c6a97334a668ec05e715218
MD5 4ff5a5ac243f4ddef0cc1c6f5101d1a3
BLAKE2b-256 1b5609ed331c58b63a4c113ae8266596e0d9692647399b4ef5776fd4cf268b9a

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py311-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py311-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b3993eda4c6a7233ae2e7bd769cba57395ff8871469b700e0e3c083a31966fe
MD5 f7056ba0ef644eb51981e4d5bb1dd78a
BLAKE2b-256 086e903c007c3e63394015fc1ecfb7e54d9eff10ee79a488c873b6ae4a348a71

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py311-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py311-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 b108bb52f433acd64ecb3bddcc576d580af0572bb1fa0f630ce5c3bd602f347f
MD5 0731b6c41f4a3eeba97652361f76af14
BLAKE2b-256 2fa6883963bfe9f14b68a7b841682fde23be6312f088e21d4b381090873d547b

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py310-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py310-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba66ca398d931a3b516828d19382abe3be7f69e4fdf53a2f4363d3b855116fde
MD5 522a7c1d49660b7b7bb8bf0fefc0ccfc
BLAKE2b-256 e1d118a0d720bd9316ecf2076a1ecf7ddfed5b277d0e6243ba69be93468dced5

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py310-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py310-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2b5a5597ba11a181af064005a07b680a835e1fda5cc8167f32c48e80f4d57ef8
MD5 4621bdfc92edd4c1e61d6094f2a6601e
BLAKE2b-256 b8800a5e15f90cff2b3f1eb2601f41723f0222d30bb74d6ef8292c52ab4a4610

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py310-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py310-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9eaeea83a558f007c70308a4fe9b807b78c8bfada11c049699930baf1e74464
MD5 6ebb12426b97fb9343dbf404bee3e494
BLAKE2b-256 83b6743c30b4c58ac339920c37b1963aad048c39af326b38541007da09e82c98

See more details on using hashes here.

File details

Details for the file tesseract_decoder-0.1.1.dev20250909234415-py310-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250909234415-py310-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 5e9065256f5224b3135473a9af064c22ba368a62ae9ea3368047058917c0d3f0
MD5 1f9b29a2e5040f1ddf4b1d9fe2895a87
BLAKE2b-256 330ce403e2b402e126e7cebcd432f4f2d828047d21fc61d57e2d418277fdee35

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