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

[Frontend] Support static_argnums #476

Merged
merged 21 commits into from
Jan 31, 2024

Conversation

tzunghanjuang
Copy link
Collaborator

@tzunghanjuang tzunghanjuang commented Jan 25, 2024

Context: Supporting static_argnums to identify which arguments are static. I

Description of the Change: Introduce the static_argnums parameter to @qjit and add a mechanism to determine if the function needs to be recompiled when the static arguments are changed.

Benefits: Users can pass custom objects to a function with @qjit. The QJIT object also stores all previously compiled functions for different arguments. If the arguments are seen before, there is no need for re-compilation.

Possible Drawbacks: The QJIT object will store all the previously compiled functions and require more space.
The mechanism for recompilation is based on checking hash values, so there might be a possibility of collision. It also creates a new catalyst.utils.filesystem.WorkspaceManager for every new function. If we do not create a new WorkspaceManager, the new function will not be properly compiled. I am not sure if I should modify anything related to it.

Related GitHub Issues: closes #461

@dime10
Copy link
Contributor

dime10 commented Jan 25, 2024

Hi @tzunghanjuang, thank you for opening this PR :) Please let us know when you feel it is ready to review, you can also tag me as a reviewer at that point.

@tzunghanjuang
Copy link
Collaborator Author

Hi @dime10, it is ready for review but it seems that I do not have repo permission to add you as the reviewer. Thank you very much.

Copy link

codecov bot commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (570a992) 99.56% compared to head (a5134d0) 99.57%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #476   +/-   ##
=======================================
  Coverage   99.56%   99.57%           
=======================================
  Files          43       43           
  Lines        7655     7722   +67     
  Branches      516      533   +17     
=======================================
+ Hits         7622     7689   +67     
  Misses         17       17           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 job getting this feature working 💯

I have a couple of questions that ask for clarification and a few suggestions to update the code, but overall this is looking great!

frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/test/pytest/test_static_arguments.py Outdated Show resolved Hide resolved
frontend/test/pytest/test_static_arguments.py Show resolved Hide resolved
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 work on this @tzunghanjuang 🥳

After all discussions are closed it should be good to merge :)

frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
@dime10
Copy link
Contributor

dime10 commented Jan 26, 2024

Oh one last thing, most PRs require a changelog entry describing at a high level what changed and why. This PR would be a "new feature", and those also require a code example in the changelog entry demonstrating the new feature. Have a look at the file here: https://github.com/PennyLaneAI/catalyst/blob/main/doc/changelog.md

@dime10
Copy link
Contributor

dime10 commented Jan 26, 2024

Sorry about the formatting failure, I think the black version was just updated. Merging with main should fix it if the issue is coming from files untouched by your PR.

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.

Hi @tzunghanjuang, I posted my answer to the last remaining issue: #476 (comment)

And make CompiledFunction store worksapce to avoid cleanup.
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.

Nice job fixing the library reopening 👍

frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Show resolved Hide resolved
frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
And rename recompilation_needed into recompilation_happened
@maliasadi maliasadi added the frontend Pull requests that update the frontend label Jan 30, 2024
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.

Alright, this one is good to go, great work 🎉 🎉

frontend/catalyst/compilation_pipelines.py Outdated Show resolved Hide resolved
@dime10 dime10 merged commit 96a8d1e into PennyLaneAI:main Jan 31, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Pull requests that update the frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support compile-time function arguments via static_argnums
3 participants