PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.17k stars 568 forks source link

Bugfix for split_non_commuting when tape measurements is empty #5869

Closed lillian542 closed 1 week ago

lillian542 commented 1 week ago

Context: Currently on master, if we apply split_non_commuting to a tape with empty measurements, we delete the tape:

>>> from pennylane.transforms import split_non_commuting
>>> tape = qml.tape.QuantumScript([qml.X(0)], measurements=[])
>>> tapes, _ = split_non_commuting(tape)
>>> tapes
[]

Description of the Change:

We add a check for len(measurements) == 0 and just return the tape if there are no measurements to split, so we get:

>>> from pennylane.transforms import split_non_commuting
>>> tape = qml.tape.QuantumScript([qml.X(0)], measurements=[])
>>> tapes, _ = split_non_commuting(tape)
>>> tapes
[<QuantumScript: wires=[0], params=0>]

Benefits: We don't delete the tape if it has no measurements (came up in catalyst tests)

github-actions[bot] commented 1 week ago

Hello. You may have forgotten to update the changelog! Please edit doc/releases/changelog-dev.md with:

codecov[bot] commented 1 week ago

Codecov Report

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

Project coverage is 99.67%. Comparing base (fb06ce8) to head (2b569d0).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5869 +/- ## ========================================== - Coverage 99.68% 99.67% -0.01% ========================================== Files 421 421 Lines 40457 40165 -292 ========================================== - Hits 40328 40035 -293 - Misses 129 130 +1 ```

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

lillian542 commented 1 week ago

[sc-60186]

lillian542 commented 1 week ago

Edit: wrong story ID [sc-60187]

lillian542 commented 1 week ago

[sc-60188]