Add Python GARI transformation - #273
Open
arshpreetmaan wants to merge 43 commits into
Open
Conversation
arshpreetmaan
requested review from
LalehB,
noajshu and
oscarhiggott
and removed request for
a team and
oscarhiggott
July 27, 2026 06:04
Contributor
|
Thanks @arshpreetmaan , this is getting a lot simpler. I think this could be simplified even further by replacing the scripts in src/py/ that call gari (gari_convert.py and gari_example.py) with one small example in the docs folder (you can update the jupytext and re-gen the docs using the script) WDYT? |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Collaborator
Author
|
Thanks for the feedback, @noajshu! I’ve incorporated the suggested changes and updated the PR accordingly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces the Python portion of #269 with a focused implementation of graph augmentation and rewiring for inference (GARI).
PR #269 combined the Python transformation, C++ runtime integration, detector remapping, ordering experiments, and benchmarking in one change. This PR separates the Python foundation so it can be reviewed independently. C++ CLI integration is handled in a separate PR.
This PR adds:
from tesseract_decoder import demutil, with GARI available asdemutil.gari;paper,xor, andlp-max-barred-costprior policies;.demandtesseract.gari_layout.v1files;Usage
From Python:
The
gari.pyCLI converts one Stim circuit and derives both output filenames from the original circuit name and selected prior policy. With a python environment with NumPy, SciPy, and Stim installed, run:python src/py/_tesseract_py_util/gari.py \ --circuit d5r5colorcode_p001.stim \ --prior xor \ --out-dir gari_outputThis writes gari_output/d5r5colorcode_p001_gari_xor.dem and gari_output/d5r5colorcode_p001_gari_xor_layout.json. Run python src/py/_tesseract_py_util/gari.py --help to see the conversion arguments.
Input and output GARI matrix
Circuit conversion generates an undecomposed source DEM with
decompose_errors=Falseand flattened loops.dem_to_matricesalso flattens repeat blocks and detector shifts before treating each resulting Stimerrorinstruction as one source matrix column. Instructions containing Stim’s^decomposition separator are rejected.The currently supported X/Z partition follows the color-code-style fourth-coordinate convention used by repository test circuits: values
0–2identify X detectors and3–5identify Z detectors.GARI emits columns in:
and rows in the
physical_then_virtuallayout:The decoder syndrome is
[s_X, s_Z, 0, 0], and generic logical observables remain on the original physical variables.Pure columns without an
e_Yprojection still receive barred counterparts. This deliberate redundancy preserves the uniform block structure and keeps the physical top-left blocks zero.Missing or ambiguous projections, duplicate pure columns, and decomposed Stim instructions are rejected.
The generated
.demis matrix storage for decoding, not a physical detector error model, and must not be sampled.Prior policies
paperimplements the published auxiliary initialization.xorassigns the auxiliary XOR parity marginal.lp-max-barred-costfirst maximizes a common nonnegative cost floor across the physical residual and barred variables, then maximizes the total barred-variable cost while preserving that floor.The latter two policies are experimental Tesseract search-cost policies and make no claim of decoding optimality.
Historical motivation
This plot reuses exploratory color-code data from the predecessor implementation in PR #269. Its GARI config corresponds to the policy now named
xor. It is included as motivation, not as a benchmark of this Python-only change.Reference
A. S. Maan, F. M. Garcia Herrero, A. Paler, and V. Savin, "Decoding correlated errors in quantum LDPC codes", Nature Communications 17, 3965 (2026).