Skip to content

Commit

Permalink
fix equiv
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Oct 28, 2022
1 parent 6ea18f3 commit 853e730
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 4 additions & 7 deletions qiskit_nature/second_q/operators/sparse_label_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ def equiv(
) -> bool:
"""Check equivalence of two ``SparseLabelOp`` instances up to an accepted tolerance.
The default absolute and relative tolerances can be changed via the `atol` and `rtol`
attributes, respectively.
Args:
other: the second ``SparseLabelOp`` to compare with this instance.
atol: Absolute numerical tolerance. The default behavior is to use ``self.atol``.
Expand All @@ -326,14 +323,14 @@ def equiv(
True if operators are equivalent, False if not.
Raises:
ValueError: Operator contains parameters.
ValueError: Raised if either operator contains parameters
"""
if self.is_parameterized():
raise ValueError("Cannot compare an operator that contains parameters.")

if not isinstance(other, self.__class__):
return False

if self.is_parameterized() or other.is_parameterized():
raise ValueError("Cannot compare an operator that contains parameters.")

if self._data.keys() != other._data.keys():
return False

Expand Down
3 changes: 3 additions & 0 deletions test/second_q/operators/test_sparse_label_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ def test_equiv(self):
test_op = DummySparseLabelOp(opParameter)
with self.assertRaisesRegex(ValueError, "parameter"):
_ = test_op.equiv(DummySparseLabelOp(opParameter))
test_op = DummySparseLabelOp(opComplex)
with self.assertRaisesRegex(ValueError, "parameter"):
_ = test_op.equiv(DummySparseLabelOp(opParameter))

def test_iter(self):
"""test __iter__ method"""
Expand Down

0 comments on commit 853e730

Please sign in to comment.