First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 8.1

What is Quantum Machine Learning (QML)?

Explore the intersection of quantum computing and artificial intelligence: four quadrants of QML, quantum speedups, and hybrid architectures.

Learning Objectives

  • ✓Define the 4 Quadrants of QML (Classical Data / Classical Algorithm, Quantum Data / Classical, Classical Data / Quantum, Quantum Data / Quantum)
  • ✓Understand how quantum mechanics enhances machine learning optimization
  • ✓Examine current NISQ-era hybrid quantum-classical computing

📖Let's Begin with a Story

In 2017, machine learning researchers were struggling with a problem: as neural networks grew to billions of parameters, training them on classical GPUs consumed megawatts of electricity and weeks of compute. Meanwhile, quantum physicists were struggling with their own problem: real-world quantum computers had noisy, imperfect qubits that could only execute short, shallow circuits before decohering into noise. Then came a marriage of minds: Quantum Machine Learning (QML)! Machine learning algorithms are inherently robust to noise—neural networks learn through statistical averages! And quantum processors excel at high-dimensional linear algebra. By teaming up a classical GPU with a Quantum Processing Unit (QPU), researchers created a hybrid powerhouse: the classical computer handles memory and data loading, while the quantum computer acts as a high-dimensional mathematical co-processor.

Why Should You Learn What is Quantum Machine Learning (QML)??

🎯 Practical & Engineering Stakes

The next AI frontier

Google, IBM, Rigetti, and Xanadu are investing heavily in QML. As classical silicon scaling hits physical limits, quantum-enhanced machine learning offers the primary path forward for processing high-dimensional data spaces.

What Is It?

Simple Explanation

Quantum Machine Learning is the marriage of AI and Quantum Physics: - AI provides the learning brain (learning from data, optimizing weights). - Quantum Computing provides the rocket fuel (exponential 2^n state spaces and interference). Together, they allow computers to find patterns in complex data that no classical algorithm could ever detect!

Technical Explanation

Quantum Machine Learning explores the intersection of quantum information processing and statistical learning theory. The canonical taxonomy (Aimeur et al., 2006) classifies QML along two axes: nature of data (Classical vs Quantum) and nature of processing device (Classical vs Quantum), forming four quadrants: CC, QC, CQ, and QQ. In the current NISQ era, CQ (Classical Data on Quantum Algorithms) via Parameterized Quantum Circuits (PQCs) dominates practical research.

📚 Key Terms

Quantum Machine Learning (QML)

Simple: Using quantum computers to run machine learning algorithms faster or find deeper patterns.
Technical: The integration of quantum algorithms within statistical machine learning workflows.

Parameterized Quantum Circuit (PQC)

Simple: A quantum circuit with adjustable knobs (angles theta) that acts like a neural network.
Technical: A quantum circuit U(θ)U(\boldsymbol{\theta}) containing tunable rotational gates optimized via classical gradient descent.

Quantum Processing Unit (QPU)

Simple: The physical quantum chip sitting inside the dilution refrigerator.
Technical: The specialized co-processor executing unitary quantum circuits.

Q-Sphere Lab: What is Quantum Machine Learning (QML)?

IBM Q-Sphere Model

Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 8.1

Azimuth: 45°Elevation: 25°
+Z |0⟩-Z |1⟩+X |+⟩+Y |+i⟩01|ψ⟩
Q-Sphere Phase Color:
0 π/2 π 3π/2

Quantum Statevector

dim(H) = 2
|ψ⟩ = (1.000 + 0.000i)|0⟩
     + (0.000 + 0.000i)|1⟩
Polar Angle (θ):0.0° (0.000π rad)
Phase Angle (ϕ):0.0° (0.000π rad)

Born Rule Probabilities: P(x) = |⟨x|ψ⟩|²Σ P = 1.00

P(|0⟩) = |α|²100.0%
P(|1⟩) = |β|²0.0%
Quantum Measurement

Apply Single-Qubit Unitary Gates

Presets:
Continuous Polar Angle θ (0° = |0⟩, 180° = |1⟩):0.0°
Continuous Phase Angle ϕ (0° to 360°):0.0°
Recent Operations Log:
#1Initial state: |0⟩

📐 Mathematical Foundation

LaTeX KaTeX
f(x;θ)=⟨0∣U†(x)W†(θ)MW(θ)U(x)∣0⟩=Tr(M W(θ)ρ(x)W†(θ))f(\mathbf{x}; \boldsymbol{\theta}) = \langle 0 | U^\dagger(\mathbf{x}) W^\dagger(\boldsymbol{\theta}) M W(\boldsymbol{\theta}) U(\mathbf{x}) | 0 \rangle = \text{Tr}\big( M \, W(\boldsymbol{\theta}) \rho(\mathbf{x}) W^\dagger(\boldsymbol{\theta}) \big)

What does it mean?

The Fundamental Quantum Machine Learning (QML) Model: In quantum machine learning, a quantum neural network processes classical data by first encoding input vector x into an entangled quantum state rho(x) = U(x)|0><0|U^dagger(x). Next, a parameterized variational ansatz W(theta) applies tunable rotation and entangling gates. Finally, a Hermitian observable M (such as Pauli-Z) is measured, yielding an expectation value in [-1, +1] that serves as the model’s prediction score.

Understanding the Symbols

Symbol / TermMeaningBeginner Interpretation
U(x)U(\mathbf{x})Quantum Feature MapUnitary transformation mapping classical vector x into quantum Hilbert space
W(θ)W(\boldsymbol{\theta})Parameterized Variational AnsatzLearnable quantum circuit weights θ\boldsymbol{\theta} optimized via gradient descent
MMHermitian Readout ObservableMeasurement operator whose statistical expectation value yields continuous prediction
f(x;θ)f(\mathbf{x}; \boldsymbol{\theta})Model Prediction ScoreOutput scalar bounded between the eigenvalues of observable M

📊 Numerical Example

Evaluating a 1-qubit QML model with input feature x = 0.5 radians, trainable weight theta = 1.2 radians, and Pauli-Z readout observable:

Step 1: Quantum Feature Encoding U(x): Apply Ry(x) on ground state ∣0⟩|0\rangle with x = 0.5 rad (28.6°): |ψ(x)⟩ = Ry(0.5)∣0⟩|0\rangle = cos(0.25)∣0⟩|0\rangle + sin(0.25)∣1⟩|1\rangle = 0.9689∣0⟩|0\rangle + 0.2474∣1⟩|1\rangle Step 2: Apply Parameterized Ansatz W(θ): Apply trainable rotation Ry(θ) with θ = 1.2 rad (68.8°): Total rotation angle = x + θ = 0.5 + 1.2 = 1.70 radians |ψ(x, θ)⟩ = Ry(1.70)∣0⟩|0\rangle = cos(0.85)∣0⟩|0\rangle + sin(0.85)∣1⟩|1\rangle = 0.6600∣0⟩|0\rangle + 0.7513∣1⟩|1\rangle Step 3: Measure Expectation of Pauli-Z Observable (M = Z): ⟨Z⟩ = |⟨0∣\langle 0|ψ⟩|² - |⟨1∣\langle 1|ψ⟩|² = (0.6600)² - (0.7513)² = 0.4356 - 0.5644 = -0.1288 Analytical Check: cos(x + θ) = cos(1.70 rad) = -0.1288 Step 4: Map to Binary Classification Probability: P(Class 1) = (⟨Z⟩ + 1) / 2 = (-0.1288 + 1) / 2 = 0.4356 (43.56%)

Result: The model predicts Class 0 with 56.44% confidence and Class 1 with 43.56% confidence.

⚙️ How Does It Work?

1

Classical Ingestion

Classical CPU loads and normalizes training batch.

2

Quantum Encoding

QPU executes feature map U(x) to embed features into quantum Hilbert space.

3

Variational Processing

Parameterized gates W(theta) rotate state space.

4

Measurement & Gradient

Expectation values are measured and passed to classical optimizer (Adam/COBYLA) to update weights theta.

🌍 Where Is It Used?

High-Energy Particle Physics (CERN)

Problem: Classifying Higgs Boson particle decay events from millions of LHC sensor hits.

Solution: Quantum Support Vector Classifiers map particle momentum tensors into quantum Hilbert spaces.

🎯 Try It Yourself

A data scientist trains a Parameterized Quantum Circuit on a QPU to classify classical cancer biopsy data. Which QML quadrant does this belong to?

Interactive activity component

🐍 Python Hands-On: Building a Parameterized Quantum Machine Learning Model in Qiskit

Construct an end-to-end QML circuit with feature encoding gates, trainable ansatz weights, and Pauli-Z expectation readout.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install qiskit scipy numpy
Packages:
qiskitscipynumpy

2Import Libraries

Import Statementspython
1from qiskit import QuantumCircuit
2from qiskit.circuit import Parameter
3from qiskit.quantum_info import Statevector, SparsePauliOp
4import numpy as np

from qiskit import QuantumCircuit → Circuit constructor

from qiskit.circuit import Parameter → Trainable parameterized angles

from qiskit.quantum_info import Statevector, SparsePauliOp → Statevector and observables

import numpy as np → Numerical array support

3Demonstration Code & Logic

Python Execution Codepython
1# 1. Define symbolic parameters for input feature x and trainable weight w
2x_param = Parameter('x_feature')
3w_param = Parameter('w_weight')
4
5# 2. Assemble QML Circuit: Encoding + Variational Layer
6qc = QuantumCircuit(1)
7qc.ry(x_param, 0) # Feature Encoding Layer: Ry(x)
8qc.rz(w_param, 0) # Trainable Parameter Layer: Rz(w)
9print('Qiskit Parameterized QML Circuit:')
10print(qc.draw('text'))
11
12# 3. Bind values and compute expectation value <Z>
13observable = SparsePauliOp('Z')
14bound_qc = qc.assign_parameters({x_param: 0.8, w_param: 1.5})
15state = Statevector.from_instruction(bound_qc)
16expectation = state.expectation_value(observable).real
17print(f'\nBound Parameters: x = 0.8, w = 1.5')
18print(f'Quantum Model Prediction <Z>: {expectation:.4f}')
19predicted_class = 1 if expectation > 0 else 0
20print(f'Predicted Class: {predicted_class}')
Step-by-Step Code Breakdown:

# 1. Define symbolic parameters for input feature x and trainable weight w

Parameters

x_param = Parameter('x_feature')

Input feature parameter

w_param = Parameter('w_weight')

Trainable parameter

# 2. Assemble QML Circuit: Encoding + Variational Layer

Assemble

qc = QuantumCircuit(1)

Single qubit

qc.ry(x_param, 0) # Feature Encoding Layer: Ry(x)

Encoding

qc.rz(w_param, 0) # Trainable Parameter Layer: Rz(w)

Weight

print('Qiskit Parameterized QML Circuit:')

Label

print(qc.draw('text'))

Print circuit

# 3. Bind values and compute expectation value <Z>

Binding & Evaluation

observable = SparsePauliOp('Z')

Pauli Z observable

bound_qc = qc.assign_parameters({x_param: 0.8, w_param: 1.5})

Bind parameters

state = Statevector.from_instruction(bound_qc)

Compute statevector

expectation = state.expectation_value(observable).real

Evaluate <Z>

print(f'\nBound Parameters: x = 0.8, w = 1.5')

Print bound

print(f'Quantum Model Prediction <Z>: {expectation:.4f}')

Prediction between -1 and +1

predicted_class = 1 if expectation > 0 else 0

Binary decision

print(f'Predicted Class: {predicted_class}')

Class decision

📋 Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Building a Parameterized Quantum Machine Learning Model in Qiskit
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install qiskit scipy numpy
8
9# Step 2: Import libraries
10from qiskit import QuantumCircuit
11from qiskit.circuit import Parameter
12from qiskit.quantum_info import Statevector, SparsePauliOp
13import numpy as np
14
15# Step 3: Run Demonstration
16# 1. Define symbolic parameters for input feature x and trainable weight w
17x_param = Parameter('x_feature')
18w_param = Parameter('w_weight')
19
20# 2. Assemble QML Circuit: Encoding + Variational Layer
21qc = QuantumCircuit(1)
22qc.ry(x_param, 0) # Feature Encoding Layer: Ry(x)
23qc.rz(w_param, 0) # Trainable Parameter Layer: Rz(w)
24print('Qiskit Parameterized QML Circuit:')
25print(qc.draw('text'))
26
27# 3. Bind values and compute expectation value <Z>
28observable = SparsePauliOp('Z')
29bound_qc = qc.assign_parameters({x_param: 0.8, w_param: 1.5})
30state = Statevector.from_instruction(bound_qc)
31expectation = state.expectation_value(observable).real
32print(f'\nBound Parameters: x = 0.8, w = 1.5')
33print(f'Quantum Model Prediction <Z>: {expectation:.4f}')
34predicted_class = 1 if expectation > 0 else 0
35print(f'Predicted Class: {predicted_class}')
⚡ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

🔄 Algorithmic Execution Flow

1
Declare Parameters

Create symbolic parameters for features and weights using Qiskit Parameter.

→
2
Construct Differentiable Circuit

Compose feature map and variational ansatz into a single QuantumCircuit.

→
3
Evaluate Expectation Value

Bind numerical values and calculate Pauli-Z expectation value to produce a model prediction.

📥 Input / Initial State
Input feature x = 0.8, weight parameter w = 1.5.
📤 Expected Output
Qiskit Parameterized QML Circuit:
q_0: ──[ Ry(x_feature) ]──[ Rz(w_weight) ]──
Prediction <Z>: ~0.6967
Predicted Class: 1
💡 What Does This Demonstration Show?

Quantum machine learning models represent functional hypotheses as parameterized quantum circuits. Adjusting gate angles w trains the quantum state vector to classify incoming features x.

Course Learning Resource • Slide DeckLesson 1011 Slides

Lesson 10: Variational Quantum Classification

Feature maps, ansatz, COBYLA optimization, and complete VQC pipeline.

Author: Dr. Syed Muzamil Basha• FDP Approved Curriculum
Open in New Tab

📝 Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: What is a Parameterized Quantum Circuit (PQC) in the context of Quantum Machine Learning?

Question 2: Placeholder question 2

Question 3: Placeholder question 3

Question 4: Placeholder question 4

Question 5: Placeholder question 5