-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fix leftover quantum operations in classical functions during the gradient passes #439
Conversation
- `0_` to avoid it appearing after the HLO pass in intermediate files - more descriptive name than "pipeline"
MLIR generated from the JAX frontend typically contains a lot of duplicate instructions. For instance, the extraction of a scalar value from the same scalar tensor could be repeated several times. Besides making the program larger than it needs to be, it also makes it more difficult to perform insert/extract elimination when dynamic wires are used. This was causing the gradient pass to fail in some instances, specifically when duplicating a hybrid function while removing all quantum code from it.
ebdfe94
to
504331d
Compare
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.
That was quick 🚤 thanks @dime10!
@erick-xanadu I implemented the single register & qubit reset in between transform tapes (626df4d), if you want to give it a look. |
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.
Very smart solution!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #439 +/- ##
=======================================
Coverage 99.56% 99.56%
=======================================
Files 43 43
Lines 7643 7662 +19
Branches 512 514 +2
=======================================
+ Hits 7610 7629 +19
Misses 17 17
Partials 16 16 ☔ View full report in Codecov by Sentry. |
**Context:** v0.4.1 bugfix PR **Description of the Change:** Incorporates the following PRs: #439 #457 #437 #465 #471 --------- Co-authored-by: David Ittah <dime10@users.noreply.github.com> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com> Co-authored-by: Romain Moyard <rmoyard@gmail.com> Co-authored-by: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> Co-authored-by: erick-xanadu <110487834+erick-xanadu@users.noreply.github.com>
Resolves an issue in the gradient dialect brought to light by #397. The error raised is as follows:
The error is thrown when when a quantum function is cloned but with all of its quantum operations removed, in order to retain only the classical code. This is done in several places in the gradient dialect.
In this case, certain input programs (see linked issue) would still cause the gradient pass to be unable to remove all quantum operations from a function. A snippet of the offending IR would look like:
Even though the qubit extraction and insertion are performed at the same index, the SSA value used in both operations is not the same, and so the operations are not automatically folded way. This folding is usually relied upon to remove all quantum operations from a function.
Applying CSE before the gradient pass resolves the issue.
[sc-53218]
fixes #437