From e5c96f28b882db7208f1da7776cea48fef1791f2 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Wed, 10 May 2023 16:41:26 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Improve=20handling=20of=20dedicated?= =?UTF-8?q?=20subgraphs=20in=20exact=20mapper=20(#308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This tiny PR improves the performance when a dedicated subgraph of an architecture is specified. This was only incompletely handled, which led to very inefficient computations (e.g., the SWAP limit was still computed from the whole architecture). This PR just reduces the architecture to the subgraph as part of the mapping. ## Checklist: - [x] The pull request only contains commits that are related to it. - [x] I have added appropriate tests and documentation. - [x] I have made sure that all CI jobs on GitHub pass. - [x] The pull request introduces no new warnings and follows the project's style guidelines. Signed-off-by: Lukas Burgholzer --- src/exact/ExactMapper.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/exact/ExactMapper.cpp b/src/exact/ExactMapper.cpp index 20bf90f68..c55da45d6 100644 --- a/src/exact/ExactMapper.cpp +++ b/src/exact/ExactMapper.cpp @@ -56,9 +56,7 @@ void ExactMapper::map(const Configuration& settings) { return; } - // 2) For all possibilities k (=m over n) to pick n qubits from m physical - // qubits - std::vector qubitRange{}; + // 2a) If only a subgraph should be considered, reduce the architecture. if (!config.subgraph.empty()) { const auto subgraphQubits = config.subgraph.size(); if (subgraphQubits < qc.getNqubits()) { @@ -76,13 +74,15 @@ void ExactMapper::map(const Configuration& settings) { std::cerr << "The subgraph is not connected." << std::endl; return; } - qubitRange = Architecture::getQubitList(reducedCouplingMap); - } else { - qubitRange.clear(); - auto qubitSet = architecture.getQubitSet(); - qubitRange.reserve(qubitSet.size()); - std::copy(qubitSet.begin(), qubitSet.end(), std::back_inserter(qubitRange)); + + architecture.setCouplingMap(reducedCouplingMap); } + + // 2b) If configured to use subsets, collect all k (=m over n) possibilities + // to pick n qubits from m device qubits. Otherwise, consider all qubits. + std::vector qubitRange = + Architecture::getQubitList(architecture.getCouplingMap()); + std::vector allPossibleQubitChoices{}; if (config.useSubsets) { allPossibleQubitChoices = architecture.getAllConnectedSubsets( @@ -90,6 +90,7 @@ void ExactMapper::map(const Configuration& settings) { } else { allPossibleQubitChoices.emplace_back(qubitRange.begin(), qubitRange.end()); } + // 3) determine exact mapping for this qubit choice std::vector swaps(reducedLayerIndices.size(), Swaps{}); mappingSwaps.reserve(reducedLayerIndices.size());