Exemple #1
0
def test_erpa_eom_ham_lih():
    filename = os.path.join(DATA_DIRECTORY, "H1-Li1_sto-3g_singlet_1.45.hdf5")
    molecule = MolecularData(filename=filename)
    reduced_ham = make_reduced_hamiltonian(
        molecule.get_molecular_hamiltonian(), molecule.n_electrons)
    rha_fermion = get_fermion_operator(reduced_ham)
    permuted_hijkl = np.einsum('ijlk', reduced_ham.two_body_tensor)
    opdm = np.diag([1] * molecule.n_electrons + [0] *
                   (molecule.n_qubits - molecule.n_electrons))
    tpdm = 2 * wedge(opdm, opdm, (1, 1), (1, 1))
    rdms = InteractionRDM(opdm, tpdm)
    dim = 3  # so we don't do the full basis.  This would make the test long
    full_basis = {}  # erpa basis.  A, B basis in RPA language
    cnt = 0
    # start from 1 to make test shorter
    for p, q in product(range(1, dim), repeat=2):
        if p < q:
            full_basis[(p, q)] = cnt
            full_basis[(q, p)] = cnt + dim * (dim - 1) // 2
            cnt += 1
    for rkey in full_basis.keys():
        p, q = rkey
        for ckey in full_basis.keys():
            r, s = ckey
            for sigma, tau in product([0, 1], repeat=2):
                test = erpa_eom_hamiltonian(permuted_hijkl, tpdm,
                                            2 * q + sigma, 2 * p + sigma,
                                            2 * r + tau, 2 * s + tau).real
                qp_op = FermionOperator(
                    ((2 * q + sigma, 1), (2 * p + sigma, 0)))
                rs_op = FermionOperator(((2 * r + tau, 1), (2 * s + tau, 0)))
                erpa_op = normal_ordered(
                    commutator(qp_op, commutator(rha_fermion, rs_op)))
                true = rdms.expectation(get_interaction_operator(erpa_op))
                assert np.isclose(true, test)
Exemple #2
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))
Exemple #3
0
 def setUp(self):
     self.n_qubits = 5
     self.majorana_operator = MajoranaOperator((1, 4, 9))
     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)
Exemple #4
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))
Exemple #5
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))
Exemple #6
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))
Exemple #7
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 == -2j * QubitOperator(()))
     self.assertEqual(
         interaction_operator,
         get_interaction_operator(reverse_jordan_wigner(qubit_operator),
                                  self.n_qubits))
Exemple #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) == normal_ordered(test_op))
    def test_interaction_operator_mapping(self):

        # Make sure mapping of FermionOperator to InteractionOperator works.
        molecular_hamiltonian = get_interaction_operator(
            self.fermion_hamiltonian)
        fermion_hamiltonian = get_fermion_operator(molecular_hamiltonian)
        self.assertTrue(self.fermion_hamiltonian == fermion_hamiltonian)

        # Make sure mapping of InteractionOperator to QubitOperator works.
        qubit_hamiltonian = jordan_wigner(self.molecular_hamiltonian)
        self.assertTrue(self.qubit_hamiltonian == qubit_hamiltonian)
Exemple #10
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))

        self.assertEqual(normal_ordered(retransformed_test_op),
                         normal_ordered(test_op))
Exemple #11
0
 def test_one_body_constraints(self):
     for constraint in one_body_fermion_constraints(self.n_orbitals,
                                                    self.n_fermions):
         interaction_operator = get_interaction_operator(
             constraint, self.n_orbitals)
         constraint_value = self.fci_rdm.expectation(interaction_operator)
         self.assertAlmostEqual(constraint_value, 0.)
         for term, _ in constraint.terms.items():
             if len(term) == 2:
                 self.assertTrue(term[0][1])
                 self.assertFalse(term[1][1])
             else:
                 self.assertEqual(term, ())
    def test_abstract_molecule(self):
        """Test an abstract molecule like jellium for saving and loading"""
        jellium_interaction = get_interaction_operator(
            jellium_model(Grid(2, 2, 1.0)))
        jellium_molecule = get_molecular_data(jellium_interaction,
                                              geometry="Jellium",
                                              basis="PlaneWave22",
                                              multiplicity=1,
                                              n_electrons=4)

        jellium_filename = jellium_molecule.filename
        jellium_molecule.save()
        jellium_molecule.load()
        correct_name = "Jellium_PlaneWave22_singlet"
        self.assertEqual(jellium_molecule.name, correct_name)
        os.remove("{}.hdf5".format(jellium_filename))
Exemple #13
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) == jordan_wigner(
             get_interaction_operator(test_op)))