MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / build_sub_graph

Function build_sub_graph

Extensions/QMapping/SabreQMapping.cpp:673–718  ·  view source on GitHub ↗

@brief 根据初始映射构建临时子图 * @param[in] const Mapping& 初始映射 * @param[in] ArchGraph::sRef 原始图 * @return 临时子图 */

Source from the content-addressed store, hash-verified

671 * @return 临时子图
672 */
673static ArchGraph::sRef build_sub_graph(const Mapping& init_mapping, const ArchGraph::sRef src_graph)
674{
675 const std::vector<uint32_t>& phy_partition = init_mapping; /* 物理连通块 */
676 std::map<uint32_t, uint32_t> p2v_map; /* 物理bit-》逻辑bit映射关系 */
677 std::map<uint32_t, uint32_t> v2p_map; /* 逻辑bit-》物理bit映射关系 */
678 uint32_t v_idx = 0;
679 for (const auto& p_val : phy_partition)
680 {
681 p2v_map[p_val] = v_idx;
682 v2p_map[v_idx] = p_val;
683 ++v_idx;
684 }
685 uint32_t max_v = p2v_map.rbegin()->first;
686
687 /* 根据连通比特块构建图 */
688 //const auto phy_partition_qubits_size = phy_partition.size();
689 const auto phy_partition_qubits_size = max_v + 1;
690 std::shared_ptr<QPanda::ArchGraph> arch_graph = QPanda::ArchGraph::Create(phy_partition_qubits_size);
691 arch_graph->putReg(std::to_string(phy_partition_qubits_size), std::to_string(phy_partition_qubits_size));
692 for (auto iter_1 = phy_partition.begin(); iter_1 != phy_partition.end(); ++iter_1)
693 {
694 for (auto iter_2 = phy_partition.begin(); iter_2 != phy_partition.end(); ++iter_2)
695 {
696 if ((*iter_1) == (*iter_2)) {
697 continue;
698 }
699
700 //if ((*iter_2) > matrix_connect.size())
701 if ((*iter_2) > src_graph->size())
702 {
703 //PILOT_OS_ERROR(ErrorCode::UNDEFINED_ERROR, "");
704 QCERR_AND_THROW(run_fail,
705 "Error, partition size error, qubit_" << (*iter_2)
706 << ", src_graph size:" << src_graph->size());
707 }
708
709 //if (matrix_connect[*iter_1][*iter_2] > 0)
710 if (src_graph->hasEdge((*iter_1), (*iter_2)) && (src_graph->getW((*iter_1), (*iter_2)) > 0)) {
711 //arch_graph->putEdge(v2p_map[*iter_1], v2p_map[*iter_2], src_graph->getW((*iter_1), (*iter_2)));
712 arch_graph->putEdge((*iter_1), (*iter_2), src_graph->getW((*iter_1), (*iter_2)));
713 }
714 }
715 }
716
717 return arch_graph;
718}
719
720/* @brief Get best mapping qubits blocks by fidelity
721 * @param[in] ArchGraph::sRef& graph

Callers 3

search_dfsMethod · 0.85
search_bfsMethod · 0.85
allocateMethod · 0.85

Calls 8

putRegMethod · 0.80
hasEdgeMethod · 0.80
getWMethod · 0.80
rbeginMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
putEdgeMethod · 0.45

Tested by

no test coverage detected