Notebook Labs - Noro-Official/OQS GitHub Wiki

Notebook Labs and Assignments

This page provides examples, design tips, and ready-to-use structures for building Jupyter-based labs and assignments with OpenQStack.

These materials are ideal for:

  • Undergraduate quantum computing courses
  • Graduate-level QEC modules
  • Remote learning environments (Colab, Binder)
  • Project-based learning or open exploration

Why Notebooks?

Jupyter notebooks let students:

  • Write and run real QEC code
  • Visualize states, errors, and recovery processes
  • Document their thought process alongside execution
  • Get immediate, visual feedback on correctness

This bridges theoretical knowledge with intuitive understanding.


Example Lab: Bit-Flip Recovery

Title: Protecting |+⟩ with a Bit-Flip Code

from openqstack.qec import BitFlipCode
from openqstack.visualize import show_state, plot_bloch
import numpy as np

psi = [1/np.sqrt(2), 1/np.sqrt(2)]
code = BitFlipCode()

encoded = code.encode(psi)
corrupted = code.apply_random_X_error(encoded)
syndrome = code.measure_syndrome(corrupted)
recovered = code.recover(corrupted, syndrome)
decoded = code.decode(recovered)

plot_bloch(decoded)

Learning goals:

  • Understand syndrome-based error detection
  • Visualize logical state restoration
  • Reflect on limits of the code (e.g. double errors)

Notebook Design Tips

  • Start with scaffolded code: have students fill in a line or two, not 50
  • Include visual checkpoints with show_state() or plot_probabilities()
  • Use assert np.allclose(...) to validate answers in real time
  • Add markdown cells that guide thinking, not just procedures

Assignment Ideas

1. Write Your Own Error Channel

class PhaseDampingChannel(ErrorChannel):
    def kraus_operators(self):
        ...

Evaluate:

  • Correctness of Kraus representation
  • Physical behavior under test states
  • Ability to describe limitations

2. Analyze a Faulty Decoder

Give students:

  • A hard-coded syndrome-to-correction map
  • Cases where it fails
  • Ask them to propose fixes or build better logic

3. Logical Error Rate Under Noise

Loop over multiple runs:

success = 0
for _ in range(1000):
    encoded = code.encode(psi)
    noisy = channel(encoded)
    recovered = code.recover(noisy, code.measure_syndrome(noisy))
    final = code.decode(recovered)
    if np.allclose(np.abs(final), np.abs(psi)):
        success += 1

Let students:

  • Graph logical success vs. noise probability
  • Identify phase transitions
  • Compare bit-flip vs. depolarizing

Running Environments

Local

pip install jupyterlab
jupyter lab

Google Colab

!git clone https://github.com/OpenQStack/OQS.git
%cd openqstack
!pip install -e .

Then open a notebook and begin importing OpenQStack.


Coming Soon

  • notebooks/ directory in the repo
  • Prebuilt .ipynb labs for classroom drop-in use
  • Binder links to run notebooks in-browser

Related Pages