[1]:
%%capture
%pip install qldpc
%pip install matplotlib
%pip install tqec
Decoding TQEC circuits
TQEC compiles lattice surgery operations into physical circuits that implement the corresponding logical operations in logical qubits of the surface code. This notebook demonstrates using a decoder from qLDPC to decode circuits compiled and simulated by TQEC. Specifically, we compute the logical error rates of observables in a logical CNOT circuit under a uniform depolarizing noise model.
This notebook is adapted from the TQEC notebooks.
imports, simulation, and plotting code
[2]:
from collections.abc import Sequence
import matplotlib.pyplot as plt
import numpy as np
import sinter
import tqec
import tqec.gallery
from tqec.simulation.plotting.inset import plot_observable_as_inset
from tqec.simulation.simulation import start_simulation_using_sinter
from qldpc import circuits, decoders
%matplotlib inline
Background: TQEC circuits and observables
tqec provides builtin functions to construct simple example computations in tqec.gallery. You define your own lattice surgery operations using tqec.BlockGraph (not shown here).
[4]:
block_graph = tqec.gallery.cnot(tqec.Basis.Z)
block_graph.view_as_html()
[4]:
We can use tqec.BlockGraph.find_correlation_surfaces to identify a generating set of correlation surfaces that correspond to stim observables, and then visualize these correlation surfaces with tqec.BlockGraph.view_as_html. We show one correlation surface below.
[5]:
correlation_surfaces = block_graph.find_correlation_surfaces()
block_graph.view_as_html(
pop_faces_at_directions=("-Y",),
show_correlation_surface=correlation_surfaces[0],
)
[5]:
Minimum-weight perfect matching (MWPM)
Here we plot the logical error rate of each observable of the CNOT block graph separately, computed using the MWPM decoder from pymatching.
[6]:
distances = [3, 5, 7]
decoder = decoders.SinterDecoder(
with_MWPM=True,
decompose_errors=True, # decomposes non-graphlike Y errors into independent X and Z errors
)
mwpm_stats = get_simulation_data(block_graph, distances, decoder)
[7]:
plot_stats(block_graph, mwpm_stats)
plt.show()
Sliding window decoding
Practically speaking, decoding a monolithic block graph with MWPM is not scalable. The sliding window decoder more closely resembles what would be used to decode during an actual quantum computation. In short, a sliding window decoder chops up the block graph into “windows” that are decoded separately. This method is known as the “overlapping recovery method” in arXiv:quant-ph/0110143, which is explained more nicely in
arXiv:2012.15403 and arXiv:2209.08552. See also help(decoders.SlidingWindowDecoder).
[8]:
distances = [3, 5, 7]
sliding_window_decoders = [
decoders.SlidingWindowDecoder(
dist, # decoding window size
dist // 2, # commit window size
with_MWPM=True,
decompose_errors=True, # decomposes non-graphlike Y errors into independent X and Z errors
)
for dist in distances
]
sliding_window_stats = get_simulation_data(block_graph, distances, sliding_window_decoders)
[9]:
plot_stats(block_graph, sliding_window_stats)
plt.show()
[ ]: