Skip to content

Commit

Permalink
🐛 make sure layout indices are consecutive when dumping
Browse files Browse the repository at this point in the history
Signed-off-by: burgholzer <burgholzer@me.com>
  • Loading branch information
burgholzer committed Jan 21, 2025
1 parent df9434d commit dca4aae
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/ir/QuantumComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,23 +721,27 @@ void QuantumComputation::dump(const std::string& filename) const {

void QuantumComputation::dumpOpenQASM(std::ostream& of, bool openQASM3) const {
// dump initial layout and output permutation
// since it might happen that the physical qubit indices are not consecutive,
// due to qubit removals, we need to adjust them accordingly.
Permutation inverseInitialLayout{};
for (const auto& q : initialLayout) {
inverseInitialLayout.insert({q.second, q.first});
std::size_t idx = 0;
for (const auto& [physical, logical] : initialLayout) {
inverseInitialLayout.emplace(logical, idx++);
}
of << "// i";
for (const auto& q : inverseInitialLayout) {
of << " " << static_cast<std::size_t>(q.second);
for (const auto& [logical, physical] : inverseInitialLayout) {
of << " " << static_cast<std::size_t>(physical);
}
of << "\n";

Permutation inverseOutputPermutation{};
for (const auto& q : outputPermutation) {
inverseOutputPermutation.insert({q.second, q.first});
idx = 0;
for (const auto& [physical, logical] : outputPermutation) {
inverseOutputPermutation.emplace(logical, idx++);
}
of << "// o";
for (const auto& q : inverseOutputPermutation) {
of << " " << q.second;
for (const auto& [logical, physical] : inverseOutputPermutation) {
of << " " << physical;
}
of << "\n";

Expand Down

0 comments on commit dca4aae

Please sign in to comment.