def succprob_poly_withMC(graph, transm=0.9, MC_samples=1000, t_sampl_func=None, in_qubit=0, printing=False): """ Returns an analytical estimate (lower bound) of the success probability for recovering a qubit encoded in the graph, in the form of a polinomial of the form a_1 t^(e_11) (1-t)^(e_12) + a_2 t^(e_21) (1-t)^(e_22) + ... + a_n t^(e_n1) (1-t)^(e_n2) returning it in the form of the dictionary {(e_11, e_12): a_1, (e_21, e_22): a_2, ... , (e_n1, e_n2): a_n} """ gstate = GraphState(graph) poss_stabs_list = get_possible_stabs_meas(gstate, in_qubit) if t_sampl_func == None: trans_sampl_func = lambda t: transm else: trans_sampl_func = lambda t: t_sampl_func(t) success_measurements = [] for test_ix in range(MC_samples): # print(trans_sampl_func(transm)) decoding_succ, decoding_meas = MC_decoding(poss_stabs_list, trans_sampl_func(transm), in_qubit, printing=False, provide_measures=True) if decoding_succ: success_measurements.append(decoding_meas) ## filter out duplicates # print('success_measurements', success_measurements) success_meas_filter = list(set(success_measurements)) polynom_all_exponents = [(len(this_meas[0]), len(this_meas[1])) for this_meas in success_meas_filter] if printing: print("success_meas_filter :", success_meas_filter) print("polynom_all_exponents :", polynom_all_exponents) return dict(Counter(polynom_all_exponents))
def graphstate_from_nodes_and_edges(graph_nodes, graph_edges): graph = nx.Graph() graph.add_nodes_from(graph_nodes) graph.add_edges_from(graph_edges) return GraphState(graph)
############################## ### MAIN ### ############################## if __name__ == '__main__': import matplotlib.pyplot as plt ## index of the input qubit (output qubit is free) in_qubit = 0 ## define graph state # three graph branching = [2, 1] graph = gen_tree_graph(branching) gstate = GraphState(graph) ### fully connected graph # graph = gen_fullyconnected_graph(7) # gstate = GraphState(graph) ## get list of possible measurements to encode & decode the state poss_stabs_list = get_possible_stabs_meas(gstate, in_qubit) ############################################################################## ################################### SINGLE TEST ############################## ############################################################################## ## define channel transmission transmission = 0.7 decoding_succ = MC_decoding(poss_stabs_list,
import qecc as q # stab_gens = ["XZII", "ZXZI", "IZXZ", "IIZX"] # stab_gens = ["ZZII", "XXZI", "IZXZ", "IIZX"] ##H on first # stab_gens = ["ZXII", "XZZI", "IXXZ", "IIZX"] ##H on first and second # stab_gens = ["ZZXXX", "XXXXX", "XZZXX", "XXZZX", "XXXZZ"] # GHZ stab_gens = ["XZZXI", "IXZZX", "XIXZZ", "ZXIXZ", "ZZZZZ"] ## 5-qubit code # stab_gens = ["ZZIIIIIII", "ZIZIIIIII", "IIIZZIIII", "IIIZIZIII", "IIIIIIZZI", "IIIIIIZIZ", # "XXXXXXIII", "XXXIIIXXX", "ZIIIZIZII"] ## Shor code gen_list = q.PauliList(stab_gens) stab_state = StabState(gen_list) graph_equiv, adj_mat, clifford_transf, basis_change_mat = stab_to_graph( stab_state) graph_state = GraphState(graph_equiv) print('Adjacency matrix of equivalent graph state:') print(adj_mat) print('Local Clifford transformation:') print(clifford_transf) # SOME TARGET GRAPHS ######## 4 qubit line # graph_targ = nx.Graph() # graph_targ.add_nodes_from([0, 1, 2, 3]) # graph_targ.add_edges_from([(0, 1), (1, 2), (2, 3)]) ######## graph for 5-qubit star # graph_targ = nx.Graph()
global_phase = np.pi / 7 ### add Z rotation on first qubit theta = np.pi / 5 added_U = np.kron(np.array([[1, 0], [0, np.exp(1.j * theta)]]), np.identity(2**(qubits_num - 1))) ### print stuff? print_tests = False for edges_conf_ix, graph_edges in enumerate(all_graphs_by_edges): # print('Testing graph', edges_conf_ix, 'of', num_graphs) graph = nx.Graph() graph.add_nodes_from(graph_nodes) graph.add_edges_from(graph_edges) this_gstate = GraphState(graph) target_adjmat = this_gstate.adj_mat() vect_state0 = this_gstate.graph_vecstate() vect_state = added_U @ vect_state0 vect_state = np.exp(1.j * global_phase) * vect_state test_if_graph, Amat, _ = vector_is_graphstate(vect_state, print_error=False) if print_tests: print() print('target_adjmat:') print(target_adjmat) print('vect_state0') print(vect_state0)
def graphstate_from_nodes_and_edges(graph_nodes, graph_edges): return GraphState(graph_from_nodes_and_edges(graph_nodes, graph_edges))
full_new_lc_class = lc_equivalence_class( graph, fixed_node=input_qubit) obt_graphs = obt_graphs + full_new_lc_class used_rots = used_rots + [ rots_list for i in range(len(full_new_lc_class)) ] # print('Total class representatives number:', len(lc_class_representatives)) # print('Total graph number:', len(obt_graphs)) else: if not arreq_in_list(adj_mat, obt_graphs): # print("Got a NEW graph! Rotation sequence:", rots_list, " Local Z phases:", local_phases, " Applied hadamards: ", applied_hadamard) print(rots_list, local_phases, applied_hadamard) obt_graphs.append(adj_mat) used_rots.append(rots_list) plt.subplot() gstate = GraphState(nx.from_numpy_matrix(adj_mat)) gstate.image(with_labels=True) plt.show() if not include_lc: obt_graphs = [nx.from_numpy_matrix(this_A) for this_A in obt_graphs] # plot all obtained graphs num_graphs = len(obt_graphs) n = int(np.sqrt(num_graphs)) n_plot_rows = n n_plot_cols = num_graphs / n if not isinstance(n_plot_cols, int): n_plot_cols = int(n_plot_cols) + 1 # for code_ix in range(num_graphs):