def test_grover_cir_qubit_topology():
    init_machine = InitQMachine()
    machine = init_machine.m_machine
    x = machine.cAlloc()

    data = [0, 6, 7, 9, 4, 5, 13, 6]
    # data=[50, 6, 16, 19]
    measure_qubits = pq.QVec()
    grover_cir = pq.Grover(data, x == 6, machine, measure_qubits, 1)
    # print(grover_cir)

    topo_matrix = pq.get_double_gate_block_topology(grover_cir, machine)
    print(topo_matrix)
    print('----------------------------')
    draw_graph(topo_matrix)

    #method 1
    # topo_matrix = pq.del_weak_edge(topo_matrix)
    # print(topo_matrix)
    # print('----------------------------')
    #draw_graph(topo_matrix)

    #method 2
    sub_graph = pq.get_sub_graph(topo_matrix)
    optimizered_topo = pq.del_weak_edge2(topo_matrix, g_max_connect_degree,
                                         sub_graph)
    print(optimizered_topo[1])
    draw_graph(optimizered_topo[0])

    #method 3
    # sub_graph = pq.get_sub_graph(topo_matrix)
    # optimizered_topo = pq.del_weak_edge3(topo_matrix, sub_graph, 0.5, 0.5, 0.5)
    # print(optimizered_topo[1])
    # draw_graph(optimizered_topo[0])

    # for test
    # tmp_topo = pq.recover_edges(optimizered_topo[0], g_max_connect_degree, optimizered_topo[2])
    # draw_graph(tmp_topo)

    complex_points = pq.get_complex_points(optimizered_topo[0],
                                           g_max_connect_degree)

    complex_point_sub_graph = pq.split_complex_points(complex_points,
                                                      g_max_connect_degree,
                                                      optimizered_topo[0], 0)

    new_topology = pq.replace_complex_points(optimizered_topo[0],
                                             g_max_connect_degree,
                                             complex_point_sub_graph)
    draw_graph(new_topology)

    new_topology = pq.recover_edges(new_topology, g_max_connect_degree,
                                    optimizered_topo[2])
    draw_graph(new_topology)
    print(new_topology)

    b = pq.planarity_testing(new_topology)
    print(b)

    draw_graph(new_topology)
예제 #2
0
    def test_grover1(self):
        init_machine = InitQMachine()
        machine = init_machine.m_machine
        x = machine.cAlloc()

        data = [8, 7, 6, 0, 6, 3, 6, 4, 21, 15, 11, 11, 3, 9, 7]
        measure_qubits = pq.QVec()
        grover_cir = pq.Grover(data, x == 6, machine, measure_qubits, 1)

        # print(grover_cir)
        # draw_qprog(grover_cir, 'pic', filename='D:/cir_grover_1.jpg', verbose=True)
        result = pq.prob_run_dict(grover_cir, measure_qubits)
    def test_grover_cir_qubit_topology2(self):
        init_machine = InitQMachine()
        machine = init_machine.m_machine
        x = machine.cAlloc()

        data = [0, 6, 7, 9, 4, 5, 13, 6]
        measure_qubits = pq.QVec()
        grover_cir = pq.Grover(data, x == 6, machine, measure_qubits, 1)

        topo_matrix = pq.get_circuit_optimal_topology(grover_cir, machine,
                                                      g_max_connect_degree)

        b = pq.planarity_testing(topo_matrix)
예제 #4
0
    def test_grover2(self):
        init_machine = InitQMachine()
        machine = init_machine.m_machine
        x = machine.cAlloc()

        # data=[8, 7, 6, 0, 6, 3, 6, 4, 21, 15, 11, 11, 3, 9, 7]
        data = [2, 7, 5, 1]
        measure_qubits = pq.QVec()
        grover_cir = pq.Grover(data, x == 5, machine, measure_qubits, 1)
        grover_prog = pq.QProg()
        grover_prog.insert(grover_cir)
        measure_qubit_num = len(measure_qubits)
        c = machine.cAlloc_many(measure_qubit_num)
        for i in range(0, measure_qubit_num):
            grover_prog.insert(pq.Measure(measure_qubits[i], c[i]))

        # draw_qprog(grover_prog, 'pic', filename='D:/prog_grover_1.jpg', verbose=True)
        result = pq.run_with_configuration(grover_prog, c, shots=1000)