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

`SProd.terms()` flattens out nested terms #5885

Open astralcai opened 1 week ago

astralcai commented 1 week ago

Context: The .terms() method of Sum, LinearCombination, Hamiltonian, Prod all flatten out any nested terms, but SProd does not. For examples:

>>> coeffs, ops = (2 * (qml.X(0) + qml.Y(0))).terms()
>>> len(ops)
1

Description of the Change: Make it so that SProd flattens out the terms.

Benefits: More consistent behaviour

[sc-66627]

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.66%. Comparing base (8fec135) to head (1f70de4). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5885 +/- ## ========================================== - Coverage 99.67% 99.66% -0.01% ========================================== Files 422 422 Lines 40651 40357 -294 ========================================== - Hits 40518 40223 -295 - Misses 133 134 +1 ```

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