Non-unitary but norm-preserving gates, such as measurements. More...
Functions | |
qreal | collapseToOutcome (Qureg qureg, int measureQubit, int outcome) |
Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1), and returns the probability of such a measurement outcome. More... | |
int | measure (Qureg qureg, int measureQubit) |
Measures a single qubit, collapsing it randomly to 0 or 1. More... | |
int | measureWithStats (Qureg qureg, int measureQubit, qreal *outcomeProb) |
Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of that outcome. More... | |
Detailed Description
Non-unitary but norm-preserving gates, such as measurements.
Function Documentation
◆ collapseToOutcome()
Updates qureg
to be consistent with measuring measureQubit
in the given outcome
(0 or 1), and returns the probability of such a measurement outcome.
This is effectively performing a projection, or a measurement with a forced outcome. This is an irreversible change to the state, whereby computational states inconsistant with the outcome are given zero amplitude and the qureg
is renormalised. Exits with error if the given outcome has a near zero probability, and so cannot be collapsed into.
Note that the collapse probably used for renormalisation is calculated for outcome
=
0
, and assumed 1 minus this probability if outcome
=
1
. Hence this routine will not correctly project un-normalised quregs onto outcome
=
1
.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] measureQubit qubit to measure [in] outcome to force the measure qubit to enter
- Returns
- probability of the (forced) measurement outcome
- Exceptions
-
invalidQuESTInputError if measureQubit
is outside [0,qureg.numQubitsRepresented
), or ifoutcome
is not in {0, 1}, or if the probability ofoutcome
is zero (within machine epsilon)
Definition at line 726 of file QuEST.c.
References densmatr_calcProbOfOutcome(), densmatr_collapseToKnownProbOutcome(), Qureg::isDensityMatrix, qasm_recordMeasurement(), qreal, statevec_calcProbOfOutcome(), statevec_collapseToKnownProbOutcome(), validateMeasurementProb(), validateOutcome(), and validateTarget().
Referenced by TEST_CASE().
◆ measure()
int measure | ( | Qureg | qureg, |
int | measureQubit | ||
) |
Measures a single qubit, collapsing it randomly to 0 or 1.
Outcome probabilities are weighted by the state vector, which is irreversibly changed after collapse to be consistent with the outcome.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] measureQubit qubit to measure
- Returns
- the measurement outcome, 0 or 1
- Exceptions
-
invalidQuESTInputError if measureQubit
is outside [0,qureg.numQubitsRepresented
)
Definition at line 758 of file QuEST.c.
References densmatr_measureWithStats(), Qureg::isDensityMatrix, qasm_recordMeasurement(), qreal, statevec_measureWithStats(), and validateTarget().
Referenced by TEST_CASE().
◆ measureWithStats()
Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of that outcome.
Outcome probabilities are weighted by the state vector, which is irreversibly changed after collapse to be consistent with the outcome.
- Parameters
-
[in,out] qureg object representing the set of all qubits [in] measureQubit qubit to measure [out] outcomeProb a pointer to a qreal which is set to the probability of the occurred outcome
- Returns
- the measurement outcome, 0 or 1
- Exceptions
-
invalidQuESTInputError if measureQubit
is outside [0,qureg.numQubitsRepresented
)
Definition at line 745 of file QuEST.c.
References densmatr_measureWithStats(), Qureg::isDensityMatrix, qasm_recordMeasurement(), statevec_measureWithStats(), and validateTarget().
Referenced by TEST_CASE().