def get_expectation(alist,shots,qc,qbits,correction_matrix): # Obtain the expectation values of the Pauli string at each time step sigma_expectation = np.zeros([4],dtype=complex) for j in range(4): p = Program() p.wrap_in_numshots_loop(shots) ro = p.declare('ro','BIT',1) ansatz(p,qbits) propagate(p,alist,qbits) sigma_expectation[j] = measure(p,ro,j,qc,qbits,correction_matrix) return sigma_expectation
def measure_energy(alist,shots,qc,qbits,hm_list,correction_matrix): # Measure the energy at the end of each time step Energy = 0 Nterms = len(hm_list) for i in range(len(hm_list)): for hm in hm_list[i]: for j in range(len(hm[0])): p = Program() p.wrap_in_numshots_loop(shots) ro = p.declare('ro','BIT',1) ansatz(p,qbits) propagate(p,alist,qbits) Energy += hm[1][j]*measure(p,ro,hm[0][j],qc,qbits,correction_matrix) return Energy