示例#1
0
        L_terms.append(
            hcp.generate_arbitary_hamiltonian(num_qubits, [0.5, -0.5j], [
                '0' * i + '1' + '0' * (num_qubits - 1 - i),
                '0' * i + '2' + '0' * (num_qubits - 1 - i)
            ]))
    #L_terms = [hcp.generate_arbitary_hamiltonian(num_qubits,[1],['30'])]
    #L_terms.append(hcp.generate_arbitary_hamiltonian(num_qubits,[0.5,-0.5j],['10','20']))
    #L_terms.append(hcp.generate_arbitary_hamiltonian(num_qubits,[1],['03']))
    #L_terms.append(hcp.generate_arbitary_hamiltonian(num_qubits,[0.5,-0.5j],['01','02']))
else:
    hamiltonian = hcp.generate_arbitary_hamiltonian(
        num_qubits, list(pauli_decomp.values()), list(pauli_decomp.keys()))

#print('Beta values are ' + str(hamiltonian.return_betas()))

ansatz = acp.initial_ansatz(num_qubits)
ansatzlist = []
ansatzlist.append(ansatz)
betamatrixlist = []
#Run IQAE
for k in range(1, uptowhatK + 1):
    print('##########################################')
    print('K = ' + str(k))
    #Generate Ansatz for this round
    ansatz = acp.gen_next_ansatz(ansatz,
                                 hamiltonian,
                                 num_qubits,
                                 method='random_selection_new',
                                 num_new_to_add=numberofnewstatestoadd)
    ansatzlist.append(ansatz)
示例#2
0
def big_ass_loop(delta,Gamma,mu, observable_obj_list):
    """
    Here, observable_obj_list refers to a list of observable objects
    """
    hamiltonian = generate_XXZ_hamiltonian(num_qubits, delta)
    gammas, L_terms = generate_nonlocaljump_gamma_and_Lterms(num_qubits,Gamma,mu)
    ansatz = acp.initial_ansatz(num_qubits)
    #get the steady state using qutip(lol)
    qtp_hamiltonian = qutip.Qobj(hamiltonian.to_matrixform())
    qtp_Lterms = [qutip.Qobj(i.to_matrixform()) for i in L_terms]
    qtp_C_ops = [np.sqrt(gammas[i]) * qtp_Lterms[i] for i in range(len(qtp_Lterms))]
    qtp_rho_ss = qutip.steadystate(qtp_hamiltonian, qtp_C_ops,method='iterative-gmres')

    #compute the theoretical observable expectation values
    observable_matrixforms = [observable.to_matrixform() for observable in observable_obj_list]
    theoretical_expectation_values = [np.trace(qtp_rho_ss.full() @ observable_matform) for observable_matform in observable_matrixforms]

    #%%
    #compute GQAS matrices
    fidelity_results = dict()
    observable_expectation_results = dict()
    for k in range(1, uptowhatK + 1):
        print('##########################################')
        print('K = ' +str(k))
        # max_k_val = k
        #Generate Ansatz for this round
        if random_selection_new:
            ansatz = acp.gen_next_ansatz(ansatz, hamiltonian, num_qubits,method='random_selection_new',num_new_to_add=numberofnewstatestoadd)
        else:
            ansatz = acp.gen_next_ansatz(ansatz, hamiltonian, num_qubits)
        O_matrices_uneval = []
        for observable in observable_obj_list:
            O_matrix_uneval = mcp.unevaluatedmatrix(num_qubits, ansatz, observable, "O")
            O_matrices_uneval.append(O_matrix_uneval)
        E_mat_uneval = mcp.unevaluatedmatrix(num_qubits, ansatz, hamiltonian, "E")
        D_mat_uneval = mcp.unevaluatedmatrix(num_qubits, ansatz, hamiltonian, "D")

        if optimizer == 'feasibility_sdp':
            R_mats_uneval = []
            F_mats_uneval = []
            for thisL in L_terms:
                R_mats_uneval.append(mcp.unevaluatedmatrix(num_qubits,ansatz,thisL,"D"))
                thisLdagL = hcp.multiply_hamiltonians(hcp.dagger_hamiltonian(thisL),thisL)
                F_mats_uneval.append(mcp.unevaluatedmatrix(num_qubits,ansatz,thisLdagL,"D"))
        
        #Here is where we should be able to specify how to evaluate the matrices.
        #However only the exact method (classical matrix multiplication) has been
        #implemented so far
        if use_qiskit:
            E_mat_evaluated = E_mat_uneval.evaluate_matrix_with_qiskit_circuits(expectation_calculator)
            D_mat_evaluated = D_mat_uneval.evaluate_matrix_with_qiskit_circuits(expectation_calculator)
            O_matrices_evaluated = [i.evaluate_matrix_with_qiskit_circuits(expectation_calculator) for i in O_matrices_uneval]
        else:
            E_mat_evaluated = E_mat_uneval.evaluate_matrix_by_matrix_multiplicaton(initial_state)
            D_mat_evaluated = D_mat_uneval.evaluate_matrix_by_matrix_multiplicaton(initial_state)
            O_matrices_evaluated = [i.evaluate_matrix_by_matrix_multiplicaton(initial_state) for i in O_matrices_uneval]
        if optimizer == 'feasibility_sdp':
            R_mats_evaluated = []
            for r in R_mats_uneval:
                if use_qiskit:
                    R_mats_evaluated.append(r.evaluate_matrix_with_qiskit_circuits(expectation_calculator))
                else:
                    R_mats_evaluated.append(r.evaluate_matrix_by_matrix_multiplicaton(initial_state))
            F_mats_evaluated = []
            for f in F_mats_uneval:
                if use_qiskit:
                    F_mats_evaluated.append(f.evaluate_matrix_with_qiskit_circuits(expectation_calculator))
                else:
                    F_mats_evaluated.append(f.evaluate_matrix_by_matrix_multiplicaton(initial_state))

        ##########################################
        #Start of the classical post-processing. #
        ##########################################
        if optimizer == 'feasibility_sdp':
            IQAE_instance = pp.IQAE_Lindblad(num_qubits, D_mat_evaluated, E_mat_evaluated,R_matrices = R_mats_evaluated,F_matrices = F_mats_evaluated,gammas = gammas)
        else:
            IQAE_instance = pp.IQAE_Lindblad(num_qubits, D_mat_evaluated, E_mat_evaluated)


        IQAE_instance.define_optimizer(optimizer, eigh_invcond=eigh_inv_cond,eig_invcond=eig_inv_cond,degeneracy_tol=degeneracy_tol,sdp_tolerance_bound=sdp_tolerance_bound)

        IQAE_instance.evaluate()
        # IQAE_instance.evaluate(kh_test=False)
        #all_energies,all_states = IQAE_instance.get_results_all()
        result_dictionary = pp.analyze_density_matrix(num_qubits,initial_state,IQAE_instance,E_mat_evaluated,ansatz,hamiltonian,gammas,L_terms,qtp_rho_ss,O_matrices_evaluated)
        observable_expectation_results[k] = result_dictionary['observable_expectation']
        fidelity_results[k] = result_dictionary['fidelity']
            #if round(fidelity, 6) == 1:
            #    print("breaking loop as fidelity = 1 already")
            #    #raise(RuntimeError("Fidelity = 1!"))
            #    break
    #print('JON: Got %s results'%len(fidelity_results))
    return (observable_expectation_results, theoretical_expectation_values, fidelity_results)