Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds GPU-backed phase encoding to QDP, complementing existing angle/IQP encoders, and validates behavior via new binding tests.
Changes:
- Introduces CUDA kernels for single-sample and batched phase encoding.
- Adds a Rust
PhaseEncoderimplementation (single + batch, including async pipeline path). - Extends encoder registry to expose
"phase"and adds pytest coverage for correctness, shape, and error cases.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| testing/qdp/test_bindings.py | Adds GPU tests validating phase encoding outputs, shapes, normalization, and errors. |
| qdp/qdp-kernels/src/phase.cu | Implements CUDA kernels + launchers for phase encoding (single + batch). |
| qdp/qdp-kernels/src/lib.rs | Exposes FFI bindings and non-CUDA stubs for phase encode launchers. |
| qdp/qdp-kernels/build.rs | Adds phase.cu to rebuild triggers and NVCC compilation list. |
| qdp/qdp-core/src/gpu/encodings/phase.rs | Adds PhaseEncoder with host input, batch, and async pipeline support. |
| qdp/qdp-core/src/gpu/encodings/mod.rs | Registers "phase" encoder and updates the unknown-encoder error message. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+471
to
+486
| let chunk_samples = chunk_len / sample_size; | ||
| let sample_offset = chunk_offset / sample_size; | ||
| let offset_elements = sample_offset.checked_mul(state_len).ok_or_else(|| { | ||
| MahoutError::InvalidInput("Phase batch output offset overflow".to_string()) | ||
| })?; | ||
|
|
||
| let state_ptr_offset = unsafe { state_ptr.add(offset_elements) as *mut c_void }; | ||
| let ret = unsafe { | ||
| qdp_kernels::launch_phase_encode_batch( | ||
| input_ptr, | ||
| state_ptr_offset, | ||
| chunk_samples, | ||
| state_len, | ||
| num_qubits as u32, | ||
| stream.stream as *mut c_void, | ||
| ) |
Comment on lines
+62
to
+66
| double norm = phase_norm(num_qubits); | ||
| double re, im; | ||
| sincos(phi, &im, &re); // re = cos(φ), im = sin(φ) | ||
|
|
||
| state[idx] = make_cuDoubleComplex(norm * re, norm * im); |
Comment on lines
+1313
to
+1317
| pytest.importorskip("torch") | ||
| from _qdp import QdpEngine | ||
|
|
||
| if not torch.cuda.is_available(): | ||
| pytest.skip("GPU required for QdpEngine") |
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.
Related Issues
Changes
Why
Phase encoding is a standard QML data encoding strategy, which is distinct from angle encoding (real-amplitude product state) and IQP encoding (entangled global-phase state).
How
Add
phase.cukernel implAdd
phase.rsencoderTest done
uv run pytest testing/qdp/test_bindings.py -k 'test_phase' -rFChecklist