Esempio n. 1
0
def run_latt_surg_circ(init_state, circuits):

    supra_circ = qcirc.CNOT_latt_surg(init_state, circuits, code, chp_loc)
    supra_circ.run_all_gates()

    final_stabs = supra_circ.state[0][:]
    final_destabs = supra_circ.state[1][:]

    # do perfect EC on ctrl and target logical qubits
    corr_circ = qfun.create_EC_subcircs(code, False, False, False, True)
    corr_circ2 = qfun.create_EC_subcircs(code, False, False, False, True)
    corr_circ.join_circuit_at(range(n_code, 2 * n_code), corr_circ2)

    final_state = (final_stabs, final_destabs)
    bare_anc = True
    supra_circ = qcirc.CNOT_latt_surg(final_state, corr_circ, code, chp_loc,
                                      bare_anc)
    supra_circ.run_all_gates()

    corr_stabs = supra_circ.state[0]

    # Determine if a failure has occurred
    fail = False
    for stab in corr_stabs:
        if stab[0] == '-':
            fail = True
            break

    return fail
Esempio n. 2
0
def run_QEC_d3(init_state, QEC_circ_list, chp_loc, alternating, decoder='old'):
    '''
    '''

    QEC_object = qwrap.QEC_with_flags(init_state, QEC_circ_list[:], chp_loc)
    supra_gates = QEC_object.run_stabilizers_high_indet_ion(
        0, alternating, 'any', decoder)

    final_stabs, final_destabs = QEC_object.stabs[:], QEC_object.destabs[:]

    # Determine if there is an error (both failures and correctable errors)
    final_error = False
    for stab in final_stabs:
        if stab[0] != '+':
            final_error = True
            break

    # Do perfect EC on the final state
    corr_circ = qfun.create_EC_subcircs('Steane', False, False, False, True)
    final_state = (final_stabs, final_destabs)
    bare_anc = True
    supra_circ = qwrap.CNOT_latt_surg(final_state, corr_circ, 'Steane',
                                      chp_loc, bare_anc)
    supra_circ.run_all_gates()
    corr_stabs = supra_circ.state[0]

    # Determine if a failure has occured.
    fail = False
    for stab in corr_stabs:
        if stab[0] != '+':
            fail = True
            break

    return final_error, fail, supra_gates
Esempio n. 3
0
def run_CNOT(init_state, CNOT_circ, chp_loc):
    '''
    First version
    '''

    # Temporary fix:  CNOT_circ is really a 1-element list
    CNOT_circ = c.Encoded_Gate('Transversal_CNOT', CNOT_circ).circuit_wrap()

    CNOT_object = qcirc.Supra_Circuit(init_state, CNOT_circ, code, chp_loc)
    CNOT_gate = CNOT_circ.gates[0]

    out_dict = CNOT_object.run_one_oper(CNOT_gate)
    final_stabs, final_destabs = CNOT_object.state[0][:], CNOT_object.state[1][:]

    # Determine if there is an error (both failures and correctable errors)
    final_errorX, final_errorZ = False, False
    for stab in final_stabs:
        if stab[0] == '-':
            if 'Z' in stab:
                final_errorX = True
            elif 'X' in stab:
                final_errorZ = True
            #break

    # Do perfect EC on the final state
    corr_circ = qfun.create_EC_subcircs(code, False, False, False, True)
    corr_circ2 = qfun.create_EC_subcircs(code, False, False, False, True)
    corr_circ.join_circuit_at(range(n_code,2*n_code), corr_circ2)

    final_state = (final_stabs, final_destabs)
    bare_anc = True
    supra_circ = qcirc.CNOT_latt_surg(final_state, corr_circ, code, chp_loc, bare_anc)
    supra_circ.run_all_gates()
    corr_stabs = supra_circ.state[0]

    # Determine if a failure has occurred
    failX, failZ = False, False
    for stab in corr_stabs:
        if stab[0] == '-':
            if 'Z' in stab:
                failX = True
            elif 'X' in stab:
                failZ = True
            #break

    return final_errorX, final_errorZ, failX, failZ
Esempio n. 4
0
def run_several_latt_fast_QEC_rep3(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
        QECd5_circ = qfun.create_EC_subcircs('d5color', Is_after_two,
                                             initial_I)

        # 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]]

        #print selected_one_q_gates
        #print selected_two_q_gates

        # 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 = QECd5_circ.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_QECd5(init_state_copy, QECd5_circ)
        if fail: n_fails += 1

        #print 'Fail', fail

    return n_fails
Esempio n. 5
0
def run_circ(CNOT_circ_copy, chp_loc):
    '''
    '''
    ion = True
    initial_state_copy = copy.deepcopy(initial_state)
    latt_object = qcirc.CNOT_latt_surg(initial_state_copy, CNOT_circ_copy, 'Steane', chp_loc,
                                   False, ion)
    latt_object.run_all_gates()
    final_stabs, final_destabs = latt_object.state[0][:], latt_object.state[1][:]

    #print latt_object.total_subcircs_run
    #sys.exit(0)

    # Determine if there is an error (both failures and correctable errors)
    final_errorX, final_errorZ = False, False
    for stab in final_stabs:
        if stab[0] != '+':
            if 'Z' in stab:
                final_errorX = True
            elif 'X' in stab:
                final_errorZ = True

    # do perfect EC on ctrl and target logical qubits
    corr_circ = qfun.create_EC_subcircs('Steane', False, False, False, True)
    corr_circ2 = qfun.create_EC_subcircs('Steane', False, False, False, True)
    corr_circ.join_circuit_at(range(n_code,2*n_code), corr_circ2)

    final_state = (final_stabs[:], final_destabs[:])
    bare_anc = True
    supra_circ = qcirc.CNOT_latt_surg(final_state, corr_circ, 'Steane', chp_loc, bare_anc)
    supra_circ.run_all_gates()
    corr_stabs = supra_circ.state[0]

    # Determine if failure has occured
    failX, failZ = False, False
    for stab in corr_stabs:
        if stab[0] != '+':
            if 'Z' in stab:
                failX = True
            elif 'X' in stab:
                failZ = True

    return final_errorX, final_errorZ, failX, failZ, latt_object.total_subcircs_run
Esempio n. 6
0
def run_QECd5(init_state, QECcirc, bare_anc=True, rep=3):
    '''
    '''
    if bare_anc:
        q_oper = qwrap.QEC_d5(init_state, [QECcirc], chp_location)
        n_X, n_Z = q_oper.run_bare_anc(rep)

    else:
        q_oper = qwrap.QEC_d5(init_state, [QECcirc], chp_location)
        n_X, n_Z = q_oper.run_fullQEC_CSS()

    final_stabs = q_oper.stabs[:]
    final_destabs = q_oper.destabs[:]

    # do perfect EC
    corr_circ = qfun.create_EC_subcircs(code, False, False, False, True)
    #brow.from_circuit(corr_circ.gates[0].circuit_list[0].gates[0].circuit_list[0], True)

    corr_oper = qwrap.Quantum_Operation(
        [final_stabs, final_destabs],
        [corr_circ.gates[0].circuit_list[0].gates[0].circuit_list[0]],
        chp_location)
    out_dict = corr_oper.run_one_circ(0)
    X_stabs = [out_dict[i][0] for i in range(17, 17 + 8)]
    X_stabs_dec = qfun.binary_to_decimal(X_stabs)
    Z_err = d5color.Code.lookuptable_str[str(X_stabs_dec)]
    Z_err = [i if i == 'I' else 'Z' for i in Z_err]
    corr_state = qfun.update_stabs(final_stabs, final_destabs, Z_err)
    final_stabs, final_destabs = corr_state[0][:], corr_state[1][:]

    Z_stabs = [out_dict[i][0] for i in range(17 + 8, 17 + 16)]
    Z_stabs_dec = qfun.binary_to_decimal(Z_stabs)
    X_err = d5color.Code.lookuptable_str[str(Z_stabs_dec)]
    X_err = [i if i == 'I' else 'X' for i in X_err]
    corr_state = qfun.update_stabs(final_stabs, final_destabs, X_err)
    final_stabs, final_destabs = corr_state[0][:], corr_state[1][:]

    # Determine if failure has occured
    fail = False
    for stab in final_stabs:
        if stab[0] == '-':
            fail = True
            break

    return fail
Esempio n. 7
0
initial_I = True
QECd3_flags_circ = cor.Flag_Correct.generate_whole_QEC_Reichardt_special(True, 
                                                                         False,
                                                                         initial_I)
QEC_circ_list = []
for i in range(len(QECd3_flags_circ.gates)):
    QEC_circ_list += [QECd3_flags_circ.gates[i].circuit_list[0]]
one_q_gates, two_q_gates = wrapper.gates_list(QEC_circ_list, error_dict.keys())
n_oneq, n_twoq = len(one_q_gates), len(two_q_gates)
#print n_oneq
#print n_twoq
#sys.exit(0)

# diVincenzo new (only 2 reps)
QEC_circ = qfun.create_EC_subcircs('Steane', False, initial_I, False, False, 2)
QEC_circ = QEC_circ.gates[0].circuit_list[0]
QEC_circ_list = []
for i in range(len(QEC_circ.gates)):
    QEC_circ_list += [QEC_circ.gates[i].circuit_list[0]]
one_q_gates, two_q_gates = wrapper.gates_list(QEC_circ_list, error_dict.keys())
n_oneq_diVin_new, n_twoq_diVin_new = len(one_q_gates), len(two_q_gates)
#print '1-q surf17 =', n_oneq_diVin_new
#print '2-q surf17 =', n_twoq_diVin_new
#sys.exit(0)

# all flags (1 flag/stab)
steane_stabs = steane.Code.stabilizer_alt[:]
flags_sq = [[1,3]]
flags_list = [flags_sq for i in range(3)]
QEC_circ = cor.Flag_Correct.generate_whole_QEC_circ(2, steane_stabs, flags_list+flags_list,
Esempio n. 8
0
#    anc_destabs += [''.join(anc_destab)]
#init_state_anc = anc_stabs, anc_destabs

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]]
init_state = qfun.combine_stabs(all_stabs, all_destabs)

# run the CNOT lattice surgery (with no EC on ctrl or targ)
supra_circ = qcirc.CNOT_latt_surg(init_state, circuits, code, chp_loc)
supra_circ.run_all_gates()

final_stabs = supra_circ.state[0][:]
final_destabs = supra_circ.state[1][:]

# do perfect EC on ctrl and target logical qubits
corr_circ = qfun.create_EC_subcircs(code, False, False, False, True)
corr_circ2 = qfun.create_EC_subcircs(code, False, False, False, True)
corr_circ.join_circuit_at(range(n_code, 2 * n_code), corr_circ2)

#init_state_ctrl = wrapper.prepare_stabs_Steane('+X')
#init_state_targ = wrapper.prepare_stabs_Steane('+Z')
#all_stabs = [init_state_ctrl[0]]+[init_state_targ[0]]
#all_destabs = [init_state_ctrl[1]]+[init_state_targ[1]]
#init_state = qfun.combine_stabs(all_stabs, all_destabs)

final_state = (final_stabs, final_destabs)
bare_anc = True
supra_circ = qcirc.CNOT_latt_surg(final_state, corr_circ, 'Steane', chp_loc,
                                  bare_anc)
supra_circ.run_all_gates()
Esempio n. 9
0
def run_several_QEC_fast(error_info, n_runs_total, init_state, QEC_kind,
                         QEC_circ_list):
    '''
    '''

    did_run = 0
    n_final_errors = 0
    n_fails = 0
    n_supra_gates = 0

    for n_run in xrange(n_runs_total):

        if QEC_kind == 'surface17':

            fraction_of_circ = 4

            QEC_circ_list_copy = []
            for subcirc in QEC_circ_list:
                QEC_circ_list_copy += [copy.deepcopy(subcirc)]

            # Add the errors and decide to run
            errors_dict, carry_run, faulty_circs = wrapper.add_errors_fast_sampler_new(
                [one_q_gates, two_q_gates], n_errors, QEC_circ_list_copy,
                error_info, fraction_of_circ)

            #brow.from_circuit(QEC_circ_list_copy[0], True)
            #time.sleep(5)

        if QEC_kind == 'flag':

            fraction_of_circ = 4
            # create the supra-circuit and insert gates
            QEC_circ = cor.Flag_Correct.generate_whole_QEC_Reichardt_special(
                True, False, initial_I)

        elif QEC_kind == 'diVin':

            fraction_of_circ = 3
            # create the supra-circuit and insert gates
            QEC_circ = qfun.create_EC_subcircs('Steane', False, initial_I,
                                               False)
            QEC_circ = QEC_circ.gates[0].circuit_list[0]

        elif QEC_kind == 'diVin_new':

            fraction_of_circ = 4
            # create the supra-circuit and insert gates
            QEC_circ = qfun.create_EC_subcircs('Steane', False, initial_I,
                                               False, False, 2)
            QEC_circ = QEC_circ.gates[0].circuit_list[0]

        if QEC_kind != 'surface17':
            QEC_circ_list = []
            for log_gate in QEC_circ.gates:
                QEC_circ_list += [log_gate.circuit_list[0]]

            # Add the errors and decide to run
            errors_dict, carry_run, faulty_circs = wrapper.add_errors_fast_sampler_new(
                [one_q_gates, two_q_gates], n_errors, QEC_circ_list,
                error_info, fraction_of_circ)

        # Run
        if carry_run:
            did_run += 1
            final_error, fail, n_supra_local = run_QEC_d3(
                init_state, faulty_circs, QEC_kind)
            n_supra_gates += n_supra_local
            if final_error:
                n_final_errors += 1
            if fail:
                n_fails += 1
                #print errors_dict
                #for key in errors_dict:
                #    if errors_dict[key] != {}:
                #        brow.from_circuit(faulty_circs[key], True)
                #break

        else:
            n_supra_gates += 2 * len(QEC_circ_list) / fraction_of_circ

    return n_final_errors, n_fails, n_supra_gates
Esempio n. 10
0
def run_QEC_d3(init_state, QEC_circ_list, kind='flag'):
    '''
    kind: 'flag' or 'diVin'
    '''
    if kind == 'surface17':
        QEC_object = qwrap.QEC_d3(init_state, QEC_circ_list[:], chp_loc)
        n_X, n_Z = QEC_object.run_fullQEC_CSS_d3('surface17', True, False)
        n_supra_gates = n_X + n_Z

    elif kind == 'all_flags':
        QEC_object = qwrap.QEC_with_flags(init_state, QEC_circ_list[:],
                                          chp_loc)
        # In this case, n_supra_gates is not an integer.  It's a list of run subcircs.
        n_supra_gates = QEC_object.run_Reichardt_d3_one_flag_stab(
            'cheap', 'any')

    elif kind == 'flag':
        QEC_object = qwrap.QEC_with_flags(init_state, QEC_circ_list[:],
                                          chp_loc)
        QEC_object.run_all_Reichardt_d3(init_state)

    elif kind == 'diVin':
        QEC_object = qwrap.QEC_d3(init_state, QEC_circ_list[:], chp_loc)
        n_X, n_Z = QEC_object.run_fullQEC_CSS('Steane', False)
        n_supra_gates = n_X + n_Z

    elif kind == 'diVin_new':
        QEC_object = qwrap.QEC_d3(init_state, QEC_circ_list[:], chp_loc)
        n_X, n_Z = QEC_object.run_fullQEC_CSS('Steane', False, False)
        n_supra_gates = n_X + n_Z

    final_stabs, final_destabs = QEC_object.stabs[:], QEC_object.destabs[:]

    # Determine if there is an error (both failures and correctable errors)
    final_error = False
    for stab in final_stabs:
        if stab[0] != '+':
            final_error = True
            break

    # do perfect EC
    if kind == 'surface17':
        surface17_stabs = surf17.Code.stabilizers[:]
        corr_circ = cor.Bare_Correct.generate_rep_bare_meas(
            9, surface17_stabs, 2, False, True, False, False, False, True)
        corr_circ_list = []
        for supra_gate in corr_circ.gates:
            corr_circ_list += [supra_gate.circuit_list[0]]
        corr_object = qwrap.QEC_d3([final_stabs[:], final_destabs[:]],
                                   corr_circ_list[:], chp_loc)
        # don't matter 1 and don't matter 2
        dm1, dm2 = corr_object.run_fullQEC_CSS('surface17', True, False)
        corr_stabs = corr_object.stabs[:]

    else:
        corr_circ = qfun.create_EC_subcircs('Steane', False, False, False,
                                            True)
        final_state = (final_stabs, final_destabs)
        bare_anc = True
        supra_circ = qwrap.CNOT_latt_surg(final_state, corr_circ, 'Steane',
                                          chp_loc, bare_anc)
        supra_circ.run_all_gates()
        corr_stabs = supra_circ.state[0]

    # Determine if a failure has occured.
    fail = False
    for stab in corr_stabs:
        if stab[0] != '+':
            fail = True
            break

    return final_error, fail, n_supra_gates
Esempio n. 11
0
                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


#QECd5_circ = cor.Cat_Correct.EC_d5_color_code(initial_I, color_stabs, meas_errors,
#                                              Is_after_two, rep_w8, redun)
#one_q_gates, two_q_gates = gates_list_QECd5(QECd5_circ, error_dict.keys())

QECd5_FT1_3rep_circ = qfun.create_EC_subcircs('d5color', Is_after_two,
                                              initial_I)
#QECd5_FT1_5rep_circ = qfun.create_EC_subcircs('d5color', Is_after_two, initial_I,
#                                              False, False, 5)
one_q_gates, two_q_gates = gates_list_QECd5_bare_anc(QECd5_FT1_3rep_circ,
                                                     error_dict.keys())


def run_QECd5(init_state, QECcirc, bare_anc=True, rep=3):
    '''
    '''
    if bare_anc:
        q_oper = qwrap.QEC_d5(init_state, [QECcirc], chp_location)
        n_X, n_Z = q_oper.run_bare_anc(rep)

    else:
        q_oper = qwrap.QEC_d5(init_state, [QECcirc], chp_location)
Esempio n. 12
0
    sys.exit(0)

    QEC_object = qcirc.CNOT_latt_surg(initial_state, CNOT_circ_copy, 'Steane',
                                      chp_loc)
    QEC_object.run_all_gates()
    final_stabs, final_destabs = QEC_object.state[0][:], QEC_object.state[1][:]

    # Determine if there is an error (both failures and correctable errors)
    for stab in final_stabs:
        if stab[0] != '+':
            #print 'ERROR'
            final_error_count += 1
            break

    # do perfect EC on ctrl and target logical qubits
    corr_circ = qfun.create_EC_subcircs('Steane', False, False, False, True)
    corr_circ2 = qfun.create_EC_subcircs('Steane', False, False, False, True)
    corr_circ.join_circuit_at(range(n_code, 2 * n_code), corr_circ2)

    final_state = (final_stabs[:], final_destabs[:])
    bare_anc = True
    supra_circ = qcirc.CNOT_latt_surg(final_state, corr_circ, 'Steane',
                                      chp_loc, bare_anc)
    supra_circ.run_all_gates()
    corr_stabs = supra_circ.state[0]

    # Determine if failure has occured
    for stab in corr_stabs:
        if stab[0] != '+':
            final_failure_count += 1
            print 'ESTOY FEO'