Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Explore the intersection of quantum computing and artificial intelligence: four quadrants of QML, quantum speedups, and hybrid architectures.
Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 8.1
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Quantum Feature Map | Unitary transformation mapping classical vector x into quantum Hilbert space | |
| Parameterized Variational Ansatz | Learnable quantum circuit weights optimized via gradient descent | |
| Hermitian Readout Observable | Measurement operator whose statistical expectation value yields continuous prediction | |
| Model Prediction Score | Output scalar bounded between the eigenvalues of observable M |
Evaluating a 1-qubit QML model with input feature x = 0.5 radians, trainable weight theta = 1.2 radians, and Pauli-Z readout observable:
Result: The model predicts Class 0 with 56.44% confidence and Class 1 with 43.56% confidence.
Classical CPU loads and normalizes training batch.
QPU executes feature map U(x) to embed features into quantum Hilbert space.
Parameterized gates W(theta) rotate state space.
Expectation values are measured and passed to classical optimizer (Adam/COBYLA) to update weights theta.
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.
Interactive activity component
Construct an end-to-end QML circuit with feature encoding gates, trainable ansatz weights, and Pauli-Z expectation readout.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install qiskit scipy numpy1 from qiskit import QuantumCircuit 2 from qiskit.circuit import Parameter 3 from qiskit.quantum_info import Statevector, SparsePauliOp 4 import 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
1 # 1. Define symbolic parameters for input feature x and trainable weight w 2 x_param = Parameter('x_feature') 3 w_param = Parameter('w_weight') 4 5 # 2. Assemble QML Circuit: Encoding + Variational Layer 6 qc = QuantumCircuit(1) 7 qc.ry(x_param, 0) # Feature Encoding Layer: Ry(x) 8 qc.rz(w_param, 0) # Trainable Parameter Layer: Rz(w) 9 print('Qiskit Parameterized QML Circuit:') 10 print(qc.draw('text')) 11 12 # 3. Bind values and compute expectation value <Z> 13 observable = SparsePauliOp('Z') 14 bound_qc = qc.assign_parameters({x_param: 0.8, w_param: 1.5}) 15 state = Statevector.from_instruction(bound_qc) 16 expectation = state.expectation_value(observable).real 17 print(f'\nBound Parameters: x = 0.8, w = 1.5') 18 print(f'Quantum Model Prediction <Z>: {expectation:.4f}') 19 predicted_class = 1 if expectation > 0 else 0 20 print(f'Predicted Class: {predicted_class}')
# 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
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
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 10 from qiskit import QuantumCircuit 11 from qiskit.circuit import Parameter 12 from qiskit.quantum_info import Statevector, SparsePauliOp 13 import numpy as np 14 15 # Step 3: Run Demonstration 16 # 1. Define symbolic parameters for input feature x and trainable weight w 17 x_param = Parameter('x_feature') 18 w_param = Parameter('w_weight') 19 20 # 2. Assemble QML Circuit: Encoding + Variational Layer 21 qc = QuantumCircuit(1) 22 qc.ry(x_param, 0) # Feature Encoding Layer: Ry(x) 23 qc.rz(w_param, 0) # Trainable Parameter Layer: Rz(w) 24 print('Qiskit Parameterized QML Circuit:') 25 print(qc.draw('text')) 26 27 # 3. Bind values and compute expectation value <Z> 28 observable = SparsePauliOp('Z') 29 bound_qc = qc.assign_parameters({x_param: 0.8, w_param: 1.5}) 30 state = Statevector.from_instruction(bound_qc) 31 expectation = state.expectation_value(observable).real 32 print(f'\nBound Parameters: x = 0.8, w = 1.5') 33 print(f'Quantum Model Prediction <Z>: {expectation:.4f}') 34 predicted_class = 1 if expectation > 0 else 0 35 print(f'Predicted Class: {predicted_class}')
Create symbolic parameters for features and weights using Qiskit Parameter.
Compose feature map and variational ansatz into a single QuantumCircuit.
Bind numerical values and calculate Pauli-Z expectation value to produce a model prediction.
Input feature x = 0.8, weight parameter w = 1.5.
Qiskit Parameterized QML Circuit: q_0: ──[ Ry(x_feature) ]──[ Rz(w_weight) ]── Prediction <Z>: ~0.6967 Predicted Class: 1
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.
Feature maps, ansatz, COBYLA optimization, and complete VQC pipeline.
Test your understanding with these questions. Remember, this is for learning, not examination!