Code
qcr:2606.34718.1

Shor's Nine-Qubit Code

Shor's code is the first quantum error-correcting code ever devised, and this Cirq example implements it directly as a quantum circuit. It encodes a single logical qubit into nine physical qubits and can correct an arbitrary error on any one of them, whether a bit flip, a phase (sign) flip, or any combination of the two, which is the key insight that made fault-tolerant quantum computing conceivable. The construction is a concatenation of two simpler three-qubit codes: an outer phase-flip code protects against sign errors, and within each of its three blocks an inner bit-flip code protects against bit errors, so the nine-qubit codeword is resilient to the most general single-qubit error. The example builds the full encoding circuit, optionally injects an error, and applies the syndrome-measurement and recovery operations that detect which qubit was affected and correct it without disturbing the encoded logical information. By walking through encoding, error, and correction on an explicit circuit, the script makes the abstract theory of stabilizer error correction concrete, showing exactly how redundancy and entanglement are used to protect quantum information. It is a foundational example for anyone learning quantum error correction.
QEC
Qubit
Circuit-based
Uploaded 1 day ago
14
Views
GitHub4990
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

quantumlib/Cirq
49901228
README.md

Shor's Nine-Qubit Code

Shor's code is the first quantum error-correcting code ever devised, and this Cirq example implements it directly as a quantum circuit. It encodes a single logical qubit into nine physical qubits and can correct an arbitrary error on any one of them, whether a bit flip, a phase (sign) flip, or any combination of the two, which is the key insight that made fault-tolerant quantum computing conceivable. The construction is a concatenation of two simpler three-qubit codes: an outer phase-flip code protects against sign errors, and within each of its three blocks an inner bit-flip code protects against bit errors, so the nine-qubit codeword is resilient to the most general single-qubit error. The example builds the full encoding circuit, optionally injects an error, and applies the syndrome-measurement and recovery operations that detect which qubit was affected and correct it without disturbing the encoded logical information. By walking through encoding, error, and correction on an explicit circuit, the script makes the abstract theory of stabilizer error correction concrete, showing exactly how redundancy and entanglement are used to protect quantum information. It is a foundational example for anyone learning quantum error correction.

Run it

pip install -r requirements.txt
python shors_code.py

Source and license

Imported from examples/shors_code.py in quantumlib/Cirq at v1.6.1, under the Apache License 2.0. Original authors: The Cirq Developers. The upstream LICENSE is included alongside this example.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Versions

v1 Latest
Jun 17, 2026
qcr:2606.34718.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

Cirq

Keywords

shor-code
error-correction
bit-flip
phase-flip
stabilizer

You may also like5