Research projectIntermediateEarly research model

Quantum Neural Network using PennyLane

Quantum Neural Network using PennyLane

A two-qubit QNN with data re-uploading for classifying "moons", with a numerical check of the parameter-shift ruleParameter-Shift Rule: The parameter-shift rule computes the exact derivative of an expectation value with respect to the angle of a gate e^-iθ P/2 from two evaluations of the same circuit at… and a plot of the decision boundary.

An educational research project on small data and quantum simulation: the results measure the model's behaviour in this setting only, and prove no quantum advantage.

The notebook and Google Colab

04-qnn-pennylane.ipynb — The notebook ran in full without errors (2026-11-20 08:11 UTC, 26 s on CPU)

The notebook has not yet been published in a public GitHub repository, so we do not give a direct Colab link. Download the notebook, then open it from Colab via "File → Upload notebook".

The notebook's twelve sections
  1. Project title
  2. Problem statement
  3. Installing the libraries
  4. Importing the libraries
  5. data loading
  6. Preprocessing
  7. Building the quantum model
  8. Training
  9. Evaluation
  10. Charts
  11. Results
  12. References

The notebook runs on a CPU without a GPU, and pins the versions it was tested with in its first cell.

Research problem

How does a small quantum model gain the ability to represent non-linear decision boundaries? And do parameter-shift gradients match automatic differentiation?

Objectives

  • Build a QNN with all its components: encoding, parameters, entanglement, measurement, optimiser.
  • Verify the parameter-shift rule.
  • Train with mini-batches.
  • Plot the model's output surface.
DataMoons (make_moons, 200 samples) — Generated programmatically in the notebook (scikit-learn or NumPy) No restrictions
Architecture($R_Y(x)$ ← StronglyEntanglingLayers) × 4 ← $\langle Z_0Z_1\rangle$
ToolsPennyLane 0.45.1 · scikit-learn · Matplotlib
Evaluation metricsTrain/Test Accuracy · max |∇AD − ∇PS| · Parameter count · Training time

Method

  1. Generate and split the data.
  2. Scale to [−π/2, π/2].
  3. Build the QNN and compare the two gradients.
  4. Train for 40 epochs with batches of 16.
  5. Evaluate and compare with a small MLP.
  6. Plot the decision surface.

Linked interactive experiment

References

  1. Maria Schuld; Ryan Sweke; Johannes Jakob Meyer (2021). Effect of data encoding on the expressive power of variational quantum-machine-learning models. Physical Review A 103, 032430 doi:10.1103/PhysRevA.103.032430
  2. Adrián Pérez-Salinas; Alba Cervera-Lierta; Elies Gil-Fuster; José I. Latorre (2020). Data re-uploading for a universal quantum classifier. Quantum 4, 226 doi:10.22331/q-2020-02-06-226
  3. Maria Schuld; Ville Bergholm; Christian Gogolin; Josh Izaac; Nathan Killoran (2019). Evaluating analytic gradients on quantum hardware. Physical Review A 99, 032331 doi:10.1103/PhysRevA.99.032331
  4. K. Mitarai; M. Negoro; M. Kitagawa; K. Fujii (2018). Quantum circuit learning. Phys. Rev. A 98:032309 doi:10.1103/PhysRevA.98.032309