Skip to content
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

Merged
merged 12 commits into from
Jul 24, 2024

Conversation

josh146
Copy link
Member

@josh146 josh146 commented Jul 18, 2024

Context:

In Catalyst, catalyst.for_loop and catalyst.while_loop will seamlessly fallback to Python interpretation when @qjit is not present. However, qml.for_loop and qml.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 and qml.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 and qml.while_loop internally, with no changes for standard Python execution, but with loops captured automatically when using @qjit.

Possible Drawbacks:

  • Not a drawback per se, more of a note, but the ForLoopCallable and WhileLoopCallable 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

…nterpreter if a compiler is not available.
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.65%. Comparing base (db7b281) to head (dc4e0f9).
Report is 295 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@josh146 josh146 marked this pull request as ready for review July 21, 2024 02:43
@josh146
Copy link
Member Author

josh146 commented Jul 22, 2024

[sc-69431]

@josh146
Copy link
Member Author

josh146 commented Jul 22, 2024

[sc-69432]

Copy link
Contributor

@dime10 dime10 left a 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 :)

tests/test_compiler.py Outdated Show resolved Hide resolved
Copy link
Contributor

@albi3ro albi3ro left a 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>
@josh146
Copy link
Member Author

josh146 commented Jul 23, 2024

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.

Yeah I agree, qjit_api.py is not the right place for it.

Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@josh146 josh146 merged commit be355e0 into master Jul 24, 2024
40 checks passed
@josh146 josh146 deleted the josh146-patch-3 branch July 24, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants