Build repetition codes
Estimated QPU usage: 2 seconds (tested on IBM Algiers)
Background
To enable real-time quantum error correction (QEC), you need to be able to dynamically control quantum program flow during execution so that quantum gates can be conditioned on measurement results. This tutorial runs the bit-flip code, which is a very simple form of QEC. It demonstrates a dynamic quantum circuit that can protect an encoded qubit from a single bit-flip error, and then evaluates the bit-flip code performance.
You can exploit additional ancilla qubits and entanglement to measure stabilizers that do not transform encoded quantum information, while still informing you of some classes of errors that might have occurred. A quantum stabilizer code encodes logical qubits into physical qubits. Stabilizer codes critically focus on correcting a discrete error set with support from the Pauli group .
For more information about QEC, refer to Quantum Error Correction for Beginners.
Requirements
Before starting this tutorial, ensure that you have the following installed:
- Qiskit SDK 1.0 or later with visualization support (
pip install qiskit[visualization] ) - Qiskit Runtime 0.22 or later (
pip install qiskit-ibm-runtime )
Setup
Output:
>>> Connected to ibm_algiers.
Step 1. Map classical inputs to a quantum problem
Build a bit-flip stabilizer circuit
The bit-flip code is among the simplest examples of a stabilizer code. It protects the state against a single bit-flip (X) error on any of the encoding qubits. Consider the action of bit-flip error , which maps and on any of our qubits, then we have . The code requires five qubits: three are used to encode the protected state, and the remaining two are used as stabilizer measurement ancillas.
No output produced
No output produced
Output:
Step 2. Optimize the problem for quantum execution
To reduce the total job execution time, Qiskit primitives only accept circuits and observables that conforms to the instructions and connectivity supported by the target system (referred to as instruction set architecture (ISA) circuits and observables). Learn more about transpilation.
Generate ISA circuits
Output:
No output produced
Step 3. Execute using Qiskit primitives
Run the version with correction applied and one without correction.
No output produced
No output produced
Output:
Data (no correction):
{'101': 146, '111': 516, '011': 180, '000': 25, '110': 23, '100': 16, '001': 46, '010': 48}
Syndrome (no correction):
{'01': 206, '00': 736, '11': 20, '10': 38}
Output:
Data (corrected):
{'010': 18, '101': 139, '111': 540, '100': 18, '001': 47, '011': 169, '000': 18, '110': 51}
Syndrome (corrected):
{'11': 19, '00': 809, '10': 90, '01': 82}
Step 4. Post-process, return result in classical format
You can see that the bit flip code detected and corrected many errors; resulting in fewer errors overall.
No output produced
Output:
Completed bit code experiment data measurement counts (without correction): {'101': 146, '111': 516, '011': 180, '000': 25, '110': 23, '100': 16, '001': 46, '010': 48}
Completed bit code experiment syndrome measurement counts (without correction): {'01': 206, '00': 736, '11': 20, '10': 38}
Bit flip errors were detected/corrected on 264/1000 trials.
A final parity error was detected on 459/1000 trials.
Output:
Completed bit code experiment data measurement counts (corrected): {'010': 18, '101': 139, '111': 540, '100': 18, '001': 47, '011': 169, '000': 18, '110': 51}
Completed bit code experiment syndrome measurement counts (corrected): {'11': 19, '00': 809, '10': 90, '01': 82}
Bit flip errors were detected/corrected on 191/1000 trials.
A final parity error was detected on 442/1000 trials.
Tutorial Survey
Tutorial Survey Please take one minute to provide feedback on this tutorial. Your insights will help us improve our content offerings and user experience. |
Was this page helpful?