-
Notifications
You must be signed in to change notification settings - Fork 603
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
Allow qml.for_loop
and qml.while_loop
to fallback to the Python interpreter if a compiler is not available.
#6014
Conversation
…nterpreter if a compiler is not available.
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6014 +/- ##
==========================================
- Coverage 99.66% 99.65% -0.01%
==========================================
Files 427 427
Lines 41119 40855 -264
==========================================
- Hits 40980 40714 -266
- Misses 139 141 +2 ☔ View full report in Codecov by Sentry. |
[sc-69431] |
[sc-69432] |
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.
Great addition, no comments from my side :)
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.
Nothing blocking, but just a few nitpicks.
My main question is about where the source code for this should live long term. I'm happy to leave these here for now, but we should consider moving it to either the capture
module or somewhere new.
Co-authored-by: Christina Lee <christina@xanadu.ai>
Yeah I agree, |
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.
🎉
Context:
In Catalyst,
catalyst.for_loop
andcatalyst.while_loop
will seamlessly fallback to Python interpretation when@qjit
is not present. However,qml.for_loop
andqml.while_loop
will instead raise an error when@qjit
is not present, which is not ideal.Description of the Change:
When
@qjit
is not present,qml.for_loop
andqml.while_loop
will now simply execute the for/while loop in standard Python.Benefits:
This will allow the same code to work with and without
@qjit
, without needing to modify the workflow.This will also allow templates and operation decompositions to use
qml.for_loop
andqml.while_loop
internally, with no changes for standard Python execution, but with loops captured automatically when using@qjit
.Possible Drawbacks:
ForLoopCallable
andWhileLoopCallable
classes introduced in this PR might be needed (and extended) to support capturing for loops/if statements as JAXPR primitives(?). They are based on the equivalent classes from Catalyst.Related GitHub Issues: n/a