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

Method allocateWithInitialMapping

Extensions/QMapping/SabreQMapping.cpp:417–607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415 : AbstractQubitMapping(ag), m_look_ahead(mLookAhead), m_max_iterations(mIterations), m_max_random_mappings(mRandomMappings), m_swap_cnt(0){}
416
417std::optional<SabreQAllocator::MappingAndNSwaps>
418SabreQAllocator::allocateWithInitialMapping(const Mapping& initialMapping, DynamicQCircuitGraph cir_graph,
419 QPanda::QuantumMachine *qvm, ArchGraph::sRef arch_graph, bool issueInstructions)
420{
421 auto mapping = initialMapping;
422 std::map<QNodeRef, uint32_t> reached;
423 std::set<QNodeRef> pastLookAhead;
424 uint32_t swapNum = 0;
425 uint32_t step_index = 0;
426 uint32_t cut_step_swap_size = 0;
427 //std::set<std::pair<uint32_t, uint32_t>> unConnectedNode; /* 记录当前层不可执行门的节点对 */
428 while (true)
429 {
430 /*
431 * Handle logic gates that can be executed directly: execute_gate
432 */
433 bool changed = false; /**< Whether there is an executable gate to join the execute_gate_list */
434 do
435 {
436 changed = false;
437 //unConnectedNode.clear();
438 std::vector<pPressedCirNode> issueNodes; /**< execute_gate_list */
439 auto& front_layer = cir_graph.get_front_layer(); /**< Front-layer qubit gate set (i.e., both previous gates of both qubits are executed) */
440 for (uint32_t _i = 0; _i < front_layer.size();)
441 {
442 const auto& cur_gate = *((front_layer[_i])->m_cur_node->m_iter);
443 /* Get the logic gate dependency */
444 auto deps = build_deps(cur_gate);
445 if (!deps.empty())
446 {
447 auto dep = deps[0];
448 uint32_t u = mapping[dep.mFrom], v = mapping[dep.mTo];
449
450 /*
451 * Determine whether the physical qubits of two logical qubit mappings are directly connected to each other
452 * If so, it means that it can be executed directly to add the current logic gate to the execute_gate_list
453 * If not, it means that it cannot be directly executed, reserved, and subsequently inserted into the swap gate
454 */
455 /* 若量子比特不相连,则加入 */
456 if (!arch_graph->hasEdge(u, v) && !arch_graph->hasEdge(v, u)) {
457 ++_i;
458 /*unConnectedNode.insert(std::make_pair(u, v));
459 unConnectedNode.insert(std::make_pair(v, u));*/
460 continue;
461 }
462 }
463
464 issueNodes.emplace_back(front_layer[_i]);
465 _i = front_layer.remove_node(_i);
466 changed = true;
467 ++step_index;
468 cut_step_swap_size = 0;
469 }
470
471 /*
472 * Remapping
473 */
474 if (issueInstructions)

Callers

nothing calls this directly

Calls 13

hasEdgeMethod · 0.80
adjMethod · 0.80
swapFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
emplace_backMethod · 0.45
remove_nodeMethod · 0.45
insertMethod · 0.45
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected