Skip to content

Tutorials

The quantum-emotion notebooks walk through quantum computing basics and how the package works, from single-qubit gates up to modular circuits and tensor network contraction.


Running Tutorials Locally

  1. Clone and install with docs/notebook dependencies:

    git clone https://github.com/QC2-python-SE/quantum-emotion.git
    cd quantum-emotion
    uv sync --extra docs
    

  2. Open Jupyter:

    uv run jupyter notebook notebooks/
    

Or open the folder in VS Code with the Jupyter extension.


Curriculum Map

Tutorial Topic Main Primitives Notebook Theory
0. Getting Started Package basics KetState, @, .eval(), .plot() Notebook States and Gates
1. Superposition Single-qubit gates KetState, Hadamard, PauliX Notebook States and Gates
2. Bell States Two-qubit entanglement CNOT, Hadamard, BraState Notebook Entanglement
3. Deutsch's Algorithm Phase kickback CNOT, PauliX, oracles Notebook Algorithms
4. Bernstein-Vazirani Hidden bitstring Hadamard, CNOT Notebook Algorithms
5. Teleportation Mid-circuit feedforward Measure, .c_if(), PauliZ Notebook Algorithms
6. Custom Gates Subclassing & rotations BaseGate, \(R_y(\theta)\), .sqrt Notebook Modules
7. Grover's Search Amplitude amplification ControlledZ, \(R_s\) Notebook Algorithms
8. Key Distribution BB84 & eavesdropping \(Z\)/\(X\) bases, sifting Notebook Algorithms
9. Modular Circuits Reusable subcircuits ModularGate, BellModule Notebook Modules
10. Superdense Coding 2 bits in 1 qubit BellModule, Pauli encoding Notebook Algorithms
11. Phase Estimation Estimating eigenphases QFTModule, InverseQFTModule Notebook Algorithms
12. Entanglement Swapping Quantum repeaters BellModule, .c_if() Notebook Algorithms
13. Shot Noise Finite sampling .sample(shots=...), \(1/\sqrt{N}\) Notebook Entanglement
14. Large Circuits 40-qubit contraction & limits cotengra, tensor networks Notebook Boundaries
15. Common Mistakes Tracebacks & fixes 8 common gotchas Notebook Troubleshooting
16. Debugging Exercises Fix-the-bug practice 5 broken snippets Notebook Troubleshooting
17. Putting It All Together Dynamic circuits (2024 paper) BellModule, Measure, .c_if() parity Notebook Entanglement

Notebook Summaries

Tutorial 0: Getting Started

  • Covers: KetState, @ operator, .eval() probabilities, .plot(), .conj expectation values, and Measure + .sample().
  • Source: 0_getting_started.ipynb

Tutorial 1: Superposition

  • Covers: KetState(N=1), PauliX, Hadamard, Born rule probabilities, and \(H^2 = I\).
  • Source: 1_superposition.ipynb

Tutorial 2: Bell States

  • Covers: Two-qubit entanglement, the four Bell basis states, inner products with BraState, and a 3-qubit GHZ exercise.
  • Source: 2_bell_states.ipynb

Tutorial 3: Deutsch's Algorithm

  • Covers: Phase kickback and distinguishing constant vs balanced 1-bit functions in one query.
  • Source: 3_deutsch_algorithm.ipynb

Tutorial 4: Bernstein-Vazirani

Tutorial 5: Quantum Teleportation

Tutorial 6: Custom Gates and Rotations

  • Covers: Phase oracle, diffusion operator, and amplitude amplification on 2 qubits.
  • Source: 7_grovers_search.ipynb

Tutorial 8: Quantum Key Distribution (BB84)

Tutorial 9: Modular Circuits

  • Covers: ModularGate, BellModule, QFTModule, TeleportationModule, and collapsed vs decompose_modules=True plotting.
  • Source: 9_circuit_modules.ipynb

Tutorial 10: Superdense Coding

Tutorial 11: Quantum Phase Estimation

Tutorial 12: Entanglement Swapping

  • Covers: Swapping entanglement between two distant wires using a middle Bell measurement and .c_if() corrections.
  • Source: 12_entanglement_swapping.ipynb

Tutorial 13: Measurements and Shot Noise

  • Covers: Finite-shot sampling, \(1/\sqrt{N}\) standard error scaling, and reconstructing expectation values from counts.
  • Source: 13_shots_and_sampling.ipynb

Tutorial 14: Large Circuits and Tensor Networks

  • Covers: Why \(2^N\) state vectors hit a RAM wall, contracting a 40-qubit GHZ chain via cotengra (\(U^\dagger U = I\) cancellation + low cut entanglement), and where deeper circuits slow down.
  • Source: 14_large_circuits.ipynb

Tutorial 15: Common Mistakes and Fixes

  • Covers: Eight common errors (.probabilities(), .eval() on scalars, .sample() without Measure, .dagger(), d=, nested CompositeGate, eval_branches(), and no-cloning).
  • Source: 15_common_mistakes.ipynb

Tutorial 16: Debugging Exercises

Tutorial 17: Putting It All Together

  • Covers: Reproducing Bäumer et al. (PRX Quantum 2024) constant-depth long-range CNOT teleportation and constant-depth GHZ preparation using BellModule, Measure, and .c_if() parity feedforward.
  • Source: 17_putting_it_all_together.ipynb

Practice Workbook