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

Disallow taking the adjoint of fractional power operations #5835

Closed dwierichs closed 2 weeks ago

dwierichs commented 2 weeks ago

Context: The adjoint of an integer power of an operator is the same power of the adjoint of the operator. For fractional powers, this does not hold because of branch cuts in the power function.

Description of the Change: This PR explicitly disallows computing the (eager) adjoint of a Pow operator with fractional power, and raises an AdjointUndefinedError in this case.

As a tiny side effect, this PR changes the signature of Identity.pow to be compatible with generalized simplification workflows where the keyword argument z for the power is passed around explicitly (this popped up in a simplification test of Pow)

NB: As usual, a lazy Adjoint(Pow(base, z=0.2)) is still supported, just can't be evaluated/simplified if that would lead to calling the method adjoint of Pow.

Benefits:

Possible Drawbacks:

Related GitHub Issues: Fixes #5812

[sc-65297]

github-actions[bot] commented 2 weeks ago

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

codecov[bot] commented 2 weeks ago

Codecov Report

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

Project coverage is 99.67%. Comparing base (45f8d4a) to head (cd09001).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #5835 +/- ## ========================================== - Coverage 99.68% 99.67% -0.01% ========================================== Files 420 420 Lines 40138 39847 -291 ========================================== - Hits 40010 39717 -293 - Misses 128 130 +2 ```

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