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

Automatically test plxpr capture integration with assert_valid #5686

Merged
merged 99 commits into from
Jun 4, 2024

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented May 14, 2024

Context:

Following on from #5523, we need a good way of ensuring operations will integrate well with program capture.

Description of the Change:

This PR adds a check to the assert_valid function to ensure capture is working as expected.

It then starts to fix up some operations that were failing to be captured correctly.

Benefits:

More robust integration with pl capture.

Possible Drawbacks:

I'm realizing a lot more operators fail to be immediately captured than I initially assumed 😢

Related GitHub Issues:

[sc-63310]

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

LGTM, just a few tiny questions. Thanks for the patch @albi3ro!
I'm wondering: Can we have a systematic way to make sure that assert_valid is called on all PL objects it can be applied to? 🤔
Similar to the logic in the templates testing file, where PL is scraped for Operators (and SymbolicOps?) and assert_valid keeps track of which classes it saw? 🤔

pennylane/ops/functions/assert_valid.py Outdated Show resolved Hide resolved
pennylane/ops/meta.py Outdated Show resolved Hide resolved
pennylane/ops/op_math/controlled_ops.py Show resolved Hide resolved
Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Thanks for the explainers! 🙏

@albi3ro
Copy link
Contributor Author

albi3ro commented May 15, 2024

LGTM, just a few tiny questions. Thanks for the patch @albi3ro! I'm wondering: Can we have a systematic way to make sure that assert_valid is called on all PL objects it can be applied to? 🤔 Similar to the logic in the templates testing file, where PL is scraped for Operators (and SymbolicOps?) and assert_valid keeps track of which classes it saw? 🤔

So by default we do automatically validate all operators except for templates. See this file for the automatic collection: https://github.com/PennyLaneAI/pennylane/blob/master/tests/ops/functions/conftest.py

We opted templates out of this process due to the complexity of automatically generating a valid instance, but most templates have an assert_valid test associated with them.

@dwierichs
Copy link
Contributor

Ah, brilliant! So the only thing one could add is a cache that memorizes tested templates (from the template test files) and checks for untested templates (as per assert_valid). I can see this being very shaky though 🙃

Base automatically changed from plxpr-capture-templates to master May 31, 2024 12:42
@albi3ro albi3ro marked this pull request as ready for review May 31, 2024 18:01
Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

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

Two new comments I had.

pennylane/ops/meta.py Outdated Show resolved Hide resolved
pennylane/resource/first_quantization.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (c14ce7b) to head (3e5ef90).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5686      +/-   ##
==========================================
- Coverage   99.67%   99.67%   -0.01%     
==========================================
  Files         414      414              
  Lines       39316    39167     -149     
==========================================
- Hits        39188    39038     -150     
- Misses        128      129       +1     

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

@albi3ro albi3ro requested a review from mudit2812 June 3, 2024 15:32
@albi3ro albi3ro merged commit ddfb019 into master Jun 4, 2024
40 checks passed
@albi3ro albi3ro deleted the plxpr-capture-assertion-tests branch June 4, 2024 21:25
@willjmax willjmax mentioned this pull request Jun 6, 2024
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.

None yet

3 participants