qir-alliance / qcor

C++ compiler for heterogeneous quantum-classical computing built on Clang and XACC
http://docs.aide-qc.org
MIT License
97 stars 39 forks source link

__quantum__qis__measure__body implementation is incorrect when multiple bases passed #260

Open nleehone opened 1 year ago

nleehone commented 1 year ago

The current implementation of the quantumqismeasurebody (https://github.com/qir-alliance/qcor/blob/master/mlir/qir_qrt/qir-qis-ms-compat.cpp#L341) will perform independent measurements of each qubit when multiple bases are passed. For example, if the measurement bases [Z, Z] are specified, the first qubit is measured and projects the state, then the second qubit is measured and again projects the state.

For a bell pair |00> + |11> (ignoring normalization factors) the current implementation will result in storing the bit 0 50% of the time, and the state will be projected into |00>, and will result in storing the bit 1 50% of the time with the state projected into |11>. This is incorrect as it does not follow the description outlined in https://learn.microsoft.com/en-us/qsharp/api/qsharp/microsoft.quantum.intrinsic.measure

The correct implementation is a parity measurement for [Z, Z], which deterministically returns 0 for the bell pair |00> + |11> and leaves the state as is without disturbing it.