![]() |
The Quantum Exact Simulation Toolkit v4.3.0
|
Functions for initialising Qureg into physical states. More...
Functions | |
| void | initArbitraryPureState (Qureg qureg, qcomp *amps) |
| void | initBlankState (Qureg qureg) |
| void | initClassicalState (Qureg qureg, qindex stateInd) |
| void | initDebugState (Qureg qureg) |
| void | initPlusState (Qureg qureg) |
| void | initPureState (Qureg qureg, Qureg pure) |
| void | initRandomMixedState (Qureg qureg, qindex numPureStates) |
| void | initRandomPureState (Qureg qureg) |
| void | initZeroState (Qureg qureg) |
Functions for initialising Qureg into physical states.
| void initArbitraryPureState | ( | Qureg | qureg, |
| qcomp * | amps ) |
Initialises qureg from the statevector amplitudes in amps.
Let \(N\) be the number of qubits in qureg, and let \(\alpha_i\) be the amplitude amps[i]. Array amps must be length \(2^N\).
qureg is a statevector, its amplitudes are overwritten by amps, to become \[ \sum\limits_i \alpha_i \ket{i}. \]
qureg is a density matrix, it is initialised to the pure state \(\ket{\psi}\) encoded by amps, i.e. \[ \ket{\psi}\bra{\psi} = \sum\limits_i\sum\limits_j \alpha_i \,\alpha_j^* \, \ket{i}\bra{j} \]
There is no need for amps to be normalised, although qureg will otherwise be left in an unnormalised, non-physical state.
| [in,out] | qureg | the Qureg to overwrite. |
| [in] | amps | an array of \(2^N\) pure-state amplitudes. |
| error |
|
| seg-fault |
|
Definition at line 100 of file initialisations.cpp.
Referenced by TEST_CASE(), and TEST_CASE().
| void initBlankState | ( | Qureg | qureg | ) |
Initialises qureg to the unnormalised all-zero-amplitude state.
Every statevector amplitude, or every density-matrix element, is set to zero. This is not a physical quantum state, but is useful as a blank workspace before manually setting amplitudes.
qureg is GPU-accelerated, this function modifies only its GPU amplitudes (Qureg::gpuAmps), leaving its CPU amps (Qureg::cpuAmps) unchanged (like almost all QuEST operations). It is therefore necessary to follow this function with syncQuregFromGpu() in order to make further, manual changes from the host side.This function is useful for preparing sparse states, noting we must explicitly copy the newly-zeroed amplitudes from GPU memory, when qureg is GPU-accelerated (though such functions are always safe to call).
| [in,out] | qureg | the Qureg to overwrite. |
| error |
|
Definition at line 42 of file initialisations.cpp.
Referenced by TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().
| void initClassicalState | ( | Qureg | qureg, |
| qindex | stateInd ) |
Initialises qureg to a computational basis state.
qureg is GPU-accelerated, overwriting only the relevant GPU buffer Qureg::gpuAmps. See initBlankState() for more information.Let \(N\) be the number of qubits in qureg, and let \(i=\) stateInd.
States are enumerated from \(0\) to \(2^N-1\), such that the bits of the indices match the qubits of the corresponding basis states.
qureg is a statevector, it is initialised to \(\ket{i}\).qureg is a density matrix, it is initialised to \(\ket{i}\bra{i}\).The bits of \(i\) will match the qubit values of the resulting state in qureg, where the zero-th qubit is the rightmost bit.
qureg is a statevector) or the \(i\)-th diagonal (when qureg is a density matrix). stateInd. | [in,out] | qureg | the Qureg to overwrite. |
| [in] | stateInd | the computational basis-state index. |
| error |
|
Definition at line 81 of file initialisations.cpp.
Referenced by TEST_CASE(), TEST_CASE(), and TEST_CASE().
| void initDebugState | ( | Qureg | qureg | ) |
Initialises qureg to the debug state.
This is a non-physical, deterministic pattern useful for debugging. The \(j\)-th local amplitude becomes
\[ 2j/10 + \iu(2j+1)/10, \]
even if qureg is a density matrix, in which case it is enumerated column-major.
qureg is GPU-accelerated, this function modifies only its GPU amplitudes (Qureg::gpuAmps), leaving its CPU amps (Qureg::cpuAmps) unchanged (like almost all QuEST operations). It is therefore necessary to follow this function with syncQuregFromGpu() in order to make further, manual changes from the host side. See initBlankState() for more information.| [in,out] | qureg | the Qureg to overwrite. |
| error |
|
Definition at line 93 of file initialisations.cpp.
Referenced by TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().
| void initPlusState | ( | Qureg | qureg | ) |
Initialises qureg to the uniform plus state.
qureg is GPU-accelerated, overwriting only the relevant GPU buffer Qureg::gpuAmps. See initBlankState() for more information.Let \(N\) be the number of qubits in qureg.
qureg is a statevector, it is initialised to \[ \begin{aligned} \ket{+}^{\otimes N} &= \left( \frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1} \right)^{\otimes N} \\ &= \frac{1}{\sqrt{2^N}} \{ 1, 1, \dots, 1 \} \end{aligned} \]
qureg is a density matrix, it is initialised to \[ \ket{+}\bra{+}^{\otimes N} = \frac{1}{2^N} \begin{pmatrix} 1 & 1 & \dots \\ 1 & \ddots \\ \vdots \end{pmatrix} \]
| [in,out] | qureg | the Qureg to overwrite. |
| error |
|
Definition at line 60 of file initialisations.cpp.
Referenced by TEST_CASE(), TEST_CASE(), and TEST_CASE().
Initialises qureg to the state in statevector pure.
qureg is GPU-accelerated, overwriting only the relevant GPU buffer Qureg::gpuAmps. See initBlankState() for more information.Let \(N\) be the number of qubits in qureg or pure, and let \(\ket{\psi} = \) pure, with amplitudes \(\ket{\psi} = \sum_i \alpha_i \ket{i}\).
qureg is a statevector, it is overwritten by the state in pure.qureg is a density matrix, it is initialised to \[ \ket{\psi}\bra{\psi} = \sum\limits_i\sum\limits_j \alpha_i \,\alpha_j^* \, \ket{i}\bra{j} \]
qureg is a statevector, this function is entirely equivalent to qureg is a density matrix, this function is equivalent to | [in,out] | qureg | the Qureg to overwrite. |
| [in] | pure | the statevector pure state to copy. |
| error |
|
Definition at line 70 of file initialisations.cpp.
Referenced by TEST_CASE().
| void initRandomMixedState | ( | Qureg | qureg, |
| qindex | numPureStates ) |
Initialises a density matrix to a mixture of uniformly random pure states.
The resulting density matrix is the equally weighted mixture of numPureStates independently sampled random pure states, each sampled as per initRandomPureState().
Let \(n=\) numPureStates, and let \(\ket{\psi_i}\) be a random pure state with number of qubits as qureg.
This function overwrites qureg to
\[ \sum\limits_i^n \frac{1}{n} \ket{\psi_i}\bra{\psi_i}. \]
| [in,out] | qureg | the density matrix to overwrite. |
| [in] | numPureStates | the number of random pure states in the mixture. |
| error |
|
Definition at line 133 of file initialisations.cpp.
Referenced by TEST_CASE().
| void initRandomPureState | ( | Qureg | qureg | ) |
Initialises qureg (a statevector or density matrix) to a pure state with uniformly random amplitudes.
The resulting state is normalised, with basis state probabilities sampled from a chi-squared variate, as described here.
| [in,out] | qureg | the Qureg to overwrite. |
| error |
|
Definition at line 118 of file initialisations.cpp.
Referenced by TEST_CASE().
| void initZeroState | ( | Qureg | qureg | ) |
Initialises qureg to the zero computational basis state.
qureg is GPU-accelerated, overwriting only the relevant GPU buffer Qureg::gpuAmps. See initBlankState() for more information.Let \(N\) be the number of qubits in qureg.
qureg is a statevector, it is initialised to \(\ket{0}^{\otimes N}\).qureg is a density matrix, it is initialised to \(\ket{0}\bra{0}^{\otimes N}\).'qureg is GPU-accelerated. | [in,out] | qureg | the Qureg to overwrite. |
| error |
|
Definition at line 51 of file initialisations.cpp.
Referenced by TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().