This repository contains the code used in the paper "Efficient Magic State Cultivation with Lattice Surgery" (arXiv:2510.24615).
The code used to generate the figures in the paper is available in the branch experiment-2025-sep.
The implementation is written in Python and depends on:
- Stim (including Sinter)
- PyMatching
- SQLite3
- NumPy
- Matplotlib
The src/ directory contains the main scripts:
-
src/lattice_surgery_complementary_gap.py
The main script that implements the end-to-end distillation sequence. -
src/lattice_surgery_error_detection.py
Supports the error-detection use case.
Used to generate the data for Fig. 9, "Logical X and Z error probabilities introduced by the lattice surgery procedure," in the paper. -
src/extract_lookup_table.py
Extracts information from the lookup table generated bylattice_surgery_complementary_gap.py.
Used to generate the data for Fig. 11, "Coverage of the lookup table," in the paper.
src/lattice_surgery_error_detection.pyrequires Sinter ≤ 1.13 due to a known bug.- Other scripts require Stim 1.15 or later.
We add type annotations wherever possible and use mypy for type checking.
[yhirano@host msc-ls]$ mypy --ignore-missing-imports src/*.py
Success: no issues found in 17 source filesTests are written in src/*_test.py and can be run with the -m unittest command-line option:
[yhirano@host msc-ls]$ cd src
[yhirano@host src]$ python3 -m unittest *_test.py
.............................................................
----------------------------------------------------------------------
Ran 61 tests in 3.384s
OKWe use pycodestyle for code formatting.
It should ideally be applied automatically (for example, via a Git commit hook), but this has not yet been set up.
[yhirano@host msc-ls]$ pycodestyle src/*.py