Code Notebooks

Eight notebooks, one continuous QML pipeline —
from your first qubit to a real capstone.

The hands-on code companion to Modules 5 through 12. Every notebook is a real, executed Jupyter notebook — run it as-is, open it directly in Google Colab with zero setup, or download it and adapt it into your own Module 12 final project.

Python PennyLane Qiskit scikit-learn Google Colab-ready 8 Notebooks
Honest by design: every result in these notebooks is real, executed output — including the ones where a classical baseline wins. Several notebooks show quantum methods matching, not beating, classical ML, which is an accurate reflection of where the field stands today, not a bug in the code.
Setup & How to Run Beginner Intermediate Advanced
Start Here

Setup & How to Run

Recommended · Zero Install

Option A — Google Colab

  1. Click Open in Colab on any notebook card below.
  2. Colab doesn't come with quantum libraries preinstalled, so run this as the very first cell, before anything else, and wait for it to finish:
    # run this first in Colab
    !pip install pennylane qiskit qiskit-aer \
        scikit-learn matplotlib numpy --quiet
  3. Then Runtime → Run all, or run each cell top to bottom with Shift + Enter.
  4. To keep your edits, go to File → Save a copy in Drive — the original link stays untouched for the next person.
Local Setup

Option B — Run in Jupyter Locally

  1. Requires Python 3.9+. Check with python3 --version.
  2. Create and activate a virtual environment (recommended, keeps this separate from other projects):
    python3 -m venv qml-env
    # macOS / Linux
    source qml-env/bin/activate
    # Windows
    qml-env\Scripts\activate
  3. Install the required libraries:
    pip install pennylane qiskit qiskit-aer \
        scikit-learn matplotlib numpy jupyter
  4. Click Download .ipynb on any notebook below, then launch Jupyter from that folder:
    jupyter notebook
  5. Open the downloaded file and run cells top to bottom (Cell → Run All).
LibraryUsed forInstall
pennylaneQuantum circuits, autodiff, QML training (Notebooks 02–08)pip install pennylane
qiskitCircuit basics, Bloch sphere, statevectors (Notebook 01, 06)pip install qiskit
qiskit-aerSimulator backend + noise models (Notebook 01, 06)pip install qiskit-aer
scikit-learnDatasets, classical SVM/logistic regression baselines, PCApip install scikit-learn
matplotlibAll plots and visualizationspip install matplotlib
numpyArray math throughout every notebookpip install numpy
jupyterOnly needed for Option B (local); Colab already has itpip install jupyter

All commands above install the same set of packages — pennylane, qiskit, qiskit-aer, scikit-learn, matplotlib, numpy — Option B adds jupyter since Colab already includes it.

Run cells top to bottom. Later cells reuse variables defined earlier — skipping around out of order will throw NameError.

Training cells take time. Notebooks 03, 05, 07 & 08 include real training loops — anywhere from a few seconds to ~1–2 minutes per cell is normal for a quantum simulator.

Numbers may vary slightly. Every notebook uses a fixed random seed, but tiny differences across library versions (PennyLane/Qiskit updates) are normal and don't indicate a broken notebook.

Built and tested with: PennyLane 0.45, Qiskit 2.5, scikit-learn 1.8, NumPy 2.4. Newer versions should work fine; if something breaks, pinning to these versions is a safe fallback.

Level 1 · Beginner

Getting Comfortable with Qubits

Companion to Module 5
NOTEBOOK 01Module 5

Quantum Computing Basics

Build single- and multi-qubit circuits in Qiskit. Apply gates, read statevectors, visualize the Bloch sphere, simulate the Born rule, and build your first entangled Bell pair.

✓ Executed · real Bell pair, Bloch sphere, measurement histograms
Level 2 · Intermediate

Encoding Data & Core QML Algorithms

Companion to Modules 8 & 9
NOTEBOOK 02Module 8

Quantum Data Encoding

Implement basis, angle, and amplitude encoding in PennyLane, build a ZZ-style feature map, and see data re-uploading squeeze expressivity from a single qubit.

✓ Executed · all four encoding strategies, live
NOTEBOOK 03Module 9

Variational Circuits & QNN

Verify the parameter-shift rule by hand, then train a full Quantum Neural Network classifier on the moons dataset and visualize its decision boundary.

✓ Executed · 87.5% test accuracy, trained live
NOTEBOOK 04Module 9

Quantum Kernels, QSVM & QPCA

Build a quantum kernel from scratch, feed it into a classical SVM, and benchmark it head-to-head against linear and RBF kernels — plus a quantum-kernel PCA projection.

✓ Executed · quantum kernel ties RBF (100%), beats linear (39%)
Level 3 · Advanced

Advanced Architectures, Noise & Real-World Use

Companion to Modules 10, 11 & 12
NOTEBOOK 05Module 11

Advanced: QCNN & Quantum GAN

Build a Quantum Convolutional Neural Network with real conv + pooling layers, then train a minimal quantum generator against a quantum discriminator — including an honest look at why adversarial training is hard to stabilize.

✓ Executed · QCNN reaches 100% test accuracy
NOTEBOOK 06Module 11

Noise & Error Mitigation

Add a realistic Qiskit Aer noise model, then implement readout error mitigation via a calibration matrix and Zero-Noise Extrapolation via gate folding.

✓ Executed · both mitigation techniques clearly reduce error
NOTEBOOK 07Module 10

Real-World Case Studies

Two full case studies: a QSVM diagnosing real breast cancer data, and a QNN predicting synthetic price direction — including an honest contrast between a learnable momentum market and pure random-walk noise.

✓ Executed · real clinical dataset + synthetic market scenarios
NOTEBOOK 08Module 12

Capstone Project

The full pipeline template: define → preprocess → encode → train → evaluate → compare, applied to handwritten digit classification — plus copy-paste-ready templates for running your circuits on real IBM Quantum hardware.

✓ Executed · full project template + IBM Quantum hardware guide