Improve operator support for new assert_equal
function: Group 2
#5648
Labels
unitaryhack
Dedicated issue for Unitary Fund open-source hackathon
Context
PennyLane currently has a
qml.equal
function which can be used to check the equality of operators, measurements, and tapes. While this has been extremely useful in testing and validation, it can be difficult to figure out why two objects aren't equal.This is why we are currently have added the framework for an
assert_equal
function:pennylane/pennylane/ops/functions/equal.py
Line 179 in b6e9658
The framework for this function was added in PR #5634 , but the implementation still needs to be updated.
Implementation Details
Comparison currently relies on a
_equal
single dispatch function, with different "kernels" registered for different types of operators. Currently this function returnsTrue
orFalse
. We are changing it to returnTrue
, or a string that explains why the two operators are not equal. This change has already been made forBasisRotation
:pennylane/pennylane/ops/functions/equal.py
Line 605 in b6e9658
This task is to update
_equal
forSProd
classes: see_equal_sprod
ControlledSequence
classes: see_equal_controlled_sequence
Prod
andSum
composite classes:_equal_prod_and_sum
Tensor
classes (legacy):_equal_tensor
Hamiltonian
(legacy) clases:_equal_hamiltonian
While more single dispatch kernels exist for
_equal
, they will be updated as part of separate tasks.After this PR and one from Issue #5644 , we should be able to do something like:
Use your best judgement as to the contents of the string and we will help refine the message if needed. The output may recursively depend on
_equal
when comparing component operations.Additional Requirements
To fulfill this task, a PR should:
_equal
kernels for the above casestest_equal.py
. Existing tests like,test_adjoint_comparison
can be extended, or new tests can be written.The text was updated successfully, but these errors were encountered: