PennyLaneAI / catalyst

A JIT compiler for hybrid quantum programs in PennyLane
https://docs.pennylane.ai/projects/catalyst
Apache License 2.0
122 stars 27 forks source link

Add a transform to split sums to QJITDevice preprocess #927

Closed lillian542 closed 1 month ago

lillian542 commented 1 month ago

Context: Some backends do not natively support sums of observables (e.g. qml.expval(X(0) + Y(1))).

This is already taken care of by the split_non_commuting transform if the backend in question also doesn't support non-commuting observables, but applying split_non_commuting to handle sums on for devices that support non-commuting measurements will result in unnecessarily splitting executions into multiple tapes.

Description of the Change: If split_non_commuting is not being added to the transform program already, and the device does not support sum observables, we add the transform split_to_single_terms, which splits the sums but leaves them all on a single tape. Supporting either Hamiltonian or Sum is taken to indicate support for summed observables.

lillian542 commented 1 month ago

[sc-60188] [sc-60187]

github-actions[bot] commented 1 month ago

Hello. You may have forgotten to update the changelog! Please edit doc/changelog.md on your branch with:

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.92%. Comparing base (1e5c6d6) to head (3444494).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #927 +/- ## ======================================= Coverage 97.92% 97.92% ======================================= Files 71 71 Lines 10246 10255 +9 Branches 1162 1163 +1 ======================================= + Hits 10033 10042 +9 Misses 169 169 Partials 44 44 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.