Beispiel #1
0
 def test_get_interaction_operator_one_body(self):
     interaction_operator = get_interaction_operator(
         FermionOperator('2^ 2'), self.n_qubits)
     one_body = numpy.zeros((self.n_qubits, self.n_qubits), float)
     one_body[2, 2] = 1.
     self.assertEqual(interaction_operator,
                      InteractionOperator(0.0, one_body, self.two_body))
 def setUp(self):
     self.n_qubits = 5
     self.fermion_term = FermionOperator('1^ 2^ 3 4', -3.17)
     self.fermion_operator = self.fermion_term + hermitian_conjugated(
         self.fermion_term)
     self.qubit_operator = jordan_wigner(self.fermion_operator)
     self.interaction_operator = get_interaction_operator(
         self.fermion_operator)
Beispiel #3
0
 def test_get_interaction_operator_two_body_distinct(self):
     interaction_operator = get_interaction_operator(
         FermionOperator('0^ 1^ 2 3'), self.n_qubits)
     two_body = numpy.zeros(
         (self.n_qubits, self.n_qubits, self.n_qubits, self.n_qubits),
         float)
     two_body[1, 0, 3, 2] = 1.
     self.assertEqual(interaction_operator,
                      InteractionOperator(0.0, self.one_body, two_body))
Beispiel #4
0
 def test_get_interaction_operator_two_body(self):
     interaction_operator = get_interaction_operator(
         FermionOperator('2^ 2 3^ 4'), self.n_qubits)
     two_body = numpy.zeros(
         (self.n_qubits, self.n_qubits, self.n_qubits, self.n_qubits),
         float)
     two_body[3, 2, 4, 2] = -1.
     self.assertEqual(interaction_operator,
                      InteractionOperator(0.0, self.one_body, two_body))
Beispiel #5
0
 def test_get_interaction_operator_one_body_twoterm(self):
     interaction_operator = get_interaction_operator(
         FermionOperator('2^ 3', -2j) + FermionOperator('3^ 2', 3j),
         self.n_qubits)
     one_body = numpy.zeros((self.n_qubits, self.n_qubits), complex)
     one_body[2, 3] = -2j
     one_body[3, 2] = 3j
     self.assertEqual(interaction_operator,
                      InteractionOperator(0.0, one_body, self.two_body))
Beispiel #6
0
 def test_get_interaction_operator_identity(self):
     interaction_operator = InteractionOperator(-2j, self.one_body,
                                                self.two_body)
     qubit_operator = jordan_wigner(interaction_operator)
     self.assertTrue(qubit_operator.isclose(-2j * QubitOperator(())))
     self.assertEqual(
         interaction_operator,
         get_interaction_operator(reverse_jordan_wigner(qubit_operator),
                                  self.n_qubits))
Beispiel #7
0
    def test_jordan_wigner_interaction_op_with_zero_term(self):
        test_op = FermionOperator('1^ 2^ 3 4')
        test_op += hermitian_conjugated(test_op)

        interaction_op = get_interaction_operator(test_op)
        interaction_op.constant = 0.0

        retransformed_test_op = reverse_jordan_wigner(
            jordan_wigner(interaction_op))
Beispiel #8
0
    def test_jordan_wigner_twobody_interaction_op_allunique(self):
        test_op = FermionOperator('1^ 2^ 3 4')
        test_op += hermitian_conjugated(test_op)

        retransformed_test_op = reverse_jordan_wigner(
            jordan_wigner(get_interaction_operator(test_op)))

        self.assertTrue(
            normal_ordered(retransformed_test_op).isclose(
                normal_ordered(test_op)))
Beispiel #9
0
 def test_jordan_wigner_twobody_interaction_op_reversal_symmetric(self):
     test_op = FermionOperator('1^ 2^ 2 1')
     test_op += hermitian_conjugated(test_op)
     self.assertTrue(
         jordan_wigner(test_op).isclose(
             jordan_wigner(get_interaction_operator(test_op))))