@@ -184,17 +184,20 @@ auto NAGraphAlgorithms::colorEdges(
184
184
std::copy_if (edges.cbegin (), edges.cend (),
185
185
std::back_inserter (adjacentEdges),
186
186
[&](const Edge& e) { return e.first == v or e.second == v; });
187
- std::sort (adjacentEdges.begin (), adjacentEdges.end (), [&](const Edge& a, const Edge& b) {
187
+ std::sort (adjacentEdges.begin (), adjacentEdges.end (),
188
+ [&](const Edge& a, const Edge& b) {
188
189
const auto u = a.first == v ? a.second : a.first ;
189
190
const auto w = b.first == v ? b.second : b.first ;
190
- return u != w && (partialOrder.isReachable (u, w) ||
191
- (!partialOrder.isReachable (w, u) &&
192
- (nAdjColors[a] > nAdjColors[b] ||
193
- (nAdjColors[a] == nAdjColors[b] &&
194
- (edgeDegree[a] > edgeDegree[b] ||
195
- (edgeDegree[a] == edgeDegree[b] && u < w))))));
196
- // the last line together with the first clause (u != w) is necessary for a
197
- // well-defined compare function to handle edges that compare equally correctly
191
+ return u != w &&
192
+ (partialOrder.isReachable (u, w) ||
193
+ (!partialOrder.isReachable (w, u) &&
194
+ (nAdjColors[a] > nAdjColors[b] ||
195
+ (nAdjColors[a] == nAdjColors[b] &&
196
+ (edgeDegree[a] > edgeDegree[b] ||
197
+ (edgeDegree[a] == edgeDegree[b] && u < w))))));
198
+ // the last line together with the first clause (u != w) is
199
+ // necessary for a well-defined compare function to handle edges
200
+ // that compare equally correctly
198
201
});
199
202
for (const auto & e : adjacentEdges) {
200
203
// color the edge
@@ -429,7 +432,8 @@ auto NAGraphAlgorithms::groupByConnectedComponent(
429
432
return result;
430
433
}
431
434
432
- auto NAGraphAlgorithms::computeSequence (const InteractionGraph& g, const std::size_t maxSites)
435
+ auto NAGraphAlgorithms::computeSequence (const InteractionGraph& g,
436
+ const std::size_t maxSites)
433
437
-> std::pair<std::vector<std::unordered_map<qc::Qubit, std::int64_t>>,
434
438
std::unordered_map<qc::Qubit, std::int64_t>> {
435
439
const auto & maxIndepSet = getMaxIndependentSet (g);
@@ -439,13 +443,14 @@ auto NAGraphAlgorithms::computeSequence(const InteractionGraph& g, const std::si
439
443
[&](const auto & u, const auto & v) {
440
444
return g.getDegree (u) > g.getDegree (v);
441
445
});
442
- auto sequence = groupByConnectedComponent (g, sequenceUngrouped);
446
+ auto sequence = groupByConnectedComponent (g, sequenceUngrouped);
443
447
const auto & colorEdgesResult =
444
448
colorEdges (g, coveredEdges (g, maxIndepSet), sequence);
445
- std::unordered_map<Edge, Color, qc::PairHash<qc::Qubit, qc::Qubit>> coloring = colorEdgesResult.first ;
449
+ std::unordered_map<Edge, Color, qc::PairHash<qc::Qubit, qc::Qubit>> coloring =
450
+ colorEdgesResult.first ;
446
451
auto partialOrder = colorEdgesResult.second ;
447
- auto fixed = partialOrder.orderTopologically ();
448
- auto resting = computeRestingPositions (sequence, fixed, coloring);
452
+ auto fixed = partialOrder.orderTopologically ();
453
+ auto resting = computeRestingPositions (sequence, fixed, coloring);
449
454
// compute relative x positions of fixed vertices
450
455
std::unordered_map<qc::Qubit, std::int64_t > fixedPositions{};
451
456
for (std::uint32_t x = 0 , i = 0 ; x < fixed.size (); ++x) {
@@ -455,26 +460,46 @@ auto NAGraphAlgorithms::computeSequence(const InteractionGraph& g, const std::si
455
460
}
456
461
}
457
462
458
- const auto maxSiteUsed = std::max_element (fixedPositions.cbegin (), fixedPositions.cend (), [](const auto & a, const auto & b){ return a.second < b.second ; })->second ;
463
+ const auto maxSiteUsed =
464
+ std::max_element (
465
+ fixedPositions.cbegin (), fixedPositions.cend (),
466
+ [](const auto & a, const auto & b) { return a.second < b.second ; })
467
+ ->second ;
459
468
const auto maxSitesSigned = static_cast <std::int64_t >(maxSites);
460
469
if (maxSiteUsed >= maxSitesSigned) {
461
- // Handle the situation when the entangling zone is not big enough to fit all fixed qubits
462
- for (auto it = fixedPositions.begin (); it != fixedPositions.end (); ) {
470
+ // Handle the situation when the entangling zone is not big enough to fit
471
+ // all fixed qubits
472
+ for (auto it = fixedPositions.begin (); it != fixedPositions.end ();) {
463
473
if (it->second >= maxSitesSigned) {
464
474
it = fixedPositions.erase (it); // erase returns the next iterator
465
475
} else {
466
476
++it; // move to the next element
467
477
}
468
478
}
469
- fixed.erase (std::remove_if (fixed.begin (), fixed.end (), [&fixedPositions](const auto & q){ return fixedPositions.find (q) == fixedPositions.end (); }), fixed.end ());
470
- for (auto it = coloring.begin (); it != coloring.end (); ) {
471
- if (fixedPositions.find (it->first .first ) == fixedPositions.end () && fixedPositions.find (it->first .second ) == fixedPositions.end ()) {
479
+ fixed.erase (std::remove_if (fixed.begin (), fixed.end (),
480
+ [&fixedPositions](const auto & q) {
481
+ return fixedPositions.find (q) ==
482
+ fixedPositions.end ();
483
+ }),
484
+ fixed.end ());
485
+ for (auto it = coloring.begin (); it != coloring.end ();) {
486
+ if (fixedPositions.find (it->first .first ) == fixedPositions.end () &&
487
+ fixedPositions.find (it->first .second ) == fixedPositions.end ()) {
472
488
it = coloring.erase (it); // erase returns the next iterator
473
489
} else {
474
490
++it; // move to the next element
475
491
}
476
492
}
477
- sequence.erase (std::remove_if (sequence.begin (), sequence.end (), [&coloring](const auto & q){ return !std::any_of (coloring.cbegin (), coloring.cend (), [q](const auto & elem){ return elem.first .first == q || elem.first .second == q; }); }), sequence.end ());
493
+ sequence.erase (std::remove_if (sequence.begin (), sequence.end (),
494
+ [&coloring](const auto & q) {
495
+ return !std::any_of (
496
+ coloring.cbegin (), coloring.cend (),
497
+ [q](const auto & elem) {
498
+ return elem.first .first == q ||
499
+ elem.first .second == q;
500
+ });
501
+ }),
502
+ sequence.end ());
478
503
// recalculate resting positions
479
504
resting = computeRestingPositions (sequence, fixed, coloring);
480
505
}
0 commit comments