def CreateLabelViaAstar(CNOT_list, G, q_phy, q_log, shortest_length_G, possible_swap_combination): ''' create minimum SWAP cost for a single layer via Astar ''' DG = ct.OperationToDependencyGraph(CNOT_list) cir_phy = QuantumCircuit(q_phy) initial_map = Map(q_log, G) res = ct.AStarSearch(q_phy, cir_phy, G, DG, initial_map, shortest_length_G, possible_swap_combination=possible_swap_combination) return res[0]
def CreateLabelViaZHOU(CNOT_list, G, q_phy, q_log, shortest_length_G, shortest_path_G): ''' create minimum SWAP cost for a single layer via our proposed method ''' DG = ct.OperationToDependencyGraph(CNOT_list) cir_phy = QuantumCircuit(q_phy) initial_map = Map(q_log, G) res = ct.RemoteCNOTandWindowLookAhead(q_phy, cir_phy, G, DG, initial_map, shortest_length_G, shortest_path_G, depth_lookahead=1, use_prune=False, draw=False, DiG=None, level_lookahead=None) return res[0]
shortest_length_G = dict(nx.shortest_path_length(G, source=None, target=None, weight=None, method='dijkstra')) if draw_architecture_graph == True: nx.draw(G, with_labels=True) ''' '''generate CNOT operation''' total_CNOT = res_qasm[1][3] '''generate dependency graph''' DG = res_qasm[1][0] if draw_DG == True: nx.draw(DG, with_labels=True) '''generate party map for CNOT circuits''' if use_steiner_tree_and_remoteCNOT == 1 or use_UDecompositionFullConnectivity == 1 or use_UDecompositionFullConnectivityPATEL == 1: party_map = np.eye(num_vertex) ct.PerformOperationCNOTinPartyMap(party_map, total_CNOT) new_G = ct.AllocateVertexToPartyMap(G, num_vertex) '''initialize map from logical qubits to physical qubits''' initial_map_list = results[file[0:-5]]['initial map'][repeat] initial_map = Map(q_log, G, initial_map_list) '''draw logical quantum circuits''' if draw_logical_circuit == True: print(cir_log.draw()) '''search using specific methods''' if use_naive_search == True: cost_naive = ct.NaiveSearch(q_phy, QuantumCircuit(q_phy), G, copy.deepcopy(DG), initial_map, shortest_path_G, draw_physical_circuit_niave) y_label_naive.append(cost_naive) if use_HeuristicGreedySearch == True: cost_HeuristicGreedySearch = ct.HeuristicGreedySearch( q_phy, QuantumCircuit(q_phy), G, copy.deepcopy(DG), initial_map, shortest_length_G, possible_swap_combination, draw_physical_circuit_HeuristicGreedySearch) y_label_HeuristicGreedySearch.append(cost_HeuristicGreedySearch)
total_CNOT = res_qasm[1][3] '''generate dependency graph''' DG = res_qasm[1][0] if draw_DG == True: nx.draw(DG, with_labels=True) '''generate party map for CNOT circuits''' if use_steiner_tree_and_remoteCNOT == 1 or use_UDecompositionFullConnectivity ==1 or use_UDecompositionFullConnectivityPATEL ==1: party_map = np.eye(num_vertex) ct.PerformOperationCNOTinPartyMap(party_map, total_CNOT) new_G = ct.AllocateVertexToPartyMap(G, num_vertex) '''initialize map from logical qubits to physical qubits''' '''1-1, 2-2 ...''' if initial_mapping_control == 0: initial_map = Map(q_log, G) '''for circuit with only 10 qubit, we mannually map last 5 qubits to the down line''' if initial_mapping_control == 2: initial_map = Map(q_log, G) initial_map.RenewMapViaExchangeCod(9, 15) initial_map.RenewMapViaExchangeCod(8, 14) initial_map.RenewMapViaExchangeCod(7, 13) initial_map.RenewMapViaExchangeCod(6, 12) '''specific initial map through vertex list in AG''' # ============================================================================= # initial_map = Map(q_log, G, [1,2,3,8,7,6,11,12,13,16,17,18,4,9,14,19]) # ============================================================================= '''optimized initial mapping''' if initial_mapping_control == 1: map_res = ct.FindInitialMapping(DG, q_log, G, shortest_length_G[0]) initial_map = map_res[0]
'''calculate shortest path and its length''' ''' shortest_path_G = nx.shortest_path(G, source=None, target=None, weight=None, method='dijkstra') shortest_length_G = dict(nx.shortest_path_length(G, source=None, target=None, weight=None, method='dijkstra')) if draw_architecture_graph == True: nx.draw(G, with_labels=True) ''' '''generate CNOT operation''' total_CNOT = res_qasm[1][3] '''generate dependency graph''' DG = res_qasm[1][0] if draw_DG == True: nx.draw(DG, with_labels=True) '''initialize map from logical qubits to physical qubits''' '''1-1, 2-2 ...''' if initial_mapping_control == 0: t_s = time.time() initial_map = Map(q_log, G) t_e = time.time() '''for circuit with only 10 qubit, we mannually map last 5 qubits to the down line''' if initial_mapping_control == 2: initial_map = Map(q_log, G) initial_map.RenewMapViaExchangeCod(9, 15) initial_map.RenewMapViaExchangeCod(8, 14) initial_map.RenewMapViaExchangeCod(7, 13) initial_map.RenewMapViaExchangeCod(6, 12) '''specific initial map through vertex list in AG''' # ============================================================================= # initial_map = Map(q_log, G, [1,2,3,8,7,6,11,12,13,16,17,18,4,9,14,19]) # ============================================================================= '''optimized initial mapping''' if initial_mapping_control == 1: t_s = time.time()
''' '''calculate shortest path and its length''' ''' shortest_path_G = nx.shortest_path(G, source=None, target=None, weight=None, method='dijkstra') shortest_length_G = dict(nx.shortest_path_length(G, source=None, target=None, weight=None, method='dijkstra')) if draw_architecture_graph == True: nx.draw(G, with_labels=True) ''' '''generate CNOT operation randomly''' total_CNOT = ct.CreateCNOTRandomly(q_log, num_CNOT, cir_log) '''generate party map for CNOT circuits''' if use_steiner_tree_and_remoteCNOT == 1 or use_UDecompositionFullConnectivity == 1 or use_UDecompositionFullConnectivityPATEL == 1: party_map = np.eye(num_vertex) ct.PerformOperationCNOTinPartyMap(party_map, total_CNOT) new_G = ct.AllocateVertexToPartyMap(G, num_vertex) '''initialize map from logical qubits to physical qubits''' initial_map = Map(q_log, G) '''generate dependency graph''' DG = ct.OperationToDependencyGraph(total_CNOT) if draw_DG == True: nx.draw(DG, with_labels=True) '''draw logical quantum circuits''' if draw_logical_circuit == True: print(cir_log.draw()) '''search using specific methods''' if use_naive_search == True: cost_naive = ct.NaiveSearch(q_phy, QuantumCircuit(q_phy), G, copy.deepcopy(DG), initial_map, shortest_path_G, draw_physical_circuit_niave) y_label_naive.append(cost_naive) total_naive = total_naive + cost_naive if use_HeuristicGreedySearch == True: cost_HeuristicGreedySearch = ct.HeuristicGreedySearch(