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
Improve use of keyword args in qml.equal
comparison
#5408
Labels
good first issue
Good for newcomers
Comments
@albi3ro |
albi3ro
added a commit
that referenced
this issue
May 15, 2024
### 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 <[email protected]>
Shiro-Raven
pushed a commit
that referenced
this issue
May 15, 2024
### 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 <[email protected]>
Closed with #5668 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While
qml.equal
has the keyword argumentscheck_interface
,check_trainability
,atol
, andrtol
, not all specialized kernels use them when they should.These operators are:
Pow
:pennylane/pennylane/ops/functions/equal.py
Line 324 in 78abf2b
Adjoint
:pennylane/pennylane/ops/functions/equal.py
Line 333 in 78abf2b
Exp
:pennylane/pennylane/ops/functions/equal.py
Line 341 in 78abf2b
SProd
:pennylane/pennylane/ops/functions/equal.py
Line 361 in 78abf2b
After this change, we should have:
Relevant tests should be added to:
https://github.com/PennyLaneAI/pennylane/blob/master/tests/ops/functions/test_equal.py
A changelog entry should be added under
Community Contributions
pennylane/doc/releases/changelog-dev.md
Line 144 in 78abf2b
And your name should be added to the list of contributors at the bottom of the changelog:
pennylane/doc/releases/changelog-dev.md
Line 238 in 78abf2b
The text was updated successfully, but these errors were encountered: