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¶
-
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 -
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(),.conjexpectation values, andMeasure+.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¶
- Covers: Recovering a hidden \(n\)-bit string in a single oracle query.
- Source: 4_bernstein_vazirani.ipynb
Tutorial 5: Quantum Teleportation¶
- Covers: Mid-circuit measurement with
Measureand classical feedforward with.c_if(). - Source: 5_quantum_teleportation.ipynb
Tutorial 6: Custom Gates and Rotations¶
- Covers: Subclassing
BaseGate, \(R_y(\theta)\), fractional gates via.sqrt, and.sample(). - Source: 6_custom_gates_and_modules.ipynb
Tutorial 7: Grover's Search¶
- Covers: Phase oracle, diffusion operator, and amplitude amplification on 2 qubits.
- Source: 7_grovers_search.ipynb
Tutorial 8: Quantum Key Distribution (BB84)¶
- Covers: Random \(Z\)/\(X\) basis encoding, sifting, and detecting an intercept-resend eavesdropper.
- Source: 8_quantum_key_distribution.ipynb
Tutorial 9: Modular Circuits¶
- Covers:
ModularGate,BellModule,QFTModule,TeleportationModule, and collapsed vsdecompose_modules=Trueplotting. - Source: 9_circuit_modules.ipynb
Tutorial 10: Superdense Coding¶
- Covers: Sending 2 classical bits over 1 qubit using a shared
BellModulepair. - Source: 10_superdense_coding.ipynb
Tutorial 11: Quantum Phase Estimation¶
- Covers: Inverting
QFTModuleand estimating the eigenphase of \(T\) and \(S\) gates. - Source: 11_quantum_phase_estimation.ipynb
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()withoutMeasure,.dagger(),d=, nestedCompositeGate,eval_branches(), and no-cloning). - Source: 15_common_mistakes.ipynb
Tutorial 16: Debugging Exercises¶
- Covers: Five short broken snippets with fixes and assertions.
- Source: 16_fix_the_bug.ipynb
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¶
- Practice Exercises: 5 exercises on superposition, Bell states, 3-qubit oracles, expectation values, and rotations.
- Practice Solutions: Worked solutions with assertions.