PennyLaneAI / catalyst

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

Fix tracing of nested Adjoint/Controlled instances #1302

Closed dime10 closed 4 days ago

dime10 commented 1 week ago

Currently, Catalyst is not capturing the following correctly:

>>> qml.adjoint(qml.adjoint(qml.Gate(0)))
Adjoint(Adjoint(Gate(0)))

although the following does work:

>>> qml.adjoint(qml.adjoint(qml.Gate))(0)
HybridAdjoint(tapes=[[Adjoint(Gate(0))]])

The conversion from PennyLane operators to JAX primitives was not build with nesting in mind for Adjoint/Controlled, and instead relied on decomposing Adjoint(Adjoint(Gate)). In version 0.9, the acceptance criteria for decomposition was changed without accounting for the above.

The second example works because HybridAdjoint operators (used for generic callables that are not operators or operator constructors) are lowered as-is and can thus be arbitrarily nested.

Fixes #1301 [sc-78276]

codecov[bot] commented 5 days ago

Codecov Report

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

Project coverage is 81.39%. Comparing base (e3266de) to head (f442a71). Report is 5 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1302 +/- ## ======================================= Coverage 81.39% 81.39% ======================================= Files 74 74 Lines 8195 8195 Branches 858 858 ======================================= Hits 6670 6670 Misses 1468 1468 Partials 57 57 ```

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


🚨 Try these New Features: