First QEC Simulation - Noro-Official/OQS GitHub Wiki
3. First QEC Simulation
This guide will walk you through your first quantum error correction (QEC) experiment using OpenQStack.
Youβll run a full encode β error β syndrome β recovery β decode cycle using the 3-qubit bit-flip code.
Step 1: Run the Demo
Navigate to the examples/
directory and run the demo script:
cd examples
python openq_blink.py
Step 2: Understand Whatβs Happening
The script performs a full QEC cycle:
-
Encoding
The logical qubit (e.g.,|Οβ© = |0β©
) is encoded into a 3-qubit state. -
Error Injection
A random bit-flip error (X
gate) is applied to one of the physical qubits. -
Syndrome Measurement
A parity check is performed to detect the error. -
Recovery
Based on the syndrome, the most likely correction is applied. -
Decoding
The recovered 3-qubit state is decoded back to a single-qubit logical state.
You will see:
- Intermediate states printed to the terminal
- Syndrome bits displayed (e.g.,
"010"
) - The final recovered logical qubit state
- A probability plot (if
matplotlib
is installed)
Step 3: Project Structure
openqstack/
βββ openqstack/ # Core logic: codes, noise, visualization
β βββ qec.py
β βββ visualize.py
β βββ __init__.py
β
βββ examples/ # Demo scripts and walkthroughs
β βββ openq_blink.py
β
βββ tests/ # Unit tests
β βββ test_bitflip.py
β
βββ requirements.txt # Python dependencies
βββ setup.py # Installable module
βββ README.md # Project overview
Step 4: Try More
Once the basic demo is working, try:
-
Changing the logical input state:
psi = [1/np.sqrt(2), 1/np.sqrt(2)]
-
Using a depolarizing noise model:
from openqstack.qec import DepolarizingChannel channel = DepolarizingChannel(p=0.1, n_qubits=3) noisy_state = channel(encoded)
-
Visualizing results:
from openqstack.visualize import plot_bloch plot_bloch(decoded)
-
Writing your own recovery logic or adding a custom error
Step 5: Troubleshooting
If something goes wrong:
-
Make sure you're using Python 3.8+
-
Install missing packages:
pip install -r requirements.txt
-
If plots donβt show:
pip install matplotlib
-
Run tests to confirm functionality:
pytest tests/
-
Verify package visibility:
python -m openqstack
Questions?
OpenQStack is an open-source initiative supporting quantum education.
- Found a bug? Open an issue.
- Teaching with OpenQStack? Let us know.
- Want to contribute? Fork the repo or start a discussion.
We welcome collaboration from students, educators, and researchers.