예제 #1
0
    def test_build_from_openfermion(self):
        print('\n')
        trial_state = qforte.QuantumComputer(4)

        trial_prep = [None] * 5
        trial_prep[0] = qforte.gate('H', 0, 0)
        trial_prep[1] = qforte.gate('H', 1, 1)
        trial_prep[2] = qforte.gate('H', 2, 2)
        trial_prep[3] = qforte.gate('H', 3, 3)
        trial_prep[4] = qforte.gate('cX', 0, 1)

        trial_circ = qforte.QuantumCircuit()

        #prepare the circuit
        for gate in trial_prep:
            trial_circ.add_gate(gate)

        # use circuit to prepare trial state
        trial_state.apply_circuit(trial_circ)

        test_operator = QubitOperator('X2 Y1', 0.0 - 0.25j)
        test_operator += QubitOperator('Y2 Y1', 0.25)
        test_operator += QubitOperator('X2 X1', 0.25)
        test_operator += QubitOperator('Y2 X1', 0.0 + 0.25j)
        print(test_operator)

        qforte_operator = qforte.build_from_openfermion(test_operator)

        qforte.smart_print(qforte_operator)

        exp = trial_state.direct_op_exp_val(qforte_operator)
        print(exp)
        self.assertAlmostEqual(exp, 0.2499999999999999 + 0.0j)
예제 #2
0
        def add_singles(occ_idx, vir_idx):
            for i in occ_idx:
                for a in vir_idx:
                    single = FermionOperator(((a, 1), (i, 0)))
                    # 1. build Fermion anti-Hermitian operator
                    single -= hermitian_conjugated(single)
                    # 2. JW transformation to qubit operator
                    jw_single = jordan_wigner(single)
                    h_single_commutator = commutator(self.h_qubit_OF, jw_single)
                    # 3. qforte.build_from_openfermion(OF_qubitop)
                    qf_jw_single = qforte.build_from_openfermion(jw_single)
                    qf_commutator = qforte.build_from_openfermion(h_single_commutator)

                    self.fermion_ops.append((i,a))
                    self.jw_ops.append(qf_jw_single)
                    self.jw_commutators.append(qf_commutator)
예제 #3
0
        def add_doubles(occ_idx_pairs, vir_idx_pairs):
            for ji in occ_idx_pairs:
                for ba in vir_idx_pairs:
                    j, i = ji
                    b, a = ba

                    double = FermionOperator(F'{a}^ {b}^ {i} {j}')
                    double -= hermitian_conjugated(double)
                    jw_double = jordan_wigner(double)
                    h_double_commutator = commutator(self.h_qubit_OF, jw_double)

                    qf_jw_double = qforte.build_from_openfermion(jw_double)
                    qf_commutator = qforte.build_from_openfermion(
                    h_double_commutator)

                    self.fermion_ops.append((j,i,b,a))
                    self.jw_ops.append(qf_jw_double)
                    self.jw_commutators.append(qf_commutator)
예제 #4
0
    def get_qubit_hamitonian(self, docc_indices=None, active_orb_indices=None):
        """ Return Hamiltonian operator as a qforte.QuantumOperator instance

        Parameters
        ----------
        docc_indices: list, optional
            list of spatial orbital indices indicating which orbitals should be considered doubly occupied.
        active_orb_indices: list, optional
            list of spatial orbital indices indicating which orbitals should be considered active.

        """
        # "molecular_hamiltonian": instance of the MolecularOperator class

        molecular_hamiltonian = self.molecule.get_molecular_hamiltonian(
            occupied_indices=docc_indices, active_indices=active_orb_indices)
        h_fermion = normal_ordered(get_fermion_operator(molecular_hamiltonian))
        h_qubit_OF = jordan_wigner(h_fermion)
        h_qubit_qf = qforte.build_from_openfermion(h_qubit_OF)
        return h_qubit_qf, h_qubit_OF