-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CancelInversesInterpreter
for transforming plxpr
#6692
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6692 +/- ##
========================================
Coverage 99.62% 99.62%
========================================
Files 476 478 +2
Lines 44733 44973 +240
========================================
+ Hits 44564 44804 +240
Misses 169 169 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good!
One question from me. Why isn't the operation canceled if I have a nested adjoint operation? Something like:
@CancelInversesInterpreter()
def f():
qml.adjoint(qml.adjoint(qml.adjoint(qml.PauliX(0))))
qml.PauliX(0)
>>> jaxpr = jax.make_jaxpr(f)()
{ lambda ; . let
a:AbstractOperator() = PauliX[n_wires=1] 0
b:AbstractOperator() = Adjoint a
c:AbstractOperator() = Adjoint b
_:AbstractOperator() = Adjoint c
_:AbstractOperator() = PauliX[n_wires=1] 0
in () }
If this is too much trouble to implement I am perfectly fine with postponing nested adjoint operators : )
@PietropaoloFrisoni the same also doesn't work with program capture disabled: >>> print(qml.transforms.cancel_inverses(qml.tape.QuantumScript([qml.X(0), qml.adjoint(qml.adjoint(qml.adjoint(qml.X(0))))]))[0][0].circuit)
[X(0), Adjoint(Adjoint(Adjoint(X(0))))] There are many cases in which |
@mudit2812 I agree. This can probably be fixed automatically by ensuring that the adjoint of an adjoint operator returns the operator itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Co-authored-by: Pietropaolo Frisoni <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
[sc-72846]
Context:
This PR adds a
CancelInversesInterpreter
to apply thecancel_inverses
transform natively to plxpr.Description of the Change:
CancelInversesInterpreter
to transform plxprBenefits:
cancel_inverses
can be applied natively to plxpr.Possible Drawbacks:
Potential operator reordering may confuse users.
Related GitHub Issues: