[Feature][QDP] One encode path across Python, Rust and CUDA (tracking)
Maintainers usually reply within 2 days
@ryankert01 is already working on this.
Since Sep 9, 2026.
Assessment
This issue has not been assessed yet.
Description
TL;DR
Adding one encoding to QDP today means writing it three times: a CUDA host launcher plus extern "C" declaration plus no-CUDA stub, an 8-method Rust encoder (f32/f64 × single/batch × host/device), and a hand-matched PyO3 branch. #1268 added one f32 variant of angle encoding and touched 9 files across 2 languages for 1,135 lines.
I refactored this so an encoding is one device-only .cu file, one ~80-line Rust descriptor, and one PyTorch reference function. The data-movement engine (dual-stream pinned upload, prefetch, buffer pool, DLPack) is untouched, the public Python API is unchanged, and the repo's standard benchmarks show no measurable throughput or latency change.
What
Six commits on a branch, each independently green (Rust tests, clippy, no-CUDA build, Python suites including a new parity grid). I'll open them as PRs against this issue:
- Parity grid + baseline tool — one test over encoding × precision × shape × input location against
torch_ref.py(which now covers phase);benchmark/baseline.pycaptures and compares throughput/latency with a threshold. - Runtime kernel loading —
build.rscompiles each.cuto a device-only fatbin and embeds it;qdp_kernels::registryloads through the CUDA driver API on first use and exposes one genericlaunch+kernel_args!. A test proves every embedded symbol resolves. - Encoder collapse — a
Kerneltrait with a singlelaunchon device-resident data,Input(host slice or device pointer on a stream), andQdpEngine::encode(input, shape, num_qubits, encoding)replacing 24 named methods (old names kept as one-line shorthands incompat.rs). Bindings becomePyInput::from_py+ one call. - Host-path fixes found while benchmarking (amplitude CPU finite pass, basis device cast).
- Remove launchers — 26 host launchers, 26 declarations, 26 stubs, the static nvcc compile and the
ccdependency are gone. - Docs — DEVELOPMENT.md architecture section, a "which files do I touch" table, the three-file recipe,
make check-kernels,make parity.
| Surface | Before | After |
|---|---|---|
CUDA host launchers / extern "C" decls / no-CUDA stubs |
26 / 26 / 26 | 0 |
qdp-kernels/src/lib.rs |
726 lines | 57 lines |
| CUDA sources (device code only after) | 2,633 lines | 1,434 lines |
| Encoder trait methods per encoding | 8 | 1 |
| Angle encoder | 868 lines | 89 lines |
Public encode* methods on QdpEngine |
24 | 1 (+ shorthands) |
| PyO3 engine methods | 11 | 6 |
| Encodings that stream from Parquet | 3 | 6 |
| Encodings that read a CUDA tensor in place | 5 | 6 |
Net: 62 files, +4,334 / −9,974 lines. Bonus behaviour: phase now encodes from CUDA tensors, basis accepts float64 CUDA tensors, streaming Parquet works for all six encodings, NumPy float32 input is accepted.
Why
Contributors should be able to add or tune an encoding knowing CUDA and a little Rust, add a reader knowing Rust, and add a loader feature knowing Python. Today every encoder change needs all three, and the FFI signatures are matched by eye (a mismatch is UB, not a compile error).
How
Performance. Old (pre-refactor commit) vs new, built into separate venvs, run with benchmark_throughput.py, benchmark_latency.py and benchmark_e2e.py at their default arguments, 5 alternating rounds on an idle RTX 6000 Ada. Medians, with new/old ratio:
| Encoding | Throughput old → new (vec/s) | Latency old → new (ms/vec) |
|---|---|---|
| amplitude | 12,660 → 5,667 (0.45, see below) | 0.096 → 0.097 (1.01) |
| angle | 23,110 → 22,993 (0.99) | 0.043 → 0.044 (1.02) |
| basis | 68,651 → 77,569 (1.13) | 0.013 → 0.015 (1.15) |
| iqp | 22,140 → 22,045 (1.00) | 0.046 → 0.045 (0.98) |
| iqp-z | 49,597 → 51,432 (1.04) | 0.020 → 0.020 (1.00) |
The amplitude throughput row is benchmark noise, not code: that benchmark alternates between ~11k and ~5.5k vec/s on consecutive runs of the same build (old: 10,563 5,665 11,367 5,694 11,434 5,606; new: 5,973 12,592 5,761 10,385 5,569 5,390). Amplitude latency on the same workload is identical, and an nsys trace shows the three amplitude kernels at the same grid and the same time on both builds (69.0 / 29.7 / 2.5 µs per batch), with the batch dominated by the pageable 16 MB host copy. Per-call amplitude encode, interleaved: 3.73 vs 3.76 ms and 3.60 vs 3.71 ms.
Behaviour changes to note in review
- Parquet streaming now honours engine precision (previously always complex128).
- Error message wording was preserved where tests asserted it.
Follow-ups (separate issues once this lands)
- Delete the
compat.rsshorthands once callers useencode. - Delete the now-unused single-sample kernels from the
.cufiles. - Consider pinned producer buffers: the amplitude pipeline is bound by a pageable host copy per batch, not by kernels.
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 1k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 7
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/mahout
-
[Bug] Amazon Braket get_final_state_vector() changes the circuit, so execute_circuit() fails afterwardsPossibly taken @Howardisme claimed this 48 days ago. Openbug enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
apache/mahout#1538 · 1 comment ·
Maintainers usually reply within 2 days
-
[Bug] Reusing a parameter name on two gates fails on Qiskit only (name conflict adding parameter)Possibly taken @Imad2702 claimed this 50 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/mahout#1509 · 2 comments ·
Maintainers usually reply within 2 days
-
[Bug] Cirq backend ignores the initialized simulator and creates its own cirq.Simulator()Possibly taken @Howardisme claimed this 49 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
apache/mahout#1508 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug] Unknown backend_name leaks ModuleNotFoundError instead of a clear ValueErrorPossibly taken @Asterisk-Hunter claimed this 38 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
apache/mahout#1506 · 5 comments ·
Maintainers usually reply within 2 days
-
bug docs enhancement question
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 2 days
Similar issues
-
chat compiler P1
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
HerringtonDarkholme/hd-lang#2793 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
security-advisory
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MinBZK/regelrecht#2173 ·
-
ci
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jonathanong/no-mistakes#5804 ·
-
triage: failed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
oxc-project/tsrs#1277 · 1 comment ·
Maintainers usually reply within 1 day