PennyLaneAI / catalyst

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

Check `op.has_matrix` before decomposing unsupported gates to QubitUnitary #831

Closed maliasadi closed 3 months ago

maliasadi commented 3 months ago

Before submitting

Please complete the following checklist when submitting a PR:

When all the above are checked, delete everything above the dashed line and fill in the pull request template.


Context: We currently don't check if an unsupported controlled operation has a matrix and always prefer applying the operation as a QubitUnitary over PL's decomposition rules. As the result applying the controlled operations like TrotterProduct is not supported in Catalyst. This PR fixes the issue by checking operation.has_matrix before trying to generate & use the unitary matrix.

Description of the Change:

Benefits: Support control of gates without matrix. For example, QJIT compiling ctrl(TrotterProduct) would throw the following compiler error without the proposed patch:

E           catalyst.utils.exceptions.CompileError: Operation Controlled(TrotterProduct(0.25, 0.75, 2.4, wires=[0]), control_wires=[1]) could not be decomposed, it might be unsupported.

Possible Drawbacks:

Related GitHub Issues: [sc-66427]

codecov[bot] commented 3 months ago

Codecov Report

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

Project coverage is 97.96%. Comparing base (76df3f7) to head (2d611ba). Report is 203 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #831 +/- ## ======================================= Coverage 97.95% 97.96% ======================================= Files 71 71 Lines 10248 10248 Branches 903 903 ======================================= + Hits 10038 10039 +1 Misses 167 167 + Partials 43 42 -1 ```

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