| 281 | } |
| 282 | |
| 283 | std::vector<std::vector<MappingCandidate>> OptBMTQAllocator::phase1(LayeredTopoSeq& layer_info) |
| 284 | { |
| 285 | // First Phase: |
| 286 | // in this phase, we divide the program in layers, such that each layer is satisfied |
| 287 | // by any of the mappings inside 'candidates'. |
| 288 | // |
| 289 | mPP.push_back(std::vector<QNodeRef>()); |
| 290 | std::vector<std::vector<MappingCandidate>> collection; |
| 291 | std::vector<MappingCandidate> candidates { { Mapping(mVQubits, UNDEF_UINT32), 0 } }; |
| 292 | std::vector<bool> mapped(mVQubits, false); |
| 293 | Graph lastPartitionGraph(mVQubits); |
| 294 | Graph partitionGraph(mVQubits); |
| 295 | |
| 296 | PTrace("OPT-BMT PHASE 1 : Solving SIP Instances."); |
| 297 | auto mXbitSize = mVQubits; |
| 298 | using CandidateCirNode = CNodeCandidate<QNodeRef>; |
| 299 | std::priority_queue<CandidateCirNode, |
| 300 | std::vector<CandidateCirNode>, |
| 301 | std::greater<CandidateCirNode>> nodeQueue; |
| 302 | QVec last_layer_qubits; |
| 303 | for (auto layer_iter = layer_info.begin(); (layer_iter != layer_info.end()) || (nodeQueue.size() > 0); ) |
| 304 | { |
| 305 | bool b_stay_cur_layer = false; |
| 306 | bool b_no_double_gate = true; |
| 307 | std::list<QNodeRef> circuitNodeCandidatesVector; |
| 308 | if (layer_iter != layer_info.end()) |
| 309 | { |
| 310 | auto& cur_layer = *layer_iter; |
| 311 | for (auto gate_iter = cur_layer.begin(); gate_iter != cur_layer.end(); ) |
| 312 | { |
| 313 | const auto tmp_node = gate_iter->first; |
| 314 | auto used_qv = tmp_node->m_target_qubits + tmp_node->m_control_qubits; |
| 315 | auto q = used_qv - last_layer_qubits; |
| 316 | bool b_qubit_multiplex = (q.size() != used_qv.size()); |
| 317 | b_stay_cur_layer = (b_stay_cur_layer || b_qubit_multiplex); |
| 318 | |
| 319 | if (tmp_node->m_gate_type == BARRIER_GATE) |
| 320 | { |
| 321 | if (!b_qubit_multiplex) |
| 322 | { |
| 323 | mPP.back().push_back(*(tmp_node->m_iter)); |
| 324 | gate_iter = cur_layer.erase(gate_iter); |
| 325 | continue; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | if ((used_qv.size() < 2)) |
| 330 | { |
| 331 | if (!b_qubit_multiplex) |
| 332 | { |
| 333 | mPP.back().push_back(*(tmp_node->m_iter)); |
| 334 | gate_iter = cur_layer.erase(gate_iter); |
| 335 | continue; |
| 336 | } |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | b_no_double_gate = false; |
nothing calls this directly
no test coverage detected