Gates

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()

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.

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]quregobject representing the set of all qubits
[in]measureQubitqubit to measure
[in]outcometo 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)
Author
Ania Brown (state-vector)
Tyson Jones (density matrix)

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().

See also
Parameters
[in,out]quregobject representing the set of all qubits
[in]measureQubitqubit to measure
Returns
the measurement outcome, 0 or 1
Exceptions
invalidQuESTInputError()
  • if measureQubit is outside [0, qureg.numQubitsRepresented)
Author
Ania Brown (state-vector)
Tyson Jones (density matrix)

Referenced by TEST_CASE().

◆ measureWithStats()

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.

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().

See also
Parameters
[in,out]quregobject representing the set of all qubits
[in]measureQubitqubit to measure
[out]outcomeProba 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)
Author
Ania Brown (state-vector)
Tyson Jones (density matrix)

Referenced by TEST_CASE().