def run_several_latt(error_info, n_runs_total, init_state): ''' ''' #if output_folder[-1] != '/': output_folder += '/' #chp_loc = './chp_extended' #CHP_IO_files = False n_fails = 0 for n_run in xrange(n_runs_total): # create the supra-circuit and insert gates CNOT_circuits = qfun.create_latt_surg_CNOT(Is_after2q, initial_I, anc_parallel, EC_ctrl_targ, FT) for supra_gate in CNOT_circuits.gates: if supra_gate.gate_name == 'Logical_I' or supra_gate.gate_name == 'MeasureX': error.add_error(supra_gate.circuit_list[0], error_info) elif supra_gate.gate_name[:8] == 'Measure2' or supra_gate.gate_name[:5] == 'Joint': for in_gate in supra_gate.circuit_list[0].gates: if in_gate.gate_name[:7] == 'Partial': error.add_error(in_gate.circuit_list[0], error_info) elif in_gate.gate_name[:2] == 'EC': for in_gate2 in in_gate.circuit_list[0].gates: error.add_error(in_gate2.circuit_list[0], error_info) #brow.from_circuit(CNOT_circuits, True) # run the faulty circuit init_state_copy = init_state[0][:], init_state[1][:] fail = run_latt_surg_circ(init_state_copy, CNOT_circuits) if fail: n_fails += 1 return n_fails
def run_several_latt_fast(error_info, n_runs_total, init_state): ''' ''' n_fails = 0 for n_run in xrange(n_runs_total): # create the supra-circuit and insert gates CNOT_circuits = qfun.create_latt_surg_CNOT(Is_after2q, initial_I, anc_parallel, EC_ctrl_targ, FT) brow.from_circuit(CNOT_circuits, True) sys.exit(0) # shuffle gate indices rd.shuffle(one_q_gates) rd.shuffle(two_q_gates) selected_one_q_gates = one_q_gates[:n_errors[0]] selected_two_q_gates = two_q_gates[:n_errors[1]] # group the selected gates total_selected_gates = selected_one_q_gates + selected_two_q_gates gate_groups = [] for gate in total_selected_gates: in_group = False for group in gate_groups: for g in group: if g[:-1] == gate[:-1]: group.insert(0, gate) in_group = True break if not in_group: gate_groups += [[gate]] # insert errors for group in gate_groups: local_gates = [g[-1] for g in group] if len(group[0]) >= 2: faulty_circ = CNOT_circuits.gates[group[0][0]].circuit_list[0] if len(group[0]) >= 3: faulty_circ = faulty_circ.gates[group[0][1]].circuit_list[0] if len(group[0]) == 4: faulty_circ = faulty_circ.gates[group[0][2]].circuit_list[0] error.add_error_alternative(faulty_circ, error_info, 'Muyalon', local_gates) # run the faulty circuit init_state_copy = init_state[0][:], init_state[1][:] fail = run_latt_surg_circ(init_state_copy, CNOT_circuits) if fail: n_fails += 1 #print 'Fail', fail return n_fails
import sys import qcircuit_wrapper as qcirc import chper_wrapper as wrapper import qcircuit_functions as qfun import cross from visualizer import browser_vis as brow # code parameters oper = 'Shor' code = 'Steane' n_code = 7 bare = False # create the supra-circuit Is_after2q = False circuits = qfun.create_latt_surg_CNOT(Is_after2q) #faulty_gate = circuits[0].gates[37] #faulty_qubit = faulty_gate.qubits[1] #new_g = circuits[0].insert_gate(faulty_gate, [faulty_qubit], '', 'Y', False) #new_g.is_error = True #brow.from_circuit(circuits, True) #i = 0 #for supra_gate in circuits.gates: # i += 1 # print 'gate', i # print supra_gate.gate_name #sys.exit(0) chp_loc = './chp_extended' # create the initial state (|+> ctrl; |0> targ; all |0> anc)
elif in_gate1.gate_name[:2] == 'EC': for k in range(len(in_gate1.circuit_list[0].gates)): in_gate2 = in_gate1.circuit_list[0].gates[k] for l in range(len(in_gate2.circuit_list[0].gates)): in_gate3 = in_gate2.circuit_list[0].gates[l] if in_gate3.gate_name in faulty_gates_names: if len(in_gate3.qubits) == 1: single_qubit_gates.append((i, j, k, l)) elif len(in_gate3.qubits) == 2: two_qubit_gates.append((i, j, k, l)) return single_qubit_gates, two_qubit_gates CNOT_circuits = qfun.create_latt_surg_CNOT(Is_after2q, initial_I, anc_parallel, EC_ctrl_targ, FT) one_q_gates, two_q_gates = gates_list_CNOT(CNOT_circuits, error_dict.keys()) def run_several_latt_fast(error_info, n_runs_total, init_state): ''' ''' n_fails = 0 for n_run in xrange(n_runs_total): # create the supra-circuit and insert gates CNOT_circuits = qfun.create_latt_surg_CNOT(Is_after2q, initial_I, anc_parallel, EC_ctrl_targ, FT) brow.from_circuit(CNOT_circuits, True) sys.exit(0)
'IX', 'IY', 'IZ', 'XI', 'XX', 'XY', 'XZ', 'YI', 'YX', 'YY', 'YZ', 'ZI', 'ZX', 'ZY', 'ZZ' ] # create the initial state (|+> ctrl; |0> targ; all |0> anc) init_state_ctrl = wrapper.prepare_stabs_Steane('+X') init_state_targ = wrapper.prepare_stabs_Steane('+X') init_state_anc = wrapper.prepare_stabs_Steane('+Z') all_stabs = [init_state_ctrl[0]] + [init_state_targ[0]] + [init_state_anc[0]] all_destabs = [init_state_ctrl[1]] + [init_state_targ[1]] + [init_state_anc[1]] initial_state = qfun.combine_stabs(all_stabs, all_destabs) # create circuit #QEC_circ = corr.Flag_Correct.measure_XXlogical() #CNOT_circ = corr.Flag_Correct.latt_surg_CNOT(True) CNOT_circ = qfun.create_latt_surg_CNOT(False, True, True, False, True, True) #brow.from_circuit(CNOT_circ, True) #sys.exit(0) # Get list of all 1-q and 2-q gates one_q_gates, two_q_gates = wrapper.gates_list_CNOT(CNOT_circ, error_dict.keys()) #print one_q_gates subset = (0, 1) one_q_errors_type = ['Y'] n_one_q_errors = subset[0] n_two_q_errors = subset[1] total_indexes, total_errors = qfun.get_total_indexes_one_circ( subset, one_q_gates, two_q_gates, one_q_errors_type,
p_1q=p1, p_2q=p2, p_meas=p_meas, p_prep=p_prep, p_sm=p_sm, p_cross=p_cross, p_5q=p_5q) error_info = mc.read_error_info(error_dict) # create the initial state (|+> ctrl; |0> targ; all |0> anc) init_state_ctrl = wrapper.prepare_stabs_Steane('+%s'%init_state1) init_state_targ = wrapper.prepare_stabs_Steane('+%s'%init_state2) init_state_anc = wrapper.prepare_stabs_Steane('+Z') all_stabs = [init_state_ctrl[0]]+[init_state_targ[0]]+[init_state_anc[0]] all_destabs = [init_state_ctrl[1]]+[init_state_targ[1]]+[init_state_anc[1]] initial_state = qfun.combine_stabs(all_stabs, all_destabs) # create the circuit latt_circ = qfun.create_latt_surg_CNOT(False,True,True,False,True,True,True) #brow.from_circuit(latt_circ, True) #sys.exit(0) # Define the list of error-prone gates # For now, we have 6 groups: (a) preps and meas, (b) MS2, (c) I_idle, (d) I_cross, # (e) 1-q gates, (f) MS5 gates_indices = wrapper.gates_list_CNOT_general(latt_circ, faulty_groups) # run the circuit def run_circ(CNOT_circ_copy, chp_loc): ''' ''' ion = True