Пример #1
0
    def test_threshold(self):
        op = get_diagonal_coulomb_hamiltonian(FermionOperator('1^ 1', 0))
        self.assertEqual(op.constant, 0)

        fop = FermionOperator('1^ 1')
        fop *= 0.5 * EQ_TOLERANCE
        op = get_diagonal_coulomb_hamiltonian(fop)
        self.assertEqual(op.constant, 0)
Пример #2
0
 def test_random_quadratic(self):
     n_qubits = 5
     quad_ham = random_quadratic_hamiltonian(n_qubits, True)
     ferm_op = get_fermion_operator(quad_ham)
     self.assertTrue(
         normal_ordered(ferm_op) == normal_ordered(
             get_fermion_operator(get_diagonal_coulomb_hamiltonian(
                 ferm_op))))
Пример #3
0
    def test_ignore_incompatible_terms(self):

        ferm_op = (FermionOperator('0^ 2') + FermionOperator('2^ 0') +
                   FermionOperator('1^ 0^ 2') + FermionOperator('1^ 0^ 2 1') +
                   FermionOperator('0^ 0 1^ 1') + FermionOperator('1^ 2^ 1 2'))
        converted_op = get_diagonal_coulomb_hamiltonian(
            ferm_op, ignore_incompatible_terms=True)
        self.assertTrue(
            numpy.allclose(converted_op.one_body,
                           numpy.array([[0, 0, 1], [0, 0, 0], [1, 0, 0]])))
        self.assertTrue(
            numpy.allclose(
                converted_op.two_body,
                numpy.array([[0, 0.5, 0], [0.5, 0, -0.5], [0, -0.5, 0]])))
Пример #4
0
    def test_hubbard(self):
        x_dim = 4
        y_dim = 5
        tunneling = 2.
        coulomb = 3.
        chemical_potential = 7.
        magnetic_field = 11.
        periodic = False

        hubbard_model = fermi_hubbard(x_dim, y_dim, tunneling, coulomb,
                                      chemical_potential, magnetic_field,
                                      periodic)

        self.assertTrue(
            normal_ordered(hubbard_model) == normal_ordered(
                get_fermion_operator(
                    get_diagonal_coulomb_hamiltonian(hubbard_model))))
Пример #5
0
 def test_exceptions(self):
     op1 = QubitOperator()
     op2 = FermionOperator('0^ 3') + FermionOperator('3^ 0')
     op3 = FermionOperator('0^ 1^')
     op4 = FermionOperator('0^ 1^ 2^ 3')
     op5 = FermionOperator('0^ 3')
     op6 = FermionOperator('0^ 0 1^ 1', 1.j)
     op7 = FermionOperator('0^ 1^ 2 3')
     with self.assertRaises(TypeError):
         _ = get_diagonal_coulomb_hamiltonian(op1)
     with self.assertRaises(ValueError):
         _ = get_diagonal_coulomb_hamiltonian(op2, n_qubits=2)
     with self.assertRaises(ValueError):
         _ = get_diagonal_coulomb_hamiltonian(op3)
     with self.assertRaises(ValueError):
         _ = get_diagonal_coulomb_hamiltonian(op4)
     with self.assertRaises(ValueError):
         _ = get_diagonal_coulomb_hamiltonian(op5)
     with self.assertRaises(ValueError):
         _ = get_diagonal_coulomb_hamiltonian(op6)
     with self.assertRaises(ValueError):
         _ = get_diagonal_coulomb_hamiltonian(op7)