Skip to content

Commit 520d4d0

Browse files
QCNN implementation for version 0.1.11
1 parent cfa68b7 commit 520d4d0

16 files changed

+1053
-6
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# CHANGELOG.md
22

3+
## [0.1.11] - 10-04-2026
4+
5+
### Added
6+
7+
- Implemented a first-class QCNN workflow in `qml.qcnn`
8+
- Added `qcnn` CLI support via `python -m qml qcnn`
9+
- Added QCNN benchmark support in classification benchmarks
10+
- Added QCNN smoke, CLI, benchmark, and import coverage
11+
- Added QCNN documentation across README, usage docs, theory notes, and a dedicated algorithm page
12+
- Added QCNN example notebook: `notebooks/quantum_convolutional_neural_network.ipynb`
13+
14+
### Summary
15+
16+
New core QML capability:
17+
18+
- variational quantum classification (VQC)
19+
- variational quantum regression (VQR)
20+
- quantum convolutional neural networks (QCNN)
21+
- quantum kernel methods
22+
- trainable quantum kernels
23+
- quantum metric learning
24+
25+
---
26+
327
## [0.1.10] - 10-04-2026
428

529
### Fixed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Modular **PennyLane-based quantum machine learning library** implementing reusab
1010

1111
• Variational quantum classification (VQC)
1212
• Variational quantum regression (VQR)
13+
• Quantum convolutional neural networks (QCNN)
1314
• Quantum kernel methods
1415
• Trainable quantum kernels (kernel-target alignment)
1516
• Quantum metric learning (trainable embedding geometry)
@@ -82,6 +83,26 @@ result = run_vqr(
8283

8384
---
8485

86+
## Quantum convolutional neural network
87+
88+
```python
89+
from qml.qcnn import run_qcnn
90+
91+
result = run_qcnn(
92+
n_samples=200,
93+
steps=50,
94+
plot=True,
95+
)
96+
```
97+
98+
Learns a small hierarchical quantum classifier using:
99+
100+
• trainable data embedding across four qubits
101+
• shared convolution-style two-qubit blocks
102+
• pooling-style entangling reductions before final readout
103+
104+
---
105+
85106
## Quantum kernel classifier
86107

87108
```python
@@ -184,6 +205,7 @@ from qml.benchmarks import compare_classification_models
184205
result = compare_classification_models(
185206
models=[
186207
"vqc",
208+
"qcnn",
187209
"quantum_kernel",
188210
"trainable_quantum_kernel",
189211
"logistic_regression",
@@ -203,6 +225,7 @@ Benchmarks accept per-model kwargs:
203225
result = compare_classification_models(
204226
models=[
205227
"vqc",
228+
"qcnn",
206229
"quantum_kernel",
207230
"trainable_quantum_kernel",
208231
],
@@ -243,6 +266,7 @@ Run workflows directly:
243266

244267
```bash
245268
python -m qml vqc --steps 50 --plot
269+
python -m qml qcnn --steps 50 --plot
246270
python -m qml regression --steps 50 --plot
247271
python -m qml kernel --plot
248272
python -m qml trainable-kernel --steps 50 --plot
@@ -253,7 +277,7 @@ Run benchmarks:
253277

254278
```bash
255279
python -m qml benchmark classification \
256-
--models vqc quantum_kernel svm_classifier logistic_regression \
280+
--models vqc qcnn quantum_kernel svm_classifier logistic_regression \
257281
--seeds 123 456
258282
```
259283

@@ -283,13 +307,17 @@ Algorithm notes:
283307

284308
• docs/qml/variational_quantum_classifier.md
285309
• docs/qml/variational_regression.md
310+
• docs/qml/qcnn.md
286311
• docs/qml/quantum_kernels.md
312+
• docs/qml/metric_learning.md
287313

288314
Example notebooks:
289315

290316
• quantum_variational_classifier.ipynb
291317
• quantum_regressor.ipynb
318+
• quantum_convolutional_neural_network.ipynb
292319
• quantum_kernel_classifier.ipynb
320+
• quantum_metric_learning.ipynb
293321
• classical_vs_quantum_classifier.ipynb
294322

295323
---
@@ -311,6 +339,9 @@ qml/
311339
regression.py
312340
variational quantum regression workflows
313341
342+
qcnn.py
343+
quantum convolutional classifier workflows
344+
314345
kernel_methods.py
315346
quantum kernel workflows
316347

THEORY.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,69 @@ Alignment encourages kernel similarity to reflect class structure.
492492

493493
---
494494

495+
# Quantum convolutional neural networks
496+
497+
Quantum convolutional neural networks use a hierarchical circuit structure to
498+
combine local feature extraction with progressive reduction of the active
499+
degrees of freedom.
500+
501+
A QCNN alternates:
502+
503+
• convolution-style local two-qubit blocks
504+
• pooling-style entangling reductions
505+
• a final readout on a reduced register
506+
507+
In the implementation used here, the classifier applies a trainable embedding
508+
on four qubits, followed by shared convolution blocks on neighbouring pairs,
509+
then a second-stage convolution on the pooled representation.
510+
511+
---
512+
513+
## Hierarchical structure
514+
515+
Let the initial embedded state be
516+
517+
$$
518+
|\phi(x, \theta_{\mathrm{emb}})\rangle.
519+
$$
520+
521+
The QCNN transforms it as
522+
523+
$$
524+
|\psi(x, \theta)\rangle
525+
=
526+
U_{\mathrm{dense}}
527+
U_{\mathrm{conv},2}
528+
U_{\mathrm{pool}}
529+
U_{\mathrm{conv},1}
530+
|\phi(x, \theta_{\mathrm{emb}})\rangle.
531+
$$
532+
533+
This differs from a flat variational classifier because information is processed
534+
through successive local blocks rather than a repeated global ansatz layer.
535+
536+
---
537+
538+
## Binary classification readout
539+
540+
The final prediction is obtained from a Pauli-$Z$ expectation on the readout qubit:
541+
542+
$$
543+
s(x, \theta) = \langle Z \rangle.
544+
$$
545+
546+
This is mapped to a class probability by
547+
548+
$$
549+
p(y=1 \mid x, \theta)
550+
=
551+
\frac{1 - s(x, \theta)}{2}.
552+
$$
553+
554+
Training then minimizes binary cross-entropy over the dataset.
555+
556+
---
557+
495558
# Quantum metric learning
496559

497560
Quantum metric learning aims to learn an embedding geometry in which distances between samples reflect label similarity.

USAGE.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,83 @@ result = run_vqr(
156156

157157
---
158158

159+
# Quantum convolutional neural network (QCNN)
160+
161+
Train a hierarchical quantum classifier on a synthetic dataset:
162+
163+
```python
164+
from qml.qcnn import run_qcnn
165+
166+
result = run_qcnn(
167+
n_samples=200,
168+
noise=0.1,
169+
test_size=0.25,
170+
seed=123,
171+
steps=50,
172+
step_size=0.1,
173+
plot=True,
174+
save=False,
175+
)
176+
```
177+
178+
---
179+
180+
## Parameters
181+
182+
| parameter | description | default |
183+
| --------- | ----------- | ------- |
184+
| n_samples | dataset size | 200 |
185+
| noise | dataset noise level | 0.1 |
186+
| test_size | test fraction | 0.25 |
187+
| seed | random seed | 123 |
188+
| steps | optimisation steps | 50 |
189+
| step_size | Adam learning rate | 0.1 |
190+
| shots | finite-shot sampling | None |
191+
| plot | show plots | False |
192+
| save | save JSON + plots | False |
193+
194+
---
195+
196+
## Returned dictionary
197+
198+
Typical fields:
199+
200+
```python
201+
{
202+
"model",
203+
"dataset",
204+
205+
"seed",
206+
207+
"n_qubits",
208+
209+
"steps",
210+
"step_size",
211+
212+
"loss_history",
213+
214+
"train_accuracy",
215+
"test_accuracy",
216+
217+
"params",
218+
"embedding_params",
219+
"conv1_params",
220+
"conv2_params",
221+
"dense_params",
222+
223+
"y_train",
224+
"y_test",
225+
226+
"y_train_pred",
227+
"y_test_pred",
228+
229+
"train_probabilities",
230+
"test_probabilities",
231+
}
232+
```
233+
234+
---
235+
159236
# Quantum kernel classifier
160237

161238
Compute a quantum kernel matrix and train an SVM:
@@ -423,6 +500,7 @@ from qml.benchmarks import compare_classification_models
423500
result = compare_classification_models(
424501
models=[
425502
"vqc",
503+
"qcnn",
426504
"quantum_kernel",
427505
"trainable_quantum_kernel",
428506
"logistic_regression",
@@ -465,6 +543,7 @@ result = compare_classification_models(
465543

466544
models=[
467545
"vqc",
546+
"qcnn",
468547
"quantum_kernel",
469548
"trainable_quantum_kernel",
470549
],
@@ -502,6 +581,8 @@ Run workflows directly:
502581
```bash
503582
python -m qml vqc --steps 50 --plot
504583

584+
python -m qml qcnn --steps 50 --plot
585+
505586
python -m qml regression --steps 50 --plot
506587

507588
python -m qml kernel --plot
@@ -519,7 +600,7 @@ Classification:
519600

520601
```bash
521602
python -m qml benchmark classification \
522-
--models vqc quantum_kernel logistic_regression svm_classifier \
603+
--models vqc qcnn quantum_kernel logistic_regression svm_classifier \
523604
--seeds 123 456
524605
```
525606

docs/qml/benchmarks.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Compare multiple classifiers on the same dataset.
4242
Supported models:
4343

4444
- `vqc`
45+
- `qcnn`
4546
- `quantum_kernel`
4647
- `logistic_regression`
4748
- `svm_classifier`
@@ -53,7 +54,7 @@ Example:
5354
from qml.benchmarks import compare_classification_models
5455

5556
result = compare_classification_models(
56-
models=["vqc", "quantum_kernel", "svm_classifier"],
57+
models=["vqc", "qcnn", "quantum_kernel", "svm_classifier"],
5758
seeds=[0, 1, 2, 3],
5859
n_samples=200,
5960
noise=0.1,
@@ -153,7 +154,7 @@ Classification benchmark:
153154

154155
```bash
155156
python -m qml benchmark classification \
156-
--models vqc quantum_kernel svm_classifier logistic_regression \
157+
--models vqc qcnn quantum_kernel svm_classifier logistic_regression \
157158
--seeds 123 456 789
158159
```
159160

@@ -215,6 +216,7 @@ Classification:
215216

216217
```
217218
vqc
219+
qcnn
218220
quantum_kernel
219221
logistic_regression
220222
svm_classifier
@@ -272,6 +274,7 @@ Benchmark utilities call the following workflows:
272274
Classification:
273275

274276
- `qml.classifiers.run_vqc`
277+
- `qml.qcnn.run_qcnn`
275278
- `qml.kernel_methods.run_quantum_kernel_classifier`
276279
- `qml.classical_baselines.run_logistic_classifier`
277280
- `qml.classical_baselines.run_svm_classifier`

0 commit comments

Comments
 (0)