Function initClassicalState

Source
pub unsafe extern "C" fn initClassicalState(
    qureg: Qureg,
    stateInd: c_longlong,
)
Expand description

Initialise \p qureg into the classical state (also known as a “computational basis state”) with index \p stateInd.

If \p qureg is a state-vector, it will become \f$ | \text{stateInd} \rangle \f$. \n If \p qureg is a density matrix, it will become \f$ | \text{stateInd} \rangle \langle \text{stateInd} | \f$.

Classical states are indexed from zero, so that \p stateInd = 0 produces \f$ | 00 \dots 00 \rangle \f$, and \p stateInd = 1 produces \f$ | 00 \dots 01 \rangle \f$, and \p stateInd = \f$ 2^N - 1 \f$ produces \f$ | 11 \dots 11 \rangle \f$.

Subsequent calls to getProbAmp() will yield 0 for all indices except \p stateInd, and the phase of \p stateInd’s amplitude will be 1 (real).

This function can be used to initialise \p qureg into a specific binary state (e.g. \p 11001) using a binary literal (supported by only some compilers):

     initClassicalState(qureg, 0b11001);

\n

@see

  • initPureState()

@ingroup init @param[in,out] qureg the ::Qureg to modify @param[in] stateInd the index of the basis state to modify \p qureg into @throws invalidQuESTInputError()

  • if \p stateInd is outside [0, qureg.numQubitsRepresented) @author Tyson Jones