def P2_update_coefficients(num_nodes, dim, graph_type, cmat_in):
    dim_list = list(range(0, dim))

    numA, numB = assign_nodes(num_nodes, graph_type)

    normK = 0
    for x in range(0, dim**numB):
        for y in range(0, dim**numA):
            for z in range(0, y):
                normK += cmat_in[y, x] * cmat_in[z, x] + cmat_in[
                    z, x] * cmat_in[y, x]
            normK += (cmat_in[y, x])**2

    indices = list(product(dim_list, repeat=numA))  #all labels
    coef_mat = np.zeros((dim**numA, dim**numB))  #blank coef matrix
    for x in range(dim**numA):
        controlA = np.array(indices[x])
        for y in range(dim**numB):

            for row_muA in range(dim**numA):
                muA = np.array(indices[row_muA])
                nuA = np.add((dim - 1) * muA, controlA) % dim
                #get row corresponding to nuA
                row_nuA = match_labA_to_indA(dim, nuA)
                #add to coefficient
                coef_mat[x, y] += (cmat_in[row_muA, y] *
                                   cmat_in[row_nuA, y]) / (normK)

    return normK, coef_mat
def P1_update_coefficients(num_nodes, dim, graph_type, cmat_in):
    dim_list = list(range(dim))

    numA, numB = assign_nodes(num_nodes,
                              graph_type)  #determines node bi-partition

    normK = 0
    for x in range(0, dim**numA):
        for y in range(0, dim**numB):
            for z in range(0, y):
                normK += cmat_in[x, y] * cmat_in[x, z] + cmat_in[
                    x, z] * cmat_in[x, y]
            normK += (cmat_in[x, y])**2

    #Application of measurement condition
    indices = list(product(dim_list, repeat=numB))
    coef_mat = np.zeros((dim**numA, dim**numB))
    for x in range(dim**numA):
        for y in range(dim**numB):
            controlB = np.array(indices[y])

            for col_muB in range(dim**numB):
                muB = np.array(indices[col_muB])
                nuB = np.add((dim - 1) * muB, controlB) % dim
                #get col corresponding to nuB
                col_nuB = match_labB_to_indB(dim, nuB)
                #add to coefficient
                coef_mat[x, y] += (cmat_in[x, col_muB] *
                                   cmat_in[x, col_nuB]) / (normK)

    return normK, coef_mat
Beispiel #3
0
def noisy_protocol_P2(num_nodes, dim, graph_type, cmat, param):

    #turn one state input into two state input
    cmat = np.kron(cmat, cmat)
    numA, numB = assign_nodes(num_nodes,
                              graph_type)  #determines node bi-partition
    #get adj_mat
    if graph_type == 'GHZ':
        adj_mat = get_GHZ_adj(num_nodes)
    elif graph_type == 'line':
        adj_mat = get_lin_adj(num_nodes)
    else:
        print('Supported graph types are GHZ and line')
        return

    #do all noisy gates of P1
    for x in range(1, num_nodes + 1):
        if x <= numA:
            set = 'sA'
            operation = 'lower'
        else:
            set = 'sB'
            operation = 'raise'
        cmat = noisy_TQG(dim, numA, numB, adj_mat, operation, x, cmat, set,
                         param)

    #'measure' & 'post-select' --> Use the coefficient map for general states
    normK, cmat = post_measurement_state_update(
        dim, numA, numB, cmat, 'P2')  #input 2 states, output 1 state

    return normK, cmat
def oneParam_min_fidelity(dim, num_nodes, graph_type, subP):
    numA, numB = assign_nodes(num_nodes, graph_type)

    if subP == 'P1':
        critX = (dim**num_nodes - 2 * dim**numA + 1) / (
            1 - dim**num_nodes - dim**numA + dim**(num_nodes + numA))
    elif subP == 'P2':
        critX = (dim**num_nodes - 2 * dim**numB + 1) / (
            1 - dim**num_nodes - dim**numB + dim**(num_nodes + numB))

    return critX
Beispiel #5
0
def single_qudit_through_channel(dim, num_nodes, graph_type, param):

    numA, numB = assign_nodes(num_nodes, graph_type)

    if graph_type == 'GHZ':
        adj_mat = get_GHZ_adj(num_nodes)
    elif graph_type == 'line':
        adj_mat = get_lin_adj(num_nodes)

    coef_mat = perfect_coef_mat(dim, numA, numB)

    coef_mat = qudit_through_channel(dim, numA, numB, adj_mat, 1, coef_mat,
                                     param)

    return coef_mat
Beispiel #6
0
def state_through_channel(dim, num_nodes, graph_type, param):

    numA, numB = assign_nodes(num_nodes, graph_type)

    if graph_type == 'GHZ':
        adj_mat = get_GHZ_adj(num_nodes)
    elif graph_type == 'line':
        adj_mat = get_lin_adj(num_nodes)

    coef_mat = perfect_coef_mat(dim, numA, numB)

    for x in range(1, num_nodes + 1):
        coef_mat = qudit_through_channel(dim, numA, numB, adj_mat, x, coef_mat,
                                         param)

    return coef_mat
def get_input_coefficients(num_nodes, dim, graph_type, input_type, param):

    numA, numB = assign_nodes(num_nodes, graph_type)

    #set coefficients
    if input_type == 'oneParam':

        filename = '../oneParam_Graph_States/{}_{}_{}_{}.txt'.format(
            dim, num_nodes, graph_type, param)
        if os.path.isfile(filename):
            coef_mat = np.loadtxt(filename).reshape(dim**numA, dim**numB)
        else:
            print('generate')
            #rows associated with A labels
            #columns with B labels
            coef_mat = np.zeros((dim**numA, dim**numB))

            coef_mat[0, 0] = param + (1 - param) / (dim**num_nodes)

            for x in range(0, dim**numA):
                for y in range(0, dim**numB):
                    if x == 0 and y == 0:
                        continue
                    else:
                        coef_mat[x, y] = (1 - param) / (dim**num_nodes)

    elif input_type == 'DP':
        pstring = str(param)
        filename = '../Depolarized_Graph_States/{}_{}_{}_{}.txt'.format(
            dim, num_nodes, graph_type, pstring)
        if os.path.isfile(filename):
            coef_mat = np.loadtxt(filename).reshape(dim**numA, dim**numB)
        else:
            coef_mat = state_through_channel(dim, num_nodes, graph_type, param)

    elif input_type == 'SQWN':
        pstring = str(param)
        filename = '../Single_Qudit_White_Noise/{}_{}_{}_{}.txt'.format(
            dim, num_nodes, graph_type, pstring)
        if os.path.isfile(filename):
            coef_mat = np.loadtxt(filename).reshape(dim**numA, dim**numB)
        else:
            coef_mat = single_qudit_through_channel(dim, num_nodes, graph_type,
                                                    param)

    return coef_mat
def save_oneParam_coefficients(num_nodes, dim, graph_type, param):
    numA, numB = assign_nodes(num_nodes, graph_type)

    coef_mat = np.zeros((dim**numA, dim**numB))
    coef_mat[0, 0] = param + (1 - param) / (dim**num_nodes)

    for x in range(0, dim**numA):
        for y in range(0, dim**numB):
            if x == 0 and y == 0:
                continue
            else:
                coef_mat[x, y] = (1 - param) / (dim**num_nodes)

    filename = '../oneParam_Graph_States/{}_{}_{}_{}.txt'.format(
        dim, num_nodes, graph_type, param)
    if not os.path.isfile(filename):
        afile = open(filename, 'w')
        for row in coef_mat:
            np.savetxt(afile, row)

        afile.close()
    return