Skip to content

Commit e2fce4f

Browse files
committed
Add tests for ValueError in double_commutator
Added test cases to DoubleCommutatorTest in commutators_test.py to cover the cases where the intersection of indices for hopping operators in double_commutator results in an empty set or a set with more than one element, which triggers a ValueError.
1 parent 022ced8 commit e2fce4f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/openfermion/utils/commutators_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,38 @@ def test_double_commtator_more_info_both_hopping(self):
217217
com, (FermionOperator('4^ 3^ 4 2', 2.73) + FermionOperator('4^ 2^ 4 3', 2.73))
218218
)
219219

220+
def test_double_commutator_hopping_no_intersection(self):
221+
# Case where intersection is empty
222+
op1 = FermionOperator('0^ 0')
223+
op2 = FermionOperator('1^ 2') + FermionOperator('2^ 1')
224+
op3 = FermionOperator('3^ 4') + FermionOperator('4^ 3')
225+
res = double_commutator(
226+
op1,
227+
op2,
228+
op3,
229+
indices2={1, 2},
230+
indices3={3, 4},
231+
is_hopping_operator2=True,
232+
is_hopping_operator3=True,
233+
)
234+
self.assertEqual(res, FermionOperator.zero())
235+
236+
def test_double_commutator_hopping_multi_intersection(self):
237+
# Case where intersection has more than one element
238+
op1 = FermionOperator('0^ 0')
239+
op2 = FermionOperator('1^ 2') + FermionOperator('2^ 1')
240+
op3 = FermionOperator('1^ 2') + FermionOperator('2^ 1')
241+
res = double_commutator(
242+
op1,
243+
op2,
244+
op3,
245+
indices2={1, 2},
246+
indices3={1, 2},
247+
is_hopping_operator2=True,
248+
is_hopping_operator3=True,
249+
)
250+
self.assertEqual(res, FermionOperator.zero())
251+
220252

221253
class TriviallyDoubleCommutesDualBasisUsingTermInfoTest(unittest.TestCase):
222254
def test_number_operators_trivially_commute(self):

0 commit comments

Comments
 (0)