Skip to content

Commit

Permalink
⚡ Improve handling of dedicated subgraphs in exact mapper (#308)
Browse files Browse the repository at this point in the history
## 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:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [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 <[email protected]>
  • Loading branch information
burgholzer authored May 10, 2023
1 parent a2ff1a8 commit e5c96f2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/exact/ExactMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint16_t> 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()) {
Expand All @@ -76,20 +74,23 @@ 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<std::uint16_t> qubitRange =
Architecture::getQubitList(architecture.getCouplingMap());

std::vector<QubitChoice> allPossibleQubitChoices{};
if (config.useSubsets) {
allPossibleQubitChoices = architecture.getAllConnectedSubsets(
static_cast<std::uint16_t>(qc.getNqubits()));
} else {
allPossibleQubitChoices.emplace_back(qubitRange.begin(), qubitRange.end());
}

// 3) determine exact mapping for this qubit choice
std::vector<Swaps> swaps(reducedLayerIndices.size(), Swaps{});
mappingSwaps.reserve(reducedLayerIndices.size());
Expand Down

0 comments on commit e5c96f2

Please sign in to comment.