-
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
Add kwargs for equal functions #5668
Conversation
Thanks for opening this PR @kenya-sk ! Looking great 🎉 I looked into the jax failure in This kind of failure is exactly why we are now in the process of adding an Now other comments from my side. I'll check back later. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5668 +/- ##
==========================================
- Coverage 99.68% 99.67% -0.01%
==========================================
Files 414 414
Lines 38819 38550 -269
==========================================
- Hits 38695 38425 -270
- Misses 124 125 +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.
Looks perfect 🎉 I'm happy to approve.
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.
@dwierichs @albi3ro |
@dwierichs @albi3ro Also, since |
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.
Thank you @kenya-sk for this thorough work! 💯
### Before submitting Please complete the following checklist when submitting a PR: - [x] All new features must include a unit test. If you've fixed a bug or added code that should be tested, add a test to the test directory! - [x] All new functions and code must be clearly commented and documented. If you do make documentation changes, make sure that the docs build and render correctly by running `make docs`. - [x] Ensure that the test suite passes, by running `make test`. - [x] Add a new entry to the `doc/releases/changelog-dev.md` file, summarizing the change, and including a link back to the PR. - [x] The PennyLane source code conforms to [PEP8 standards](https://www.python.org/dev/peps/pep-0008/). We check all of our code against [Pylint](https://www.pylint.org/). To lint modified files, simply `pip install pylint`, and then run `pylint pennylane/path/to/file.py`. When all the above are checked, delete everything above the dashed line and fill in the pull request template. ------------------------------------------------------------------------------------------------------------ **Context:** The kwargs (`check_interface`, `check_trainability`, `atol` and `rtol`) were not available for `_equal_pow`, `_equal_adjoint`, `_equal_exp` and `_equal_sprod`, which are overrides of `qml.equal`. Therefore, comparisons that allowed for interfacing and numerical errors were not possible. **Description of the Change:** Changed to allow kwargs to be used in override of `qml.equal`. **Benefits:** The following interfaces and comparisons with tolerance for numerical errors are possible. ``` >>> op1 = qml.RX(1.2, wires=0) >>> op2 = qml.RX(1.2 + 1e-4, wires=0) >>> qml.equal(op1 **2, op2 ** 2, atol=1e-3) True >>> qml.equal(op1 **2, op2 ** 2, atol=1e-6) False >>> qml.equal(qml.adjoint(op1), qml.adjoint(op2), atol=1e-3) True >>> qml.equal(qml.adjoint(op1), qml.adjoint(op2), atol=1e-6) False >>> op3 = qml.exp( qml.s_prod(2j, qml.X(0))) >>> op4 = qml.exp(qml.s_prod(qml.numpy.array(2j), qml.X(0))) >>> qml.equal(op3, op4, check_interface=True) False >>> qml.equal(op3, op4, check_interface=False) True ``` **Possible Drawbacks:** **Related GitHub Issues:** #5408 --------- Co-authored-by: Christina Lee <christina@xanadu.ai>
Before submitting
Please complete the following checklist when submitting a PR:
All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to the
test directory!
All new functions and code must be clearly commented and documented.
If you do make documentation changes, make sure that the docs build and
render correctly by running
make docs
.Ensure that the test suite passes, by running
make test
.Add a new entry to the
doc/releases/changelog-dev.md
file, summarizing thechange, and including a link back to the PR.
The PennyLane source code conforms to
PEP8 standards.
We check all of our code against Pylint.
To lint modified files, simply
pip install pylint
, and thenrun
pylint pennylane/path/to/file.py
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Context:
The kwargs (
check_interface
,check_trainability
,atol
andrtol
) were not available for_equal_pow
,_equal_adjoint
,_equal_exp
and_equal_sprod
, which are overrides ofqml.equal
. Therefore, comparisons that allowed for interfacing and numerical errors were not possible.Description of the Change:
Changed to allow kwargs to be used in override of
qml.equal
.Benefits:
The following interfaces and comparisons with tolerance for numerical errors are possible.
Possible Drawbacks:
Related GitHub Issues:
#5408