| 955 | |
| 956 | |
| 957 | Mapping OptBMTQAllocator::phase3(const MappingSwapSequence& mss, QPanda::QuantumMachine *qvm) |
| 958 | { |
| 959 | // Third Phase: |
| 960 | // build the operations vector by tracebacking from the solution we have |
| 961 | // found. For this, we have to go through every dependency again. |
| 962 | uint32_t idx = 0; |
| 963 | const auto& initial_mapping = mss.mappings[idx]; |
| 964 | m_init_mapping = initial_mapping; |
| 965 | //std::cout << "Initial Mapping: " << MappingToString(m_init_mapping) << std::endl; |
| 966 | auto final_mapping = initial_mapping; |
| 967 | for (auto& partition : mPP) |
| 968 | { |
| 969 | if (idx > 0) |
| 970 | { |
| 971 | auto swaps = mss.swapSeqs[idx - 1]; |
| 972 | |
| 973 | for (auto swp : swaps) |
| 974 | { |
| 975 | uint32_t u = swp.u, v = swp.v; |
| 976 | |
| 977 | if (!mArchGraph->hasEdge(u, v)) |
| 978 | { |
| 979 | std::swap(u, v); |
| 980 | } |
| 981 | |
| 982 | m_mapped_prog << _swap(qvm->allocateQubitThroughPhyAddress(u), qvm->allocateQubitThroughPhyAddress(v)); |
| 983 | mCirReliability *= mSwapDist[u][v]; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | final_mapping = mss.mappings[idx++]; |
| 988 | |
| 989 | for (auto& node : partition) |
| 990 | { |
| 991 | // We are sure that there are no instruction dependency that has more than |
| 992 | // one dependency. |
| 993 | auto iDependencies = build_deps(node); |
| 994 | |
| 995 | if (iDependencies.size() < 1) |
| 996 | { |
| 997 | QVec qv; |
| 998 | QNodeDeepCopy reproduction; |
| 999 | switch (node->getNodeType()) |
| 1000 | { |
| 1001 | case GATE_NODE: |
| 1002 | { |
| 1003 | auto new_node = reproduction.copy_node(std::dynamic_pointer_cast<AbstractQGateNode>(node)); |
| 1004 | new_node.getQuBitVector(qv); |
| 1005 | QVec c_qv; |
| 1006 | new_node.getControlVector(c_qv); |
| 1007 | new_node.clear_qubits(); |
| 1008 | |
| 1009 | auto qidx = final_mapping[qv[0]->get_phy_addr()]; |
| 1010 | auto qbit = qvm->allocateQubitThroughPhyAddress(qidx); |
| 1011 | new_node.remap({ qbit }); |
| 1012 | if (new_node.getQGate()->getGateType() == BARRIER_GATE) |
| 1013 | { |
| 1014 | for (auto &_q : c_qv) |
nothing calls this directly
no test coverage detected