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

Uploaded Python 3.12macOS 11.0+ ARM64

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

Uploaded Python 3.11macOS 11.0+ ARM64

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

Uploaded Python 3.10macOS 11.0+ ARM64

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py312-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2ebe0817c8ab3ad3af0559994b54498f5964ff9233e097e54947d74a4679c98
MD5 761c8cf41fa8db14e1097a2354af47d0
BLAKE2b-256 283f238349db5a219702b997daf42db595d942813e30ecdd32744c5c1c95e35c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py312-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 031fbbc1c19ddd5e29e230b76787fa4fd34c32519941a4e590145b1b2266bc22
MD5 4f88742b9152454d57989d3c0b4b1e10
BLAKE2b-256 bfda7c0d9e96904d7362835727eebc1a0bf632c0c4b42cb97e68350d51ff82cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py312-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f5c68992d9672db213ac8a3b7d6baaa3d9f5f23f6280daece6b32c8f87091cf
MD5 6fb3cda98f546eb46d3cf977ceccbe4a
BLAKE2b-256 9e030fd25dff0750ff067f01ded11672bfce930bedb71a000ad9fa33b9d75c89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py312-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 bb834531f7c1a62e6af231d42acfffdbf91917465bd71a0075134f071d9d2a71
MD5 d63677cb0b92a18f952d40a69ff7640a
BLAKE2b-256 324339d2c0f70252d4c09271d182df280eb3f0bef7278bbcb638ad76b7655b90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py311-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9b4103a713678fcead94851b3c40f13912776fef11ee99524419579215e6c0f5
MD5 8d3de82faf873e6f55c4f5811ee28699
BLAKE2b-256 5b0138cf51886fc208fb2ef7951e4a263065626c69e7a2004ba412e427b85327

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py311-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59f57f8db100524671e155a2fd52d7959e51ab4fd6e0b9ea6343055e52730404
MD5 d72bb8687f9052d2cb70c68b73ae4068
BLAKE2b-256 3b5106db31fc49068e4e185c1e95994113fa6c5e2ae6c2ac2d6f67e0dcbd2f92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py311-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c4007931abd91f468969427d30573f330364d43205758d3df3dd65647059634
MD5 f26b2396aa188358ed68d00fcafc8604
BLAKE2b-256 92f3ebad1bc90744baa5a357a503d1028af59c6ea96ec4616cf4e6ff9c57310f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py311-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 85f473b418e33d36974e09992238d18e73a377482c351a9db48b3414c23e1422
MD5 49608d123c0ac1f1d09612b3d1bb28a3
BLAKE2b-256 a5a5a35e1e75da4dd1cbe335dc8054bc2fcc819689825b928312c2d569204a31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py310-none-manylinux_2_39_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 698d08d75bef153dcc04e7baa179fe3f0ede099d60e6cd6a33657a54e10145e0
MD5 6f8d540975e3e82ce4c3f1a968899788
BLAKE2b-256 d6616639bad01fde0505d59675a691daeb3f51fd747f53f141068798697e8e53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py310-none-manylinux_2_35_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 797768b88dae4284a8172ee4db3b67c56586d552a0bd94d5d291bcb55434a9a3
MD5 3db8db3025d2f1d6c2a1e9dc6822bf07
BLAKE2b-256 0af8ac7261b524d4ed9b089bf677766ae0f272f95c1090f7af198e7d1a033fc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py310-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e94a8148438c367b65eeacb56536ae42b6b09cea7345a22e9bb3e0ce2839ca0b
MD5 d9fa230f56fcb40759c690b3d85f97b7
BLAKE2b-256 8f7934823f318ded90f1d83b158343ab0f20c84972a0ff65f6296a5ab90b6eeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tesseract_decoder-0.1.1.dev20250830192610-py310-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 122bfc915e2a397c33ff6a223716e17acfd5e36a0c0de0ac702b411f1f9bf99e
MD5 55e4b7a8d34bcee9ddccd16cfbf2bb18
BLAKE2b-256 f7157a9abfb2f5f116542549d0aaf4a5585499627c011d034a4c2966aab40aaa

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