Пример #1
0
def single(graph, p, it=0, worker=0):

    seed = te.init_random_seed(worker=worker, iteration=it)

    te.init_pauli(graph, pX=p)
    tc.measure_stab(graph)

    uff = uf.cluster_farmer(graph)
    uff.find_clusters()
    uff.grow_clusters(method="tree")
    uff.peel_clusters()
    logical_error = tc.logical_error(graph)
    tree_solved = True if logical_error == [False, False, False, False
                                            ] else False
    graph.reset()

    te.apply_random_seed(seed)
    te.init_pauli(graph, pX=p)
    tc.measure_stab(graph)
    uff = uf.cluster_farmer(graph)
    uff.find_clusters()
    uff.grow_clusters(method="list")
    uff.peel_clusters()
    logical_error = tc.logical_error(graph)
    list_solved = True if logical_error == [False, False, False, False
                                            ] else False
    graph.reset()

    return (tree_solved, list_solved, seed)
def plot_both(graph_t, graph_l, seed, p, saveanim=None):

    toric_plot = tp.lattice_plot(graph_t, plot_size=6, line_width=1.5)

    te.apply_random_seed(seed)
    te.init_pauli(graph_t, pX=float(p))
    te.apply_random_seed(seed)
    te.init_pauli(graph_l, pX=float(p))
    toric_plot.plot_errors()

    tc.measure_stab(graph_t, toric_plot)
    tc.measure_stab(graph_l)

    uf_plot_t = up.toric(graph_t,
                         toric_plot.f,
                         axn=2,
                         plot_size=10,
                         line_width=1.5,
                         plotstep_click=1)

    uf_plot_t.ax.legend().set_visible(False)
    uf_plot_l = up.toric(graph_l,
                         toric_plot.f,
                         axn=3,
                         plot_size=10,
                         line_width=1.5,
                         plotstep_click=1)

    axes = toric_plot.f.get_axes()
    axes[0].set_title("Peeling lattice")
    axes[1].set_title("tree peeling lattice")
    axes[2].set_title("list peeling lattice")

    uft = uf.cluster_farmer(graph_t, uf_plot_t, plot_growth=1, print_steps=1)
    ufl = uf.cluster_farmer(graph_l, uf_plot_l, plot_growth=1, print_steps=1)

    uft.find_clusters(plot_step=0, order="Vup-Hup")
    ufl.find_clusters(plot_step=0, order="Vup-Hup")

    grow_clusters(graph_t,
                  uft,
                  uf_plot_t,
                  graph_l,
                  ufl,
                  uf_plot_l,
                  plot_growth=1,
                  print_steps=1)

    uft.peel_clusters(plot_step=0)
    ufl.peel_clusters(plot_step=0)

    plot_final(toric_plot, graph_t, graph_l)
    # Measure logical operator
    graph_t.reset()
    graph_l.reset()
Пример #3
0
def plot_both(graph_u, graph_v, array):

    toric_plot = tp.lattice_plot(graph_u, plot_size=10, line_width=2)

    input_error_array(graph_u, array)
    input_error_array(graph_v, array)
    toric_plot.plot_errors()
    # Measure stabiliziers
    tc.measure_stab(graph_u, toric_plot)
    tc.measure_stab(graph_v)

    # Peeling decoder
    uf_plot_u = up.toric(
        graph_u, toric_plot.f, axn=2, plot_size=10, line_width=1.5, plotstep_click=1
    )
    uf_plot_v = up.toric(
        graph_v, toric_plot.f, axn=3, plot_size=10, line_width=1.5, plotstep_click=1
    )

    axes = toric_plot.f.get_axes()
    axes[0].set_title("Peeling lattice")
    axes[1].set_title("UBUCK peeling lattice")
    axes[2].set_title("VCOMB peeling lattice")

    uf.find_clusters(graph_u, uf_plot=uf_plot_u, plot_step=0, vcomb=0)
    uf.find_clusters(graph_v, uf_plot=uf_plot_v, plot_step=0, vcomb=1)

    grow_clusters(graph_u, uf_plot_u, graph_v, uf_plot_v, plot_step=0, print_steps=1)

    uf.peel_clusters(graph_u, uf_plot=uf_plot_u, plot_step=0)
    uf.peel_clusters(graph_v, uf_plot=uf_plot_v, plot_step=0)

    # Apply matching
    tc.apply_matching_peeling(graph_u)
    tc.apply_matching_peeling(graph_v)

    plot_final(toric_plot, graph_u, graph_v)

    # Measure logical operator
    graph_u.reset()
    graph_v.reset()
Пример #4
0
graph0 = go.init_toric_graph(size)
graph = go.init_toric_graph(size)

counter = 0
total = 0
while counter < 100:

    print(total)
    total += 1

    seed = te.init_random_seed()

    te.apply_random_seed(seed)
    te.init_pauli(graph0, pX, pZ)
    tc.measure_stab(graph0)
    matching = tc.get_matching_mwpm(graph0)
    tc.apply_matching_mwpm(graph0, matching)
    result0 = tc.logical_error(graph0)
    count0 = countmatching(graph0)

    te.apply_random_seed(seed)
    te.init_pauli(graph, pX, pZ)
    tc.measure_stab(graph)

    ufg = uf.cluster_farmer(graph,
                            plot_growth=0,
                            print_steps=0,
                            random_traverse=0,
                            intervention=0,
                            vcomb=0)
Пример #5
0
def countmatching(graph):
    count = 0
    for edge in graph.E.values():
        if edge.matching:
            count += 1
    return count


seed = '1576237986127575800'
graph0 = go.init_toric_graph(size)
toric_plot = tp.lattice_plot(graph0, plot_size=6, line_width=1)

te.apply_random_seed(seed)
te.init_pauli(graph0, pX, pZ, toric_plot=toric_plot)
tc.measure_stab(graph0, toric_plot)
matching = tc.get_matching_mwpm(graph0)
tc.apply_matching_mwpm(graph0, matching, toric_plot)
result0 = tc.logical_error(graph0)
count0 = countmatching(graph0)

graph = go.init_toric_graph(size)
toric_plot = tp.lattice_plot(graph, plot_size=6, line_width=1)
te.apply_random_seed(seed)
te.init_pauli(graph, pX, pZ, toric_plot=toric_plot)
tc.measure_stab(graph, toric_plot)
uf_plot = up.toric(graph,
                   toric_plot.f,
                   plot_size=6,
                   line_width=1,
                   plotstep_click=1)
Пример #6
0
def single(size, pX=0, graph0=None, graph1=None, worker=0, iter=0):
    """
    Runs the peeling decoder for one iteration
    """

    # size, pX, graph, worker, iter = 28, 0.09, None, 0, 0

    # Initialize lattice

    if graph0 is None:
        graph0 = go.init_toric_graph(size)
    else:
        graph0.reset()
    if graph1 is None:
        graph1 = go.init_toric_graph(size)
    else:
        graph1.reset()

    seed = te.init_random_seed(worker=worker, iteration=iter)
    te.init_pauli(graph0, pX)

    te.apply_random_seed(seed)
    te.init_pauli(graph1, pX)

    tc.measure_stab(graph0)
    tc.measure_stab(graph1)

    uf0 = uf.cluster_farmer(graph0)
    uf1 = uf.cluster_farmer(graph1)

    uf0.find_clusters()
    uf1.find_clusters()

    # Analyze clusters after bucket 0 growth
    uf0.tree_grow_bucket(graph0.buckets[0], 0)
    cl0 = cca.get_support2clusters(graph0, size, minl, maxl)

    uf1.list_grow_bucket(graph1.buckets[0], 0)
    cl1 = cca.get_support2clusters(graph1, size, minl, maxl)

    clist, normc0, normc1 = [], [], []
    for key, val in data_p.items():
        clist.append(key)
        normc0.append(val[(size, pX)][0][0])
        normc1.append(val[(size, pX)][0][1])

    count0 = get_count(cl0, clist, size)
    count1 = get_count(cl1, clist, size)

    num0, num1 = countp[(size, pX)]

    val0 = sum([
        d / (d + abs(c - d)**1.002)
        for d, c in [(n / num0, c) for n, c in zip(normc0, count0)] if d > 0
    ])
    val1 = sum([
        d / (d + abs(c - d)**1)
        for d, c in [(n / num1, c) for n, c in zip(normc1, count1)] if d > 0
    ])

    choice = "tree" if val0 > val1 else "list"

    if choice == "tree":
        uf0.grow_clusters(method="tree", start_bucket=1)
        uf0.peel_clusters()
        graph = graph0
    else:
        uf1.grow_clusters(method="list", start_bucket=1)
        uf1.peel_clusters()
        graph = graph1

    # Measure logical operator
    logical_error = tc.logical_error(graph)
    correct = 1 if logical_error == [False, False, False, False] else 0
    return correct, choice