Skip to content

Commit 33d4ced

Browse files
committed
🐛 properly account for global phases in simulation
Signed-off-by: burgholzer <[email protected]>
1 parent 1a01248 commit 33d4ced

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/mqt-core/dd/Simulation.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ VectorDD simulate(const QuantumComputation& qc, const VectorDD& in,
4040
}
4141
changePermutation(e, permutation, qc.outputPermutation, dd);
4242
e = dd.reduceGarbage(e, qc.getGarbage());
43+
44+
// properly account for the global phase of the circuit
45+
if (std::abs(qc.getGlobalPhase()) > 0) {
46+
// create a temporary copy for reference counting
47+
auto oldW = e.w;
48+
// adjust for global phase
49+
const auto globalPhase = ComplexValue{std::polar(1.0, qc.getGlobalPhase())};
50+
e.w = dd.cn.lookup(e.w * globalPhase);
51+
// adjust reference count
52+
dd.cn.incRef(e.w);
53+
dd.cn.decRef(oldW);
54+
}
55+
4356
return e;
4457
}
4558

0 commit comments

Comments
 (0)