Skip to content

Commit 1c225b2

Browse files
authored
šŸ› Fix corner case handling for output permutation in defer measurements optimization (cda-tum#587)
## Description This PR fixes a small corner case in the defer measurements optimization pass where a circuit with no measurements would loose its output permutation and have it reset to an identity permutation. ## 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: burgholzer <burgholzer@me.com>
1 parent 00fcfaa commit 1c225b2

File tree

3 files changed

+430
-399
lines changed

3 files changed

+430
-399
lines changed

ā€Žsrc/CircuitOptimizer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include "CircuitOptimizer.hpp"
22

3+
#include "operations/NonUnitaryOperation.hpp"
4+
35
#include <algorithm>
46
#include <cassert>
7+
#include <unordered_map>
58
#include <utility>
69
#include <vector>
710

@@ -927,6 +930,9 @@ void CircuitOptimizer::deferMeasurements(QuantumComputation& qc) {
927930
}
928931
++it;
929932
}
933+
if (qubitsToAddMeasurements.empty()) {
934+
return;
935+
}
930936
qc.outputPermutation.clear();
931937
for (const auto& [qubit, clbit] : qubitsToAddMeasurements) {
932938
qc.measure(qubit, clbit);

0 commit comments

Comments
Ā (0)