| 222 | |
| 223 | |
| 224 | qreal calcProbOfBasisState(Qureg qureg, qindex index) { |
| 225 | validate_quregFields(qureg, __func__); |
| 226 | validate_basisStateIndex(qureg, index, __func__); |
| 227 | |
| 228 | // |i><i| = ||(1+2^N)i>> |
| 229 | if (qureg.isDensityMatrix) |
| 230 | index *= 1 + powerOf2(qureg.numQubits); |
| 231 | |
| 232 | qcomp amp = localiser_statevec_getAmp(qureg, index); |
| 233 | qreal prob = (qureg.isDensityMatrix)? |
| 234 | std::real(amp): |
| 235 | std::norm(amp); |
| 236 | |
| 237 | return prob; |
| 238 | } |
| 239 | |
| 240 | |
| 241 | qreal calcProbOfQubitOutcome(Qureg qureg, int qubit, int outcome) { |
no test coverage detected