Skip to content

Commit

Permalink
Undated changelog and added a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dubeyPraY committed Sep 6, 2023
1 parent 8b002da commit d7260b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@

<h3>Bug fixes 🐛</h3>

* `hamiltonian comaparison` now also `rounds off the float to 15digit` to remove float point errors. Have just added a line of rounded float comaprison.
[(#4567)](https://github.com/PennyLaneAI/pennylane/issues/4567)

* `convert_to_numpy_parameters` now uses `qml.ops.functions.bind_new_parameters`. This reinitializes the operation and
makes sure everything references the new numpy parameters.

Expand All @@ -141,4 +144,4 @@ Lillian M. A. Frederiksen,
Romain Moyard,
Mudit Pandey,
Matthew Silverman

Yash Prabhat
3 changes: 3 additions & 0 deletions pennylane/ops/qubit/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ def compare(self, other):
if isinstance(other, Hamiltonian):
self.simplify()
other.simplify()
if self._obs_data() == other._obs_data() : # pylint: disable=protected-access
return True
#for removing float point error
return ((round(list(self._obs_data())[0][0],15),list(self._obs_data())[0][1]) == (
(round(list(other._obs_data())[0][0],15), list(other._obs_data())[0][1]))) # pylint: disable=protected-access

Expand Down
7 changes: 7 additions & 0 deletions tests/test_hamiltonian_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#to test if hamiltonian comapre function has float point error
import pennylane as qml

def test_hamiltonian_compare():
H2 = qml.Hamiltonian([0.3, 0.3], [qml.PauliZ(0), qml.PauliZ(0)])
H1 = qml.Hamiltonian([0.1, 0.2, 0.3], [qml.PauliZ(0), qml.PauliZ(0), qml.PauliZ(0)])
assert (H1.compare(H2))

0 comments on commit d7260b9

Please sign in to comment.