| 1607 | } |
| 1608 | |
| 1609 | int applyQubitMeasurementAndGetProb(Qureg qureg, int target, qreal* probability) { |
| 1610 | validate_quregFields(qureg, __func__); |
| 1611 | validate_target(qureg, target, __func__); |
| 1612 | |
| 1613 | // we do not assume state normalisation (that is posteriori checked), |
| 1614 | // so we must perform two reductions; one for each outcome. We choose |
| 1615 | // to re-enumerate the state (potentially doubling caching costs) to |
| 1616 | // avoid the nuisances/race-cons of parallel adding to two scalars. |
| 1617 | vector<qreal> probs(2); |
| 1618 | probs[0] = calcProbOfQubitOutcome(qureg, target, 0); // harmlessly re-validates |
| 1619 | probs[1] = calcProbOfQubitOutcome(qureg, target, 1); // " " |
| 1620 | validate_measurementProbsAreNormalised(probs, __func__); |
| 1621 | |
| 1622 | // randomly choose the outcome |
| 1623 | int outcome = rand_getRandomSingleQubitOutcome(probs[0]); |
| 1624 | *probability = probs[outcome]; |
| 1625 | |
| 1626 | // collapse to the outcome |
| 1627 | (qureg.isDensityMatrix)? |
| 1628 | localiser_densmatr_multiQubitProjector(qureg, {target}, {outcome}, *probability): |
| 1629 | localiser_statevec_multiQubitProjector(qureg, {target}, {outcome}, *probability); |
| 1630 | |
| 1631 | return outcome; |
| 1632 | } |
| 1633 | |
| 1634 | qreal applyForcedQubitMeasurement(Qureg qureg, int target, int outcome) { |
| 1635 | validate_quregFields(qureg, __func__); |
no test coverage detected