def lindbladian_epc_analytical(U_dict: dict, proj: bool): real_cliffords = evaluate_sequences(U_dict, cliffords_decomp) lvls = int(np.sqrt(real_cliffords[0].shape[0])) projection = 'fulluni' fid_lvls = lvls if proj: projection = 'wzeros' fid_lvls = 2 ideal_cliffords = perfect_cliffords(lvls, projection) fids = [] for C_indx in range(24): C_real = real_cliffords[C_indx] C_ideal = tf_super( tf.constant( ideal_cliffords[C_indx], dtype=tf.complex128 ) ) ave_fid = tf_superoper_average_fidelity(C_real, C_ideal, lvls=fid_lvls) fids.append(ave_fid) infid = 1 - tf_ave(fids) return infid
def orbit_infid( U_dict, RB_number: int = 30, RB_length: int = 20, lindbladian=False, shots: int = None, seqs=None, noise=None ): if not seqs: seqs = single_length_RB(RB_number=RB_number, RB_length=RB_length) Us = evaluate_sequences(U_dict, seqs) infids = [] for U in Us: dim = int(U.shape[0]) psi_init = tf.constant(basis(dim, 0), dtype=tf.complex128) psi_actual = tf.matmul(U, psi_init) pop0 = tf_abs(psi_actual[0])**2 p1 = 1 - pop0 if shots: vals = tf.keras.backend.random_binomial( [shots], p=p1, dtype=tf.float64, ) # if noise: # vals = vals + (np.random.randn(shots) * noise) infid = tf.reduce_mean(vals) else: infid = p1 # if noise: # infid = infid + (np.random.randn() * noise) if noise: infid = infid + (np.random.randn() * noise) infids.append(infid) return tf_ave(infids)
def epc_analytical(U_dict: dict, index, dims, proj: bool): # TODO make this work with new index and dims gate = list(U_dict.keys())[0] U = U_dict[gate] num_gates = len(gate.split(":")) lvls = int(U.shape[0] ** (1 / num_gates)) fid_lvls = lvls if num_gates == 1: real_cliffords = evaluate_sequences(U_dict, cliffords_decomp) elif num_gates == 2: real_cliffords = evaluate_sequences(U_dict, cliffords_decomp_xId) projection = "fulluni" if proj: projection = "wzeros" fid_lvls = 2 ** num_gates ideal_cliffords = perfect_cliffords(str(lvls), proj=projection, num_gates=num_gates) fids = [] for C_indx in range(24): C_real = real_cliffords[C_indx] C_ideal = ideal_cliffords[C_indx] ave_fid = tf_average_fidelity(C_real, C_ideal, fid_lvls) fids.append(ave_fid) infid = 1 - tf_ave(fids) return infid
def lindbladian_epc_analytical(U_dict: dict, index, dims, proj: bool, cliffords=False): num_gates = len(dims) if cliffords: real_cliffords = evaluate_sequences(U_dict, [[C] for C in cliffords_string]) elif num_gates == 1: real_cliffords = evaluate_sequences(U_dict, cliffords_decomp) elif num_gates == 2: real_cliffords = evaluate_sequences(U_dict, cliffords_decomp_xId) ideal_cliffords = perfect_cliffords(lvls=[2] * num_gates, num_gates=num_gates) fids = [] for C_indx in range(24): C_real = real_cliffords[C_indx] C_ideal = tf_super( tf.constant(ideal_cliffords[C_indx], dtype=tf.complex128)) ave_fid = tf_superoper_average_fidelity(C_real, C_ideal, lvls=dims) fids.append(ave_fid) infid = 1 - tf_ave(fids) return infid
def epc_analytical(propagators: dict, index, dims, proj: bool, cliffords=False): # TODO check this work with new index and dims (double-check) num_gates = len(dims) if cliffords: real_cliffords = evaluate_sequences(propagators, [[C] for C in cliffords_string]) elif num_gates == 1: real_cliffords = evaluate_sequences(propagators, cliffords_decomp) elif num_gates == 2: real_cliffords = evaluate_sequences(propagators, cliffords_decomp_xId) ideal_cliffords = perfect_cliffords(lvls=[2] * num_gates, num_gates=num_gates) fids = [] for C_indx in range(24): C_real = real_cliffords[C_indx] C_ideal = tf.constant(ideal_cliffords[C_indx], dtype=tf.complex128) ave_fid = tf_average_fidelity(C_real, C_ideal, lvls=dims) fids.append(ave_fid) infid = 1 - tf_ave(fids) return infid