PennyLaneAI / catalyst

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

Introduce folding argument in ZNE mitigation #946

Closed cosenal closed 1 month ago

cosenal commented 1 month ago

Context: We'd like to extend Zero-noise extrapolation (ZNE) with different folding techniques. For more details, see #755 and https://mitiq.readthedocs.io/en/stable/guide/zne-3-options.html#unitary-folding.

Description of the Change: In this PR a folding argument is added both to the ZNE mitigation routine in Catalyst API/frontend/MLIR dialect. At the moment the argument is passed throughout the stack from the frontend all the way to the MLIR dialect. However it is mute, in the sense that it's not being used to change the behavior of the MLIR ZNE transform.

Benefits: This is an incremental change to discuss design and to accomodate follow-up pull requests where the argument will be used to branch off the ZNE mitigation code for different unitary folding techniques.

Possible Drawbacks: The argument is left as global by default and it's not yet used in the MLIR transform, so the current behavior is unchanged. If one tries to use different value for the new argument, exceptions are raised.

Related GitHub Issues: This is an incremental change towards #755.

josh146 commented 1 month ago

Thanks @cosenal! I've pinged @rmoyard to take a look

cosenal commented 1 month ago

Thanks, @josh146. Thanks to @dime10, I have now resolved the errors, and this approach now works 🎉

I haven't publicized the PR yet, because I wanted to clean it up and write tests, but before I do that, it may be a good idea if you or Romain take a preliminary look and give me feedback on the approach.

codecov[bot] commented 1 month ago

Codecov Report

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

Project coverage is 97.93%. Comparing base (daa7109) to head (afe58f8). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #946 +/- ## ======================================= Coverage 97.93% 97.93% ======================================= Files 72 72 Lines 10317 10333 +16 Branches 1176 1177 +1 ======================================= + Hits 10104 10120 +16 Misses 169 169 Partials 44 44 ```

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

dime10 commented 1 month ago

Thanks, @josh146. Thanks to @dime10, I have now resolved the errors, and this approach now works 🎉

I haven't publicized the PR yet, because I wanted to clean it up and write tests, but before I do that, it may be a good idea if you or Romain take a preliminary look and give me feedback on the approach.

Thanks @cosenal, this looks great to me!

cosenal commented 1 month ago

@dime10 @rmoyard @WrathfulSpatula This PR is now ready for review (I don't have permission to formally request reviewers on this repo).