-
Notifications
You must be signed in to change notification settings - Fork 975
[QDP] Refactor encode() method into helper functions with tests
#814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QDP] Refactor encode() method into helper functions with tests
#814
Conversation
encode() method into helper functions with tests
|
cc @400Ping, @guan404ming 🙌 |
|
Please resolve conflicts |
|
plz resolve the pre-commit error |
|
please resolve the conflict and re-think the solution with newly introduced testing refactor if needed |
Sure, I'll kick off today or tomorrow! |
|
Hey @viiccwen, how this going? Feel free let me know if you need any help. Thanks! |
|
replying here!
Edit: bcz this file updated frequently. |
|
Make sense, thanks. |
ryankert01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to resolve conflicts
- Introduced dedicated methods `encode_from_numpy` and `encode_from_pytorch` to streamline the encoding process for NumPy arrays and PyTorch tensors, respectively. - Improved error handling for unsupported shapes in both encoding methods. - Simplified the main encoding logic by delegating to these new methods.
Replace deprecated PyReadonlyArrayDyn with dimension-specific types PyReadonlyArray1 and PyReadonlyArray2 for better type safety and compatibility with newer pyo3-numpy versions.
496fb7c to
5a22fa0
Compare
rich7420
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viiccwen thanks for the update!
Tests all passed locally.
left some comments:
| /// CUDA device ID from DLPack metadata. | ||
| /// Currently unused but kept for potential future device validation or multi-GPU support. | ||
| #[allow(dead_code)] | ||
| device_id: i32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a dead code but may be used in the future.
I think maybe we could add a defensive assertion to verify DLPack device_id matches the validated device_id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it could be a follow-up. WDYT?
bcz this PR only deals with refactoring encode path & adding missing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem, plz open a issue.
|
another conflict 💀 |
|
Thanks for reviewing! 🙌 |
Purpose of PR
Refactor
QdpEngine.encode()method to improve code maintainability and readability by splitting the monolithic 150+ line method into smaller and focused helper methods.This PR also adds/refactors tests to ensure all adjust code paths are covered.
Related Issues or PRs
comment
Changes Made
Breaking Changes
Detailed Changes
Code Refactoring (
src/lib.rs)Split
encode()method into focused helper methods:encode_from_numpy()- Handles NumPy array input (1D and 2D)encode_from_pytorch()- Handles PyTorch tensor input (1D and 2D)encode_from_list()- Handles Python list inputencode()method now acts as a router, delegating to appropriate handlersBenefits:
Test Improvements (
tests/test_bindings.py)Added 3 tests for refactored paths:
test_encode_numpy_array()- Tests NumPy array encoding (1D and 2D)test_encode_pytorch_tensor()- Tests PyTorch tensor encoding (1D and 2D)test_encode_pathlib_path()- Testspathlib.Pathobject inputCode quality improvements:
TEST_DATA_1D,NUM_QUBITS,SAMPLE_SIZE)engine,engine_float64) to reduce duplicationTesting
Checklist