Skip to content

Conversation

@JerryChen97
Copy link
Contributor

@JerryChen97 JerryChen97 commented Sep 11, 2025

Context:
Previously, the default.tensor device did not integrate with the new graph-based decomposition system introduced in PennyLane. This system allows for more intelligent circuit compilation by selecting the best decomposition strategy based on available hardware resources (e.g., choosing a gate implementation that doesn't require extra "work" wires if the device has none to spare). This PR updates the device's preprocessing pipeline to leverage this new, more efficient decomposition logic.

Description of the Change:

  • Enabled Graph Decomposition: Modified default_tensor.py to correctly configure and include the graph decomposition transform in its preprocessing pipeline. This involves passing necessary device information, like device_wires and target_gates, to the decompose function.
  • Added Comprehensive Tests: Introduced a new test class, TestPreprocessingTransforms, to validate the structure and behavior of the updated preprocessing pipeline. These tests ensure that:
    • The decompose transform is correctly included in the pipeline.
    • It receives the correct device_wires and target_gates.
    • The device works end-to-end with QNodes containing operations that require decomposition.
  • Integration with New Fixture: Updated existing tests to use the new @pytest.mark.usefixtures("enable_and_disable_graph_decomp") fixture, ensuring they run with both the old and new decomposition methods for backward compatibility and robustness.

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-97955] [sc-97952]

JerryChen97 and others added 22 commits September 9, 2025 10:46
This commit refactors the preprocess.decompose function to improve its integration
with the new graph-based decomposition system and adds support for device-specific
parameters.

Key Changes:
- Enhanced decompose() function to accept device_wires and target_gates parameters
- Improved work wire calculation using set operations: len(set(device_wires) - set(tape.wires))
- Removed redundant num_available_work_wires and graph_solution parameters (computed internally)
- Added preprocess_decompose_plxpr_to_plxpr function for PLXPR integration
- Updated function signature and internal logic for better parameter handling

Testing:
- Added comprehensive test coverage for new device_wires and target_gates functionality
- Added parametrized tests for work wire calculation with various edge cases
- Added fixtures for graph decomposition backward compatibility testing
- Used spy-based testing for safe parameter verification without mocking core functionality

Code Quality:
- Added __all__ export list for proper module interface definition
- Fixed pylint warnings and ensured CI/CD compatibility
- Improved exception handling with explicit re-raising patterns
- Enhanced imports and dependencies for graph-based decomposition

Backward Compatibility:
- Maintained full backward compatibility for existing decompose() calls
- Legacy behavior preserved when device_wires/target_gates not provided
- Comprehensive fixture-based testing ensures both old and new modes work correctly
@JerryChen97 JerryChen97 marked this pull request as ready for review September 11, 2025 21:28
@codecov
Copy link

codecov bot commented Sep 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (61ba7c3) to head (d5c43f3).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8253      +/-   ##
==========================================
- Coverage   99.39%   99.39%   -0.01%     
==========================================
  Files         558      558              
  Lines       57781    57781              
==========================================
- Hits        57432    57431       -1     
- Misses        349      350       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JerryChen97 JerryChen97 self-assigned this Sep 12, 2025
@JerryChen97 JerryChen97 requested a review from albi3ro September 12, 2025 15:51
@JerryChen97
Copy link
Contributor Author

NQ part has been spawn at #8260

@JerryChen97 JerryChen97 requested a review from albi3ro September 12, 2025 18:44
@JerryChen97 JerryChen97 changed the title New decomp integration/default tensor default.tensor can preprocess with graph based decomposition system Sep 17, 2025
@JerryChen97
Copy link
Contributor Author

@astralcai

@JerryChen97 JerryChen97 added this pull request to the merge queue Sep 18, 2025
Merged via the queue into master with commit 6ce2780 Sep 18, 2025
52 checks passed
@JerryChen97 JerryChen97 deleted the new-decomp-integration/default-tensor branch September 18, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants