Add QDP backend detection and pure-PyTorch reference implementations#1189
Open
ryankert01 wants to merge 4 commits intoapache:mainfrom
Open
Add QDP backend detection and pure-PyTorch reference implementations#1189ryankert01 wants to merge 4 commits intoapache:mainfrom
ryankert01 wants to merge 4 commits intoapache:mainfrom
Conversation
562e6c2 to
be21049
Compare
Member
Author
|
cc @viiccwen @vvvdwbvvv for review |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a pure-PyTorch reference implementation for QDP encoders plus backend detection/selection plumbing, enabling comparisons against the Rust+CUDA path and allowing parts of qumat_qdp to function when _qdp isn’t built.
Changes:
- Added PyTorch reference implementations for amplitude/angle/basis/IQP encodings with a string-based dispatcher.
- Introduced backend detection utilities and exposed backend info via
qumat_qdpexports; added explicit backend selection toQdpBenchmarkandQuantumDataLoader. - Added new tests for the PyTorch reference encoders and for behavior when
_qdpis unavailable; added a benchmark script supporting “encode-only” vs “end-to-end” modes.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
testing/qdp_python/test_torch_ref.py |
New unit tests for PyTorch reference encoders + optional cross-validation vs _qdp. |
testing/qdp_python/test_fallback.py |
Tests for backend detection and explicit PyTorch backend behavior when _qdp is missing. |
testing/conftest.py |
Adjusts skip logic so selected tests can run without _qdp. |
qdp/qdp-python/qumat_qdp/torch_ref.py |
Implements pure-PyTorch reference encoders and an encode() dispatcher. |
qdp/qdp-python/qumat_qdp/loader.py |
Adds explicit `.backend('rust' |
qdp/qdp-python/qumat_qdp/api.py |
Adds `.backend('rust' |
qdp/qdp-python/qumat_qdp/_backend.py |
Adds backend detection (Backend enum, get_backend, force_backend, get_qdp, get_torch). |
qdp/qdp-python/qumat_qdp/__init__.py |
Makes qumat_qdp importable without _qdp; exports BACKEND/Backend and safe _qdp symbols. |
qdp/qdp-python/benchmark/benchmark_pytorch_ref.py |
Adds benchmark script comparing PyTorch vs Mahout with --mode (encode-only/end-to-end). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
update at df90a6e |
9 tasks
Member
Author
|
I already implements the amplitude one and successfully increase the speed to slightly faster than |
- Implemented backend detection and selection logic in _backend.py, prioritizing Rust+CUDA, PyTorch, and fallback to None. - Added pure-PyTorch reference implementations for quantum data encoding methods in torch_ref.py, including amplitude, angle, basis, and IQP encoding. - Created comprehensive tests for fallback mechanisms and pure-PyTorch encodings in test_fallback.py and test_torch_ref.py, ensuring functionality without the Rust extension. - Enhanced error handling and validation across encoding methods to ensure robustness.
df90a6e to
d814d7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1177
Summary
This PR adds a pure-PyTorch reference backend to the QDP Python package to compare with our implementation of GPU kernel~
Benchmark Results
All runs: 100 batches x 64 vectors (except 18-qubit: 50 batches x 64), median of 3 trials.
Amplitude Encoding
Angle Encoding
IQP Encoding
Analysis
encodepath still pays per-batch GPU output allocation + D2H norm validation sync overhead.generate_batch_data+torch.tensor+ H2D transfer.Known Limitations
engine.encodeexpects per-sample basis indices; batch input format differs from PyTorch. Requires Rust API change to support.1 << num_qubitsas sample_size regardless of encoding method, causing a mismatch for IQP (which expectsn + n*(n-1)/2). Pre-existing Rust pipeline bug.