예제 #1
0
    def test_ccr_offsite_odd_aa(self):
        a1 = FermionOperator(((1, 0), ))
        a4 = FermionOperator(((4, 0), ))
        self.assertTrue(
            normal_ordered(a1 * a4).isclose(normal_ordered(-a4 * a1)))

        self.assertTrue(
            jordan_wigner(a1 * a4).isclose(jordan_wigner(-a4 * a1)))
예제 #2
0
    def test_ccr_offsite_even_aa(self):
        a2 = FermionOperator(((2, 0), ))
        a4 = FermionOperator(((4, 0), ))
        self.assertTrue(
            normal_ordered(a2 * a4).isclose(normal_ordered(-a4 * a2)))

        self.assertTrue(
            jordan_wigner(a2 * a4).isclose(jordan_wigner(-a4 * a2)))
예제 #3
0
    def test_ccr_offsite_odd_cc(self):
        c1 = FermionOperator(((1, 1), ))
        c4 = FermionOperator(((4, 1), ))
        self.assertTrue(
            normal_ordered(c1 * c4).isclose(normal_ordered(-c4 * c1)))

        self.assertTrue(
            jordan_wigner(c1 * c4).isclose(jordan_wigner(-c4 * c1)))
예제 #4
0
    def test_ccr_offsite_even_cc(self):
        c2 = FermionOperator(((2, 1), ))
        c4 = FermionOperator(((4, 1), ))
        self.assertTrue(
            normal_ordered(c2 * c4).isclose(normal_ordered(-c4 * c2)))

        self.assertTrue(
            jordan_wigner(c2 * c4).isclose(jordan_wigner(-c4 * c2)))
예제 #5
0
 def test_ccr_onsite(self):
     c1 = FermionOperator(((1, 1), ))
     a1 = hermitian_conjugated(c1)
     self.assertTrue(
         normal_ordered(
             c1 *
             a1).isclose(FermionOperator(()) - normal_ordered(a1 * c1)))
     self.assertTrue(
         jordan_wigner(
             c1 * a1).isclose(QubitOperator(()) - jordan_wigner(a1 * c1)))
예제 #6
0
    def test_jordan_wigner_one_body(self):
        # Make sure it agrees with jordan_wigner(FermionTerm).
        for p in range(self.n_qubits):
            for q in range(self.n_qubits):
                # Get test qubit operator.
                test_operator = jordan_wigner_one_body(p, q)

                # Get correct qubit operator.
                fermion_term = FermionOperator(((p, 1), (q, 0)))
                correct_op = jordan_wigner(fermion_term)
                hermitian_conjugate = hermitian_conjugated(fermion_term)
                if not fermion_term.isclose(hermitian_conjugate):
                    correct_op += jordan_wigner(hermitian_conjugate)

                self.assertTrue(test_operator.isclose(correct_op))
예제 #7
0
 def test_jordan_wigner_transm_op(self):
     n = number_operator(self.n_qubits)
     n_jw = jordan_wigner(n)
     self.assertEqual(self.n_qubits + 1, len(n_jw.terms))
     self.assertEqual(self.n_qubits / 2., n_jw.terms[()])
     for qubit in range(self.n_qubits):
         operators = ((qubit, 'Z'), )
         self.assertEqual(n_jw.terms[operators], -0.5)
예제 #8
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))
예제 #9
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))
예제 #10
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)))
예제 #11
0
    def test_transm_lower0(self):
        lowering = jordan_wigner(FermionOperator(((0, 0), )))

        correct_operators_x = ((0, 'X'), )
        correct_operators_y = ((0, 'Y'), )
        qtermx = QubitOperator(correct_operators_x, 0.5)
        qtermy = QubitOperator(correct_operators_y, 0.5j)

        self.assertEqual(lowering.terms[correct_operators_x], 0.5)
        self.assertEqual(lowering.terms[correct_operators_y], 0.5j)
        self.assertTrue(lowering.isclose(qtermx + qtermy))
예제 #12
0
 def test_transm_raise3lower0(self):
     # recall that creation gets -1j on Y and annihilation gets +1j on Y.
     term = jordan_wigner(FermionOperator(((3, 1), (0, 0))))
     self.assertEqual(term.terms[((0, 'X'), (1, 'Z'), (2, 'Z'), (3, 'Y'))],
                      0.25 * 1 * -1j)
     self.assertEqual(term.terms[((0, 'Y'), (1, 'Z'), (2, 'Z'), (3, 'Y'))],
                      0.25 * 1j * -1j)
     self.assertEqual(term.terms[((0, 'Y'), (1, 'Z'), (2, 'Z'), (3, 'X'))],
                      0.25 * 1j * 1)
     self.assertEqual(term.terms[((0, 'X'), (1, 'Z'), (2, 'Z'), (3, 'X'))],
                      0.25 * 1 * 1)
예제 #13
0
    def test_transm_raise1(self):
        raising = jordan_wigner(FermionOperator(((1, 1), )))

        correct_operators_x = ((0, 'Z'), (1, 'X'))
        correct_operators_y = ((0, 'Z'), (1, 'Y'))
        qtermx = QubitOperator(correct_operators_x, 0.5)
        qtermy = QubitOperator(correct_operators_y, -0.5j)

        self.assertEqual(raising.terms[correct_operators_x], 0.5)
        self.assertEqual(raising.terms[correct_operators_y], -0.5j)
        self.assertTrue(raising.isclose(qtermx + qtermy))
예제 #14
0
    def test_jordan_wigner_two_body(self):
        # Make sure it agrees with jordan_wigner(FermionTerm).
        for p in range(self.n_qubits):
            for q in range(self.n_qubits):
                for r in range(self.n_qubits):
                    for s in range(self.n_qubits):
                        # Get test qubit operator.
                        test_operator = jordan_wigner_two_body(p, q, r, s)

                        # Get correct qubit operator.
                        fermion_term = FermionOperator(
                            ((p, 1), (q, 1), (r, 0), (s, 0)))
                        correct_op = jordan_wigner(fermion_term)
                        hermitian_conjugate = hermitian_conjugated(
                            fermion_term)
                        if not fermion_term.isclose(hermitian_conjugate):
                            if p == r and q == s:
                                pass
                            else:
                                correct_op += jordan_wigner(
                                    hermitian_conjugate)

                        self.assertTrue(test_operator.isclose(correct_op),
                                        str(test_operator - correct_op))
예제 #15
0
 def test_bad_input(self):
     with self.assertRaises(TypeError):
         jordan_wigner(3)
예제 #16
0
 def test_transm_number(self):
     n = number_operator(self.n_qubits, 3)
     n_jw = jordan_wigner(n)
     self.assertEqual(n_jw.terms[((3, 'Z'), )], -0.5)
     self.assertEqual(n_jw.terms[()], 0.5)
     self.assertEqual(len(n_jw.terms), 2)
예제 #17
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))))