Skip to content

Commit 018bd87

Browse files
committed
🐛 fix a bug in the SWAP application in circuit extraction
the locations of qubits where not properly tracked if the mapped circuit used more qubits than the original circuit. Signed-off-by: Lukas Burgholzer <lukas.burgholzer@jku.at>
1 parent 69ab527 commit 018bd87

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/exact/ExactMapper.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,13 @@ void ExactMapper::map(const Configuration& settings) {
343343
// apply swaps before layer
344344
for (auto it = (*swapsIterator).rbegin(); it != (*swapsIterator).rend();
345345
++it) {
346-
auto& swap = *it;
347-
qcMapped.swap(swap.first, swap.second);
348-
std::swap(qcMapped.outputPermutation.at(swap.first),
349-
qcMapped.outputPermutation.at(swap.second));
350-
std::swap(qubits.at(swap.first), qubits.at(swap.second));
351-
std::swap(
352-
locations.at(static_cast<std::size_t>(qubits.at(swap.first))),
353-
locations.at(static_cast<std::size_t>(qubits.at(swap.second))));
346+
const auto& [q0, q1] = *it;
347+
const auto logical0 = static_cast<qc::Qubit>(qubits.at(q0));
348+
const auto logical1 = static_cast<qc::Qubit>(qubits.at(q1));
349+
qcMapped.swap(q0, q1);
350+
std::swap(qubits.at(q0), qubits.at(q1));
351+
locations[logical0] = static_cast<std::int16_t>(q1);
352+
locations[logical1] = static_cast<std::int16_t>(q0);
354353

355354
if (settings.verbose) {
356355
std::cout << "Qubits: ";

0 commit comments

Comments
 (0)