def test_commutator(self):
     operator_a = FermionOperator('')
     self.assertTrue(FermionOperator().isclose(
         commutator(operator_a, self.fermion_operator)))
     operator_b = QubitOperator('X1 Y2')
     self.assertTrue(commutator(self.qubit_operator, operator_b).isclose(
         self.qubit_operator * operator_b -
         operator_b * self.qubit_operator))
 def test_commutator_operator_b_bad_type_raise_TypeError(self):
     with self.assertRaises(TypeError):
         commutator(self.qubit_operator, "hello")
 def test_commutator_operator_b_bad_type_raise_TypeError(self):
     with self.assertRaises(TypeError):
         commutator(1, self.fermion_operator)
Example #4
0
 def test_commutator_hopping_with_double_number_two_intersections(self):
     com = commutator(FermionOperator('2^ 3'), FermionOperator('3^ 2^ 3 2'))
     com = normal_ordered(com)
     self.assertTrue(com.isclose(FermionOperator.zero()))
Example #5
0
 def test_commutator_not_same_type(self):
     with self.assertRaises(TypeError):
         commutator(self.fermion_operator, self.qubit_operator)
Example #6
0
 def test_commutator_hopping_with_single_number(self):
     com = commutator(FermionOperator('1^ 2', 1j), FermionOperator('1^ 1'))
     com = normal_ordered(com)
     self.assertTrue(com.isclose(-FermionOperator('1^ 2') * 1j))
Example #7
0
 def test_commutator_hopping_operators(self):
     com = commutator(3 * FermionOperator('1^ 2'), FermionOperator('2^ 3'))
     com = normal_ordered(com)
     self.assertTrue(com.isclose(FermionOperator('1^ 3', 3)))
Example #8
0
 def test_commutes_number_operators(self):
     com = commutator(FermionOperator('4^ 3^ 4 3'), FermionOperator('2^ 2'))
     com = normal_ordered(com)
     self.assertTrue(com.isclose(FermionOperator.zero()))
Example #9
0
 def test_commutes_no_intersection(self):
     com = commutator(FermionOperator('2^ 3'), FermionOperator('4^ 5^ 3'))
     com = normal_ordered(com)
     self.assertTrue(com.isclose(FermionOperator.zero()))
Example #10
0
 def test_commutes_identity(self):
     com = commutator(FermionOperator.identity(),
                      FermionOperator('2^ 3', 2.3))
     self.assertTrue(com.isclose(FermionOperator.zero()))