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 renormalising 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. The given outcome must not have a near zero probability, else it 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
.
To avoid renormalisation after projection, or force projection into non-physical states with very small probability, use applyProjector().
- See also
- 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
) - if
outcome
is not in {0, 1} - if the probability of
outcome
is zero (within machine epsilon)
- if
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.
The random outcome generator is seeded by seedQuESTDefault() within createQuESTEnv(), unless later overridden by seedQuEST().
- 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
)
- if
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.
The random outcome generator is seeded by seedQuESTDefault() within createQuESTEnv(), unless later overridden by seedQuEST().
- 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
)
- if
Referenced by TEST_CASE().