示例#1
0
def basic_dict1(sched, flags=[1,3], n_total=17, stabs=d5_stabs[:],
                extra_errors=[]):
    '''
    computes the basic dictionary when the stabilizer given by
    sched triggers a flag.  Basic dictionary means that we don't
    try to complete all the 2^8 syndromes, just the ones necessary
    to correct for 1-q and 2-q error events.  
    
    The second argument, flags, gives the location of the two-qubit 
    gates from the ancilla qubit to the flag qubit.  
    For example, [1,3] means that the first CNOT occurs before the 
    second gate and the second CNOT occurs before the third gate.
   
    extra_errors are other errors, apart from the 1-q erros, that
    can occur with probability O(p).  For example, when the octagon
    has flags [2,6], (0,1) and (6,7) are extra_errors.

    returns True, dict1  if it's possible to construct the dict
            False, {}    if it's not possible.
    '''

    sched = list(sched)

    dict1 = dict(basic_lookup)
    for extra_error in extra_errors:
        extra_bin = sched_fun.convert_to_binary(extra_error, n_total)
        in_dict, log_par, syn = sched_fun.can_correct(extra_bin[:], dict1, 
                                                      n_total, stabs[:])
        if not in_dict:
            dict1[syn] = extra_bin
        else:
            if log_par == 1:
                return False, {} 

    for i in range(flags[0], flags[1]+1):
        hook = sched[i : ]
        hook_bin = sched_fun.convert_to_binary(hook, n_total)
        for err in errors_0 + errors_1 + extra_errors:
            err_bin = sched_fun.convert_to_binary(err, n_total)
            comb_err = sched_fun.multiply_operators(hook_bin, err_bin)
            in_dict, log_par, syn = sched_fun.can_correct(comb_err[:], dict1,
                                                          n_total, stabs[:])
            if not in_dict:
                dict1[syn] = comb_err
            else:
                if log_par == 1:
                    return False, {} 
            
    return True, dict1
示例#2
0
def complete_lookup(lookup, n_qubits, stabs, initial_w=1):
    '''
    Takes in an incomplete lookup table and loops over all w-1, w-2, w-3, ...
    data errors until it fills in all the syndromes.
    '''

    n_syndromes = 2**(len(stabs))

    current_w = initial_w
    # loop iteratively until all syndromes are covered
    while len(lookup) < n_syndromes:

        print current_w
        print len(lookup)
        current_errors = lookup.values()[:]
        data_errors = errors_n(n_qubits, current_w)

        for data_err in data_errors:
            data_err_bin = sched_fun.convert_to_binary(data_err, n_qubits)
            for err in current_errors:
                comb_err = sched_fun.multiply_operators(
                    data_err_bin[:], err[:])
                in_dict, log_par, syn = sched_fun.can_correct(
                    comb_err[:], lookup, n_qubits, stabs[:])
                if not in_dict:
                    lookup[syn] = comb_err

        current_w += 1

    return lookup, current_w
示例#3
0
def hook_and_flag(sched_flags, err_locs, flag='f1', n_total=17):
    '''
    - sched_flags is a schedule with a flag.  For example:
    [2,3,'f1',5,6,9,10,'f1',13,14,'m1']
    - err_locs are the indexes of the locations of the errors
    - flag is the flag we are interested in, cause we might
    have more than two for the octagon.

    returns:  trigger (0 or 1), the hook error
    '''

    meas = 'm' + flag[1]
    flag_indexes = [i for i,q in enumerate(sched_flags) if q==flag]
    total_hook_bin = [0 for i in range(n_total)]
    trigger = 0
    for err_loc in err_locs:
        local_hook_flags = sched_flags[err_loc:]
        if local_hook_flags.count(flag)%2==1 or sched_flags[err_loc]==meas:
            trigger += 1
        local_hook = [q for q in local_hook_flags if type(q)==type(0)]
        local_hook_bin = sched_fun.convert_to_binary(local_hook, n_total)
        total_hook_bin = sched_fun.multiply_operators(total_hook_bin, 
                                                      local_hook_bin)

    return trigger%2, total_hook_bin
示例#4
0
def basic_dict2(sched1, flags1, sched2, flags2, n_total=17, stabs=d5_stabs[:]):
    '''
    '''

    sched1, sched2 = list(sched1), list(sched2)

    # (no hook)1 (no hook)2
    dict2 = {tuple([0 for i in range(len(stabs))]): tuple([0 for i in range(n_total)])}

    # (no hook)1 (hook)2  and  (hook)1 (no hook)2
    for combo in [[sched1, flags1], [sched2, flags2]]:
        flags = combo[1]
        for i in range(flags[0], flags[1]+1):
            hook = combo[0][i : ]
            hook_bin = sched_fun.convert_to_binary(hook, n_total)
            in_dict, log_par, syn = sched_fun.can_correct(hook_bin[:], dict2, 
                                                          n_total, stabs[:])
            if not in_dict:
                dict2[syn] = hook_bin
            else:
                if log_par == 1:
                    return False, {} 
    
    # (hook)1 (hook)2
    for i in range(flags1[0], flags1[1]+1):
        hook1 = sched1[i : ]
        hook1_bin = sched_fun.convert_to_binary(hook1, n_total)
        for j in range(flags2[0], flags2[1]+1):
            hook2 = sched2[j : ]
            hook2_bin = sched_fun.convert_to_binary(hook2, n_total)
            comb_err = sched_fun.multiply_operators(hook1_bin, hook2_bin)
            in_dict, log_par, syn = sched_fun.can_correct(comb_err[:], dict2, 
                                                          n_total, stabs[:])
            if not in_dict:
                dict2[syn] = comb_err
            else:
                if log_par == 1:
                    return False, {} 

    return True, dict2
示例#5
0
def all_lookups_one_schedule(sched_bare, flags=[[1,3]], n_total=17, stabs=color_code_stabs[:]):
    '''
    '''

    #print 'sched bare =', sched_bare
    #print 'flags = ', flags

    # First we add the flags to the schedule
    sched_flags = sched_fun.add_flags_to_sched(sched_bare, flags)

    #print 'sched flags =', sched_flags

    # Now we define the dictionary of lookup tables.
    # There's one lookup table for each flag combination
    lookups = {}
    for prod in it.product([0,1], repeat=len(flags)):
        err_weight = sum(prod)
        if err_weight == 0:
            lookups[prod] = dict(dict_noflag)
        elif err_weight == 1:
            lookups[prod] = dict(basic_lookup)
        elif err_weight > 1:
            lookups[prod] = dict(trivial_lookup)

    flag_names = ['f'+str(i+1) for i in range(len(flags))]
    
    
    # First we deal with the cases where we only had 1 error
    # on the ancilla
    dict_hooks = all_hooks(sched_flags, flag_names, 1)
    #print dict_hooks
    for trig_comb in dict_hooks:
        for hook in dict_hooks[trig_comb]:
            #print 'hook =', hook

            # for each hook we add all the possible w-1
            # errors on the data
            for data_err in errors_0 + errors_1:
                #print data_err
                data_err_bin = sched_fun.convert_to_binary(data_err, n_total)
                comb_err = sched_fun.multiply_operators(hook[:], data_err_bin[:])
                in_dict, log_par, syn = sched_fun.can_correct(comb_err[:],
                                                              lookups[trig_comb],
                                                              n_total,
                                                              stabs[:])
                if not in_dict:
                    lookups[trig_comb][syn] = comb_err[:]
                else:
                    if log_par == 1:
                        return False, {}


    # Secondly we deal with the cases where we had 2 errors
    # on the ancilla
    dict_hooks = all_hooks(sched_flags, flag_names, 2)
    for trig_comb in dict_hooks:
        for hook in dict_hooks[trig_comb]:
            in_dict, log_par, syn = sched_fun.can_correct(hook[:],
                                                          lookups[trig_comb],
                                                          n_total,
                                                          stabs[:])
            if not in_dict:
                lookups[trig_comb][syn] = hook[:]
            else:
                if log_par == 1:
                    return False, {}
               
    return True, lookups
示例#6
0
           ]

d5_stabs_good = [
              [2,3,6,5,9,10,14,13],
              [0,1,2,3],
              [0,2,4,5],
              [4,5,8,9],
              [8,9,12,13],
              [6,7,10,11],
              [10,11,14,15],
              [7,11,15,16]
]


logical_oper = range(n_total)
log_bin = sched_fun.convert_to_binary(logical_oper)
color_code_stabs = d5_stabs_good[:]

# Errors
errors_0 = [[]]
errors_1 = [[i] for i in range(n_total)]
errors_2 = []
for err2comb in it.combinations(range(n_total), 2):
    errors_2 += [list(err2comb)]
#for i in range(n_total):
#    for j in range(i+1, n_total):
#        errors_2 += [[i,j]]

total_errors = errors_0 + errors_1 + errors_2