Repository: PennyLaneAI/pennylane

Issue:
[BUG] `qml.equal` ignore in-place inversion
Currently, we have:
```
>>> qml.equal(qml.RX(1.0, wires=0), qml.RX(1.0, wires=0).inv())
True
```

If two operations are inverses of each other, they should not be equal.

Discussion:
github-actions[bot]: Hello. You may have forgotten to update the changelog!
Please edit [`doc/releases/changelog-dev.md`](/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) with:
* A one-to-two sentence description of the change. You may include a small working example for new features.
* A link back to this PR.
* Your name (or GitHub username) in the contributors section.
codecov[bot]: # [Codecov](https://codecov.io/gh/PennyLaneAI/pennylane/pull/2947?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
> :exclamation: No coverage uploaded for pull request base (`v0.25.0-rc0@ee190b3`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI#section-missing-base-commit).
> The diff coverage is `n/a`.

```diff
@@              Coverage Diff               @@
##             v0.25.0-rc0    #2947   +/-   ##
==============================================
  Coverage               ?   99.64%           
==============================================
  Files                  ?      260           
  Lines                  ?    21939           
  Branches               ?        0           
==============================================
  Hits                   ?    21862           
  Misses                 ?       77           
  Partials               ?        0           
```



Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI)


Patch:
diff --git a/doc/releases/changelog-0.25.0.md b/doc/releases/changelog-0.25.0.md
index 1696b9060..3a49b7bd4 100644
--- a/doc/releases/changelog-0.25.0.md
+++ b/doc/releases/changelog-0.25.0.md
@@ -710,6 +710,9 @@ of operators.
 
 <h3>Bug fixes 🐞</h3>
 
+* Fixes `qml.equal` so that operators with different inverse properties are not equal.
+  [(#2947)](https://github.com/PennyLaneAI/pennylane/pull/2947)
+
 * Cleans up interactions between operator arithmetic and batching by
   testing supported cases and adding errors when batching is not supported.
   [(#2900)](https://github.com/PennyLaneAI/pennylane/pull/2900)
diff --git a/pennylane/ops/functions/equal.py b/pennylane/ops/functions/equal.py
index 531b9cebe..a4cdbd092 100644
--- a/pennylane/ops/functions/equal.py
+++ b/pennylane/ops/functions/equal.py
@@ -98,4 +98,4 @@ def equal(
             if qml.math.get_interface(params_1) != qml.math.get_interface(params_2):
                 return False
 
-    return True
+    return getattr(op1, "inverse", False) == getattr(op2, "inverse", False)


Test patch:
diff --git a/tests/ops/functions/test_equal.py b/tests/ops/functions/test_equal.py
index 5d8b2bf07..d72118c34 100644
--- a/tests/ops/functions/test_equal.py
+++ b/tests/ops/functions/test_equal.py
@@ -847,3 +847,15 @@ class TestEqual:
             + " depth larger than 0 is not yet implemented.",
         ):
             qml.equal(qml.adjoint(qml.PauliX(0)), qml.adjoint(qml.PauliX(0)))
+
+    def test_equal_same_inversion(self):
+        """Test operations are equal if they are both inverted."""
+        op1 = qml.RX(1.2, wires=0).inv()
+        op2 = qml.RX(1.2, wires=0).inv()
+        assert qml.equal(op1, op2)
+
+    def test_not_equal_different_inversion(self):
+        """Test operations are not equal if one is inverted and the other is not."""
+        op1 = qml.PauliX(0)
+        op2 = qml.PauliX(0).inv()
+        assert not qml.equal(op1, op2)