Steane Encoding#
This notebook demonstrates the construction and simulation of a logical Steane encoder circuit. Steane code was introduced by Andrew Steane in 1996 [1]. In surface code, this logical circuit can be used to prepare the magic state for logical S gate [2].
Construction#
tqec
provides builtin functions tqec.gallery.steane_encoding
to construct it.
[1]:
from tqec.gallery.steane_encoding import steane_encoding
graph = steane_encoding()
graph.view_as_html()
[1]:
We can use the find_correlation_surfaces()
method to identify all correlation surfaces, and then visualize them using the view_as_html()
method. In this case, there are a total of seven correlation surfaces. For simplicity, only two are shown here.
[2]:
correlation_surfaces = graph.find_correlation_surfaces()
len(correlation_surfaces)
[2]:
7
[3]:
graph.view_as_html(
pop_faces_at_direction="-Y",
show_correlation_surface=correlation_surfaces[0],
)
[3]:
[4]:
graph.view_as_html(
pop_faces_at_direction="-Y",
show_correlation_surface=correlation_surfaces[1],
)
[4]:
Circuit#
Here we show an example circuit of Steane encoding circuit with \(d=3\) that is initialized and measured in X basis. The circuit can be downloaded here or viewed in Crumble.
[5]:
from tqec import Basis, NoiseModel, compile_block_graph
graph = steane_encoding(Basis.X)
compiled_graph = compile_block_graph(graph)
circuit = compiled_graph.generate_stim_circuit(
k=1, noise_model=NoiseModel.uniform_depolarizing(p=0.001)
)
Simulation#
Here we show the simulation results for all the seven observables under uniform depolarizing noise model.
Click to show the full code used for simulation
from pathlib import Path
import matplotlib.pyplot as plt
import numpy
import sinter
from tqec.gallery import steane_encoding
from tqec import NoiseModel
from tqec.simulation.plotting.inset import plot_observable_as_inset
from tqec.simulation.simulation import start_simulation_using_sinter
from tqec.utils.enums import Basis
SAVE_DIR = Path("results")
def generate_graphs(support_observable_basis: Basis) -> None:
block_graph = steane_encoding(support_observable_basis)
zx_graph = block_graph.to_zx_graph()
correlation_surfaces = block_graph.find_correlation_surfaces()
# Start simulation using sinter, note that the `save_resume_filepath` is useful
# when simulation takes a long time.
# If the Python interpreter is stopped or killed, calling this method again with
# the same file path will load the previous results and resume from where it left off.
stats = start_simulation_using_sinter(
block_graph,
range(1, 4),
list(numpy.logspace(-4, -1, 10)),
NoiseModel.uniform_depolarizing,
manhattan_radius=2,
observables=correlation_surfaces,
num_workers=20,
max_shots=10_000_000,
max_errors=5_000,
decoders=["pymatching"],
print_progress=True,
# save_resume_filepath=SAVE_DIR / "steane_encoding_sim.txt",
)
for i, stat in enumerate(stats):
fig, ax = plt.subplots()
sinter.plot_error_rate(
ax=ax,
stats=stat,
x_func=lambda stat: stat.json_metadata["p"],
failure_units_per_shot_func=lambda stat: stat.json_metadata["d"],
group_func=lambda stat: stat.json_metadata["d"],
)
plot_observable_as_inset(ax, zx_graph, correlation_surfaces[i])
ax.grid(axis="both")
ax.legend()
ax.loglog()
ax.set_title("Steane Encoding Error Rate")
ax.set_xlabel("Physical Error Rate")
ax.set_ylabel("Logical Error Rate(per round)")
fig.savefig(
SAVE_DIR
/ f"steane_encoding_result_{support_observable_basis}_observable_{i}.png"
)
def main():
SAVE_DIR.mkdir(exist_ok=True)
generate_graphs(Basis.X)
generate_graphs(Basis.Z)
if __name__ == "__main__":
main()







References#
[1] Steane, A. (1996). Multiple-particle interference and quantum error correction. Proceedings of the Royal Society of London. Series A: Mathematical, Physical and Engineering Sciences, 452(1954), 2551-2577.
[2] Fowler, A. G., Mariantoni, M., Martinis, J. M., & Cleland, A. N. (2012). Surface codes: Towards practical large-scale quantum computation. Physical Review A—Atomic, Molecular, and Optical Physics, 86(3), 032324.