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]}")

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.dev20250831012512-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.dev20250831012512-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.dev20250831012512-py312-none-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded Python 3.12macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250831012512-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.dev20250831012512-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.dev20250831012512-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.dev20250831012512-py311-none-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded Python 3.11macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250831012512-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.dev20250831012512-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.dev20250831012512-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.dev20250831012512-py310-none-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded Python 3.10macOS 11.0+ ARM64

tesseract_decoder-0.1.1.dev20250831012512-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.dev20250831012512-py312-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py312-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa00497fdf00e20fcc020ea4010dbbf8252a966796264cec365a93bc993e4155
MD5 ba3feda53d80db3e514c5d44c4d6dd18
BLAKE2b-256 cf7ed4e5a952a3d85227949ad7298aeef5fb9d66d3d4926c9563f95e16657466

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py312-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ce201b4ab5b428936995857d873a45d660cbb3ccdf3fe56ae684df7043a07ad
MD5 4bd85b3ebfac40354d7610bbe7a62b43
BLAKE2b-256 3e2461bd2560ed9fbb84bf80bf1b44e81b9a7b41f486649eca1d05e4c9c48bce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py312-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5d7e58971ed4743098803fa9fd83565b3b3c85243ef6698e5982c15fca889d0
MD5 93b6e605466f3b2a3a3b0bb2e3617daf
BLAKE2b-256 c1112d9423e1241488e28ec41aa2b76656a6b939077f066c2811117aa75bb7a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py312-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 de8c93c738e6f16c420b288fc4b09fbe6b57bece026826e2de32b2263854850b
MD5 67a68c5b2954762a1a00aa809aee5796
BLAKE2b-256 b8fb52a072b22d12f1807e9d79226f379160f5abf16b8f17d8602c96d691d2dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py311-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4434d06886a5228997bcc0f9ef6ab2495f76307ec045423020b088143cef5e9b
MD5 1a3d426046fb7da7696997c080a095d1
BLAKE2b-256 f1e234cde4fea33deabc0d81bc80e4667e7293a69cdf5366d793a522e864fbc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py311-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 31cc96907a303189e03645c5e3dc25831daa4ad532537c5adb60c754b546bdc6
MD5 82e0a483f4d9bbc5b24b660a2fb1eb4f
BLAKE2b-256 bc3cdaafe215edad6f33610db5283296c2a59f1527772b4bce03e98be9c27d26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py311-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a18573363a57be4a73b092d598b7199a6e9beeba62318e0362c7218f9c57adc4
MD5 fd9e51bc57c587d1b3f1f5dec20900a8
BLAKE2b-256 aae0efe48700318426e70205a46e2a2afd667aef64700a9ac689c801568cd38c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py311-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 e1bf4d8118db9b43ecb1bb96b5f2959f4d6b2618867dbe671c2697a0bacfb160
MD5 db8be81e7e7321ce3bb29f2e61d8c7b0
BLAKE2b-256 c4de9fc6ec0fdc2d2f7fe3d9ad41856e44c1056eb367b46aab15e947aa135f89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py310-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de266ee4c44ee698762b5ad8ddcc7d4c4cbc501574f74a22ae79fd0ce0ca0888
MD5 57ecefd331f6be6661bbdf2b8a22c43b
BLAKE2b-256 58936ec8272dab6a999b5a623d3d63ad8d5f6c1ef518083489f95b7f5c60b0c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py310-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4ca15aa6e3914bee0faf42ce70b965b3c74d8b405d6e918af8dfbae7026d3673
MD5 d48def262524f17a821071b6ab1ea7ab
BLAKE2b-256 8fa750a37c4e27f391947a1f224f541306fdafbcff8b268ead8e06e3a1c4b7b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py310-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6aba9b96167eeadafb7fa33dd2a40251cda7a72e42d0499b35540b2e0879a85c
MD5 278c2fe9c0eacbdec4e98e0e639faef3
BLAKE2b-256 624f972c08518d353e3ea802b12854735f5b2e9cdae8f49d71cd9bb7f030c1fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250831012512-py310-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4c1da136a2b688a398b7ea318dbae775092bebf41c9243c84de7a5762340e2a6
MD5 179d5d42914c72d61e5ed725294623ee
BLAKE2b-256 012d4aa086fe70833c7682e72f24835ad3951771929b161a5361e50e86a4f599

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