Ejemplo n.º 1
0
def post_measurement_state_update(dim, numA, numB, cmat_in, subP):

    dim_list = np.arange(dim)
    new_coef_mat = complex(1, 0) * np.zeros((dim**numA, dim**numB))

    normK = 0

    if subP == 'P1':
        indA2 = 0
        #Application of measurement condition
        for indA1 in range(dim**numA):  #fix row of updated state
            for indB1 in range(dim**numB):  #fix col of updated state
                for indB2 in range(
                        dim**numB):  #loop through other coefficients
                    row, col = index_convert(dim, numA, numB, indA1, indB1,
                                             indA2, indB2)
                    new_coef_mat[indA1, indB1] += cmat_in[row, col]
                    normK += cmat_in[row, col]  #calculate normK while updating
        new_coef_mat = new_coef_mat / normK

    elif subP == 'P2':
        indB2 = 0
        #Application of measurement condition
        for indA1 in range(dim**numA):  #fix row of updated state
            for indB1 in range(dim**numB):  #fix col of updated state
                for indA2 in range(
                        dim**numA):  #loop through other coefficients
                    row, col = index_convert(dim, numA, numB, indA1, indB1,
                                             indA2, indB2)
                    new_coef_mat[indA1, indB1] += cmat_in[row, col]
                    normK += cmat_in[row, col]  #calculate normK while updating
        new_coef_mat = new_coef_mat / normK

    return normK, new_coef_mat
Ejemplo n.º 2
0
def lowerA(dim, numA, numB, row, col, target_node, adj_mat, new_coef_mat,
           current_coef):

    cutAdjRow = adj_mat[target_node - 1, numA:(numA + numB)]
    cutBasisVec = getbasisR(numA + numB)[target_node - 1][0:numA]

    indA1, indA2, indB1, indB2 = get_two_state_indices(dim, numA, numB, row,
                                                       col)
    labB2 = list(product(np.arange(dim), repeat=numB))[indB2]
    labA2 = list(product(np.arange(dim), repeat=numA))[indA2]
    labA1 = list(product(np.arange(dim), repeat=numA))[indA1]

    for n in range(dim):
        outLabB2 = (labB2 + n * cutAdjRow) % dim
        indB2 = match_labB_to_indB(dim, outLabB2)
        for m in range(0, dim):
            outLabA1 = (labA1 + m * cutBasisVec) % dim
            indA1 = match_labA_to_indA(dim, outLabA1)
            cf = (1 / dim) * exp(
                (2 * pi * complex(0, 1) / dim) * ((n * labA2[target_node - 1] +
                                                   (dim - m * n)) % dim))

            new_row, new_col = index_convert(dim, numA, numB, indA1, indB1,
                                             indA2, indB2)
            new_coef_mat[new_row, new_col] += cf * current_coef

    return new_coef_mat
Ejemplo n.º 3
0
def qudit_through_channel(dim, numA, numB, adj_mat, target_node, state_copy,
                          coef_mat, param):

    input_coef_mat = np.copy(coef_mat)
    new_coef_mat = (1 - param) * np.copy(coef_mat)

    Alabels = list(product(np.arange(0, dim), repeat=numA))
    Blabels = list(product(np.arange(0, dim), repeat=numB))

    for x in range(dim**2):
        error_label = list(product(np.arange(0, dim), repeat=2))[x]

        for row in range(dim**(2 * numA)):
            for col in range(dim**(2 * numB)):

                indA1, indA2, indB1, indB2 = get_two_state_indices(
                    dim, numA, numB, row, col)
                current_coef = input_coef_mat[row, col]

                if state_copy == 'first':
                    if current_coef > 0:
                        labelIn = np.array(Alabels[indA1] + Blabels[indB1])

                        #create list of effected labels
                        altered = []

                        labelOut = label_update(dim, adj_mat, target_node,
                                                labelIn, error_label)

                        if compare_labels(labelOut, labelIn):
                            altered.append(labelOut)

                    #determine which coefficients need to change and change them
                    try:
                        for entry in range(np.shape(altered)[0]):
                            #graphs state basis label of coefficient to be updated
                            focus = altered[entry]
                            #get matrix indices of label
                            id_indA1, id_indB1 = match_label_to_index(
                                dim, numA, numB, focus)
                            #convert back to row and col of new_coef_mat
                            id_row, id_col = index_convert(
                                dim, numA, numB, id_indA1, id_indB1, indA2,
                                indB2)
                            #update coeficient matrix
                            new_coef_mat[id_row, id_col] += current_coef * (
                                param / (dim**2 - 1))
                    except UnboundLocalError:
                        continue

                elif state_copy == 'second':
                    if current_coef > 0:
                        labelIn = np.array(Alabels[indA2] + Blabels[indB2])

                        #create list of effected labels
                        altered = []

                        labelOut = label_update(dim, adj_mat, target_node,
                                                labelIn, error_label)

                        if compare_labels(labelOut, labelIn):
                            altered.append(labelOut)

                    try:
                        #determine which coefficients need to change and change them
                        for entry in range(np.shape(altered)[0]):
                            #graphs state basis label of coefficient to be updated
                            focus = altered[entry]
                            #get matrix indices of label
                            id_indA2, id_indB2 = match_label_to_index(
                                dim, numA, numB, focus)
                            #convert back to row and col of new_coef_mat
                            id_row, id_col = index_convert(
                                dim, numA, numB, indA1, indB1, id_indA2,
                                id_indB2)
                            #update coeficient matrix
                            new_coef_mat[id_row, id_col] += current_coef * (
                                param / (dim**2 - 1))
                    except UnboundLocalError:
                        continue

    return new_coef_mat