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
Test all operators with assert_valid, or fail with a reason #4978
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4978 +/- ##
==========================================
- Coverage 99.67% 99.67% -0.01%
==========================================
Files 392 392
Lines 35556 35303 -253
==========================================
- Hits 35442 35188 -254
- Misses 114 115 +1 ☔ View full report in Codecov by Sentry. |
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.
I obviously like having a list of all the things we need to fix. Though I am distracted by wanting to fix all those issues immediately, the point of isn't to fix the issues, but just to keep a list of the things we need to fix.
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.
Looks good, but lets wait on merging this until after the RC-master merge and fixing the consequent IsingXX
PickleError
(or lack thereof).
Co-authored-by: Christina Lee <christina@xanadu.ai>
# Conflicts: # tests/ops/functions/conftest.py
**Context:** Continuation of the work I started in #4922 (this is part 1 of the future work listed in that PR) **Description of the Change:** 1. Implement `_flatten` for `BlockEncode` and `SpecialUnitary` to pytreeify those types 2. Organize `tests/ops/functions/conftest.py` to better parametrize tests. The parametrization fixtures are easier to make using the following: - `_INSTANCES_TO_TEST` is a list of operator instances that couldn't be auto-generated, but do pass validation - `_INSTANCES_TO_FAIL` is a list of tuples (`(Operator, Type[Exception])`) where the first element is an operator instance that will fail validation, and the second element is the exception type raised during validation. Ideally, it also comes with a comment explaining what's failing/why it should fail. All test collection logic is now in `conftest.py`, making the tests much smaller and simpler. The only "extra" logic in the tests is the xfail I added for all qutrit ops before auto-generation. Now there are 3 tests: 1. `test_generated_list_of_ops`, which auto-generates instances of every Operator type and asserts its validity 2. `test_explicit_list_of_ops`, which tests the validity of manual operator instances 3. `test_explicit_list_of_failing_ops`, which ensures that invalid operator instances fail to validate as expected **Benefits:** Every single pennylane operator (except for templates) is (in)validated in a single test file, and most of it is done automatically. **Possible Drawbacks:** Yet another test file that needs maintenance. --------- Co-authored-by: Christina Lee <christina@xanadu.ai>
Context:
Continuation of the work I started in #4922 (this is part 1 of the future work listed in that PR)
Description of the Change:
_flatten
forBlockEncode
andSpecialUnitary
to pytreeify those typestests/ops/functions/conftest.py
to better parametrize tests. The parametrization fixtures are easier to make using the following:_INSTANCES_TO_TEST
is a list of operator instances that couldn't be auto-generated, but do pass validation_INSTANCES_TO_FAIL
is a list of tuples ((Operator, Type[Exception])
) where the first element is an operator instance that will fail validation, and the second element is the exception type raised during validation. Ideally, it also comes with a comment explaining what's failing/why it should fail.All test collection logic is now in
conftest.py
, making the tests much smaller and simpler. The only "extra" logic in the tests is the xfail I added for all qutrit ops before auto-generation. Now there are 3 tests:test_generated_list_of_ops
, which auto-generates instances of every Operator type and asserts its validitytest_explicit_list_of_ops
, which tests the validity of manual operator instancestest_explicit_list_of_failing_ops
, which ensures that invalid operator instances fail to validate as expectedBenefits:
Every single pennylane operator (except for templates) is (in)validated in a single test file, and most of it is done automatically.
Possible Drawbacks:
Yet another test file that needs maintenance.