Skip to content

Commit d7cf2c3

Browse files
authored
Align Iris amplitude encoding benchmark between PennyLane and QDP (#1088)
1 parent bdc1a7b commit d7cf2c3

File tree

3 files changed

+969
-0
lines changed

3 files changed

+969
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Encoding benchmarks
2+
3+
This directory is used to **compare a pure PennyLane baseline with a QDP pipeline on the full training loop**.
4+
Both scripts use the same dataset and the same variational model; **only the encoding step is different**.
5+
6+
- **`pennylane_baseline/`**: pure PennyLane (sklearn / official Iris file → encoding → variational classifier).
7+
- **`qdp_pipeline/`**: same data and model, but encoding is done via the QDP `QuantumDataLoader` (amplitude).
8+
9+
Run all commands from the `qdp-python` directory:
10+
11+
```bash
12+
cd qdp/qdp-python
13+
```
14+
15+
## Environment (one-time setup)
16+
17+
```bash
18+
uv sync --group benchmark # install PennyLane, torch(+CUDA), scikit-learn, etc.
19+
uv run maturin develop # build QDP Python extension (qumat_qdp)
20+
```
21+
22+
If your CUDA driver is not 12.6, adjust the PyTorch index URL in `pyproject.toml` according to the comments there.
23+
24+
## Iris amplitude baseline (pure PennyLane)
25+
26+
Pipeline: 2-class Iris (sklearn or official file) → L2 normalize → `get_angles` → variational classifier.
27+
28+
```bash
29+
uv run python benchmark/encoding_benchmarks/pennylane_baseline/iris_amplitude.py
30+
```
31+
32+
Common flags (only the key ones):
33+
34+
- `--iters`: optimizer steps (default: 1500)
35+
- `--layers`: number of variational layers (default: 10)
36+
- `--lr`: learning rate (default: 0.08)
37+
- `--optimizer`: `adam` or `nesterov` (default: `adam`)
38+
- `--trials`: number of restarts; best test accuracy reported (default: 20)
39+
- `--data-file`: use the official Iris file instead of sklearn (2 features, 75% train)
40+
41+
Example (official file + Nesterov + short run):
42+
43+
```bash
44+
uv run python benchmark/encoding_benchmarks/pennylane_baseline/iris_amplitude.py \
45+
--data-file benchmark/encoding_benchmarks/pennylane_baseline/data/iris_classes1and2_scaled.txt \
46+
--optimizer nesterov --lr 0.01 --layers 6 --trials 3 --iters 80 --early-stop 0
47+
```
48+
49+
## Iris amplitude (QDP pipeline)
50+
51+
Pipeline is identical to the baseline except for encoding:
52+
4-D vectors → QDP `QuantumDataLoader` (amplitude) → `StatePrep(state_vector)` → same variational classifier.
53+
54+
```bash
55+
uv run python benchmark/encoding_benchmarks/qdp_pipeline/iris_amplitude.py
56+
```
57+
58+
The CLI mirrors the baseline, plus:
59+
60+
- **QDP-specific flags**
61+
- `--device-id`: QDP device id (default: 0)
62+
- `--data-dir`: directory for temporary `.npy` files (default: system temp directory)
63+
64+
Example (same settings as the baseline example, but with QDP encoding):
65+
66+
```bash
67+
uv run python benchmark/encoding_benchmarks/qdp_pipeline/iris_amplitude.py \
68+
--data-file benchmark/encoding_benchmarks/pennylane_baseline/data/iris_classes1and2_scaled.txt \
69+
--optimizer nesterov --lr 0.01 --layers 6 --trials 3 --iters 80 --early-stop 0
70+
```
71+
72+
To see the full list of options and defaults, append `--help`:
73+
74+
```bash
75+
uv run python benchmark/encoding_benchmarks/pennylane_baseline/iris_amplitude.py --help
76+
uv run python benchmark/encoding_benchmarks/qdp_pipeline/iris_amplitude.py --help
77+
```

0 commit comments

Comments
 (0)