Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Explore multi-qubit Quantum Neural Networks: Strongly Entangling Layers, Quantum Convolutional Neural Networks (QCNN), and Expressibility.
Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 8.9
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Number of QNN layers | Depth of parameterized transformations | |
| Parameterized single-qubit rotation | Rx, Ry, Rz gates acting as trainable synaptic weights | |
| Two-qubit entangling gates | Simulates multi-qubit synaptic connectivity between neighboring qubits | |
| Gradient variance across parameter space | Decays exponentially as in deep random circuits |
Comparing gradient variance decay between a small 4-qubit QNN and a larger 20-qubit QNN on a global observable:
Result: The 20-qubit network requires over 1 million shots per gradient step due to barren plateaus, demonstrating why local cost functions are essential.
Load input features via angle or amplitude encoding.
Apply 2-qubit unitary operators across neighboring qubit pairs.
Measure alternate qubits to reduce dimension by 50%.
Measure final surviving qubit to yield classification.
Problem: Classifying exotic phases of matter (Symmetry-Protected Topological phases) in condensed matter physics.
Solution: QCNNs classify topological order with 99%+ fidelity where classical neural networks fail.
Interactive activity component
Construct a Quantum Neural Network (QNN) layer in Qiskit with parameterized unitary transformations and observable expectation gradients.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install qiskit numpy1 from qiskit import QuantumCircuit 2 from qiskit.circuit import ParameterVector 3 from qiskit.quantum_info import Statevector, SparsePauliOp 4 import numpy as np
from qiskit import QuantumCircuit β Circuit constructor
from qiskit.circuit import ParameterVector β Parameter vector
from qiskit.quantum_info import Statevector, SparsePauliOp β Observables
import numpy as np β NumPy array support
1 # Construct a 2-qubit Quantum Neural Network layer 2 inputs = ParameterVector('input', 2) 3 weights = ParameterVector('weight', 4) 4 qc = QuantumCircuit(2) 5 # Feature encoding 6 qc.rx(inputs[0], 0) 7 qc.rx(inputs[1], 1) 8 # Neural entanglement block 9 qc.cz(0, 1) 10 qc.ry(weights[0], 0) 11 qc.ry(weights[1], 1) 12 qc.cz(0, 1) 13 qc.rz(weights[2], 0) 14 qc.rz(weights[3], 1) 15 print('Quantum Neural Network Layer Circuit:') 16 print(qc.draw('text')) 17 18 # Forward Pass: Evaluate <Z0> and <Z1> outputs 19 obs_z0 = SparsePauliOp('ZI') 20 obs_z1 = SparsePauliOp('IZ') 21 test_inputs = [0.5, -0.3] 22 test_weights = [0.8, 1.2, -0.5, 0.4] 23 bound = qc.assign_parameters({inputs: test_inputs, weights: test_weights}) 24 sv = Statevector.from_instruction(bound) 25 out0 = sv.expectation_value(obs_z0).real 26 out1 = sv.expectation_value(obs_z1).real 27 print(f'\nForward Pass Output Vector: [{out0:.4f}, {out1:.4f}]')
# Construct a 2-qubit Quantum Neural Network layer
QNN setup
inputs = ParameterVector('input', 2)
Input parameters
weights = ParameterVector('weight', 4)
Trainable parameters
qc = QuantumCircuit(2)
2 qubits
# Feature encoding
Encoding
qc.rx(inputs[0], 0)
Rx on wire 0
qc.rx(inputs[1], 1)
Rx on wire 1
# Neural entanglement block
Entanglement
qc.cz(0, 1)
CZ gate
qc.ry(weights[0], 0)
Ry weight on wire 0
qc.ry(weights[1], 1)
Ry weight on wire 1
qc.cz(0, 1)
CZ gate
qc.rz(weights[2], 0)
Rz weight on wire 0
qc.rz(weights[3], 1)
Rz weight on wire 1
print('Quantum Neural Network Layer Circuit:')
Diagram label
print(qc.draw('text'))
Print circuit
# Forward Pass: Evaluate <Z0> and <Z1> outputs
Forward pass
obs_z0 = SparsePauliOp('ZI')
Output neuron 0
obs_z1 = SparsePauliOp('IZ')
Output neuron 1
test_inputs = [0.5, -0.3]
Sample inputs
test_weights = [0.8, 1.2, -0.5, 0.4]
Sample weights
bound = qc.assign_parameters({inputs: test_inputs, weights: test_weights})
Bind parameters
sv = Statevector.from_instruction(bound)
Compute state
out0 = sv.expectation_value(obs_z0).real
Neuron 0 output
out1 = sv.expectation_value(obs_z1).real
Neuron 1 output
print(f'\nForward Pass Output Vector: [{out0:.4f}, {out1:.4f}]')
Display output neurons
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Implementing an Estimator QNN Layer in Qiskit 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install qiskit numpy 8 9 # Step 2: Import libraries 10 from qiskit import QuantumCircuit 11 from qiskit.circuit import ParameterVector 12 from qiskit.quantum_info import Statevector, SparsePauliOp 13 import numpy as np 14 15 # Step 3: Run Demonstration 16 # Construct a 2-qubit Quantum Neural Network layer 17 inputs = ParameterVector('input', 2) 18 weights = ParameterVector('weight', 4) 19 qc = QuantumCircuit(2) 20 # Feature encoding 21 qc.rx(inputs[0], 0) 22 qc.rx(inputs[1], 1) 23 # Neural entanglement block 24 qc.cz(0, 1) 25 qc.ry(weights[0], 0) 26 qc.ry(weights[1], 1) 27 qc.cz(0, 1) 28 qc.rz(weights[2], 0) 29 qc.rz(weights[3], 1) 30 print('Quantum Neural Network Layer Circuit:') 31 print(qc.draw('text')) 32 33 # Forward Pass: Evaluate <Z0> and <Z1> outputs 34 obs_z0 = SparsePauliOp('ZI') 35 obs_z1 = SparsePauliOp('IZ') 36 test_inputs = [0.5, -0.3] 37 test_weights = [0.8, 1.2, -0.5, 0.4] 38 bound = qc.assign_parameters({inputs: test_inputs, weights: test_weights}) 39 sv = Statevector.from_instruction(bound) 40 out0 = sv.expectation_value(obs_z0).real 41 out1 = sv.expectation_value(obs_z1).real 42 print(f'\nForward Pass Output Vector: [{out0:.4f}, {out1:.4f}]')
Map input neurons to rotational gates and output neurons to Pauli observables.
Connect qubits using multi-qubit gates representing quantum synapse interactions.
Extract continuous multi-neuron activation values in the range [-1.0, +1.0].
Inputs: [0.5, -0.3], Weights: [0.8, 1.2, -0.5, 0.4].
Quantum Neural Network Circuit: q_0: ββ[ Rx(input[0]) ]βββ ββ[ Ry(weight[0]) ]βββ ββ[ Rz(weight[2]) ]ββ Forward Pass Output Vector: [0.6841, -0.3412]
In a Quantum Neural Network (QNN), qubits serve as artificial quantum neurons, gates act as trainable synaptic weights, and measurement expectation values yield non-linear continuous activation values.
EstimatorQNN, TorchConnector, and hybrid PyTorch training.
Test your understanding with these questions. Remember, this is for learning, not examination!