Skip to content

Commit de9a5fc

Browse files
committed
šŸ› Fix segfault in DD sample method when idle classical bits are present
Signed-off-by: burgholzer <burgholzer@me.com>
1 parent 0cbd0f7 commit de9a5fc

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

ā€Žsrc/dd/Simulation.cppā€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ std::map<std::string, std::size_t> sample(const qc::QuantumComputation& qc,
109109
}
110110

111111
// correct permutation if necessary
112-
changePermutation(e, permutation, qc.outputPermutation, dd);
113-
e = dd.reduceGarbage(e, qc.getGarbage());
112+
if (!hasMeasurements) {
113+
changePermutation(e, permutation, qc.outputPermutation, dd);
114+
e = dd.reduceGarbage(e, qc.getGarbage());
115+
}
114116

115117
// measure all qubits
116118
std::map<std::string, std::size_t> counts{};
@@ -134,7 +136,7 @@ std::map<std::string, std::size_t> sample(const qc::QuantumComputation& qc,
134136
// measurement map specifies that the circuit `qubit` is measured into
135137
// a certain `bit`
136138
measurement[numBits - 1U - bit] =
137-
bitstring[bitstring.size() - 1U - qc.outputPermutation.at(qubit)];
139+
bitstring[bitstring.size() - 1U - permutation.at(qubit)];
138140
}
139141
} else {
140142
// otherwise, we consider the output permutation for determining where

0 commit comments

Comments
Ā (0)