![]() |
The Quantum Exact Simulation Toolkit v4.3.0
|
Functions for overwriting Qureg amplitudes. More...
Functions | |
| void | setDensityQuregAmps (Qureg qureg, qindex startRow, qindex startCol, qcomp **amps, qindex numRows, qindex numCols) |
| void | setDensityQuregFlatAmps (Qureg qureg, qindex startInd, qcomp *amps, qindex numAmps) |
| void | setQuregAmps (Qureg qureg, qindex startInd, qcomp *amps, qindex numAmps) |
| void | setQuregToClone (Qureg outQureg, Qureg inQureg) |
| void | setQuregToMixture (Qureg out, qreal *probs, Qureg *in, int numIn) |
| void | setQuregToPartialTrace (Qureg out, Qureg in, int *traceOutQubits, int numTraceQubits) |
| void | setQuregToPauliStrSum (Qureg qureg, PauliStrSum sum) |
| void | setQuregToReducedDensityMatrix (Qureg out, Qureg in, int *retainQubits, int numRetainQubits) |
| qreal | setQuregToRenormalized (Qureg qureg) |
| void | setQuregToWeightedSum (Qureg out, qcomp *coeffs, Qureg *in, int numIn) |
Functions for overwriting Qureg amplitudes.
| void setDensityQuregAmps | ( | Qureg | qureg, |
| qindex | startRow, | ||
| qindex | startCol, | ||
| qcomp ** | amps, | ||
| qindex | numRows, | ||
| qindex | numCols ) |
Overwrites a rectangular block of density-matrix amplitudes.
qureg is distributed, startRow, startCol, numRows and numCols are treated globally and use of this function is ergo agnostic to distribution. Therefore, every process should contain identical amps.qureg is GPU-accelerated, only its GPU amplitudes are updated.The equivalent function for a statevector is setQuregAmps().
Let \(\dmrho=\) qureg with \(N\) qubits, and with \((r,c)\)-th global amplitude \(\alpha_{r,c}\). Let \(s_r=\) startRow, \(s_c=\) startCol, \(n_r=\) numRows and \(n_c=\) numCols, and let \(\beta_{j,k}\) be the \((j,k)\)-th element of amps, i.e. amps[j][k].
This function overwrites qureg from
\[ \dmrho = \sum\limits_{r=0}^{2^N-1} \sum\limits_{c=0}^{2^N-1} \alpha_{r,c} \ket{r}\bra{c} \]
by modifying only the global rows \([s_r,s_r+n_r)\) and columns \([s_c,s_c+n_c)\), such that
\[ \alpha_{s_r+j,\,s_c+k} \rightarrow \beta_{j,k} \quad\quad \forall \; j \in [0,n_r), \; k \in [0,n_c). \]
Expressed as a matrix,
\[ \dmrho = \begin{pmatrix} \alpha_{0,0} & \alpha_{0,1} & \dots & \alpha_{0,2^N-1} \\ \alpha_{1,0} & \alpha_{1,1} & \\ \vdots & & \ddots \\ \alpha_{2^N-1,0} & & & \alpha_{2^N-1,2^N-1} \end{pmatrix}, \]
the state is modified to contain the sub-matrix below. Grey dots indicate \(\alpha_{ij}\) above.
\[ \def\x{{\color{gray}\circ}} \dmrho \rightarrow \begin{array}{c@{\;}c} & \hspace{0.5em} \overset{\scriptstyle [s_c,\,s_c+n_c)}{\overline{\hspace{10.5em}}} \hspace{-0.5em} \\[1ex] \lower1.0em\hbox{$ \scriptstyle [s_r,\,s_r+n_r) \quad \left\{\vphantom{\begin{matrix} \beta_{0,0} \\ \beta_{1,0} \\ \vdots \\ \beta_{n_r-1,0} \end{matrix}}\right. $} & \begin{pmatrix} \x & \x & \x & \x & \x & \x & \x \\ \x & \x & \x & \x & \x & \x & \x \\ \x & \x & \beta_{0,0} & \beta_{0,1} & \cdots & \beta_{0,n_c-1} & \x \\ \x & \x & \beta_{1,0} & \beta_{1,1} & \cdots & \beta_{1,n_c-1} & \x \\ \x & \x & \vdots & \vdots & \ddots & \vdots & \x \\ \x & \x & \beta_{n_r-1,0} & \beta_{n_r-1,1} & \cdots & \beta_{n_r-1,n_c-1} & \x \\ \x & \x & \x & \x & \x & \x & \x \end{pmatrix} \end{array} \]
qureg must be a density matrix, and ergo compatible with a 2D range. Statevectors can be overwritten at a 1D range with setQuregAmps(). Density matrices can also be overwritten with a 1D contiguous range when flattening the density matrix column-major with setDensityQuregFlatAmps().qureg is **_not_** distributed, this function is equivalent to manual modification of the CPU elements, followed by copies to GPU (except that this function does not modify Qureg::cpuAmps when qureg is not GPU-accelerated). qureg is distributed, the logic is complicated by each specified global column range overlapping some, none or all of a node's partition. It follows the same pattern as demonstrated in setQuregAmps(), through column-wise linearisation of the density matrix.amps are within a single column (numCols==1), or span multiple full columns (numRows==(1<<qureg.numQubits)), this function becomes equivalent to calling setDensityQuregFlatAmps(), passing amps as a column-flattened 1D array.When numRows and numCols are sufficiently small such that the matrix amps can fit onto every distributed node, this function can be used in a manner totally agnostic to distribution and/or qureg deployments. In C++, an overload accepts amps as nested std::vector<qcomp>:
In C, amps must be a double pointer (and alas not an array):
numRows or numCols is large, one can avoid the superfluous storing of all amps simultaneously, by repeatedly calling setDensityQuregAmps(), each time passing a tractable sub-block, regardless of how qureg is distributed. | [in,out] | qureg | the density matrix to modify. |
| [in] | startRow | the first global density-matrix row index to overwrite. |
| [in] | startCol | the first global density-matrix column index to overwrite. |
| [in] | amps | a numRows by numCols matrix of amplitudes, as row-major nested pointers. |
| [in] | numRows | the total number of rows to overwrite. |
| [in] | numCols | the total number of columns to overwrite. |
| error |
|
Definition at line 157 of file initialisations.cpp.
Referenced by TEST_CASE().
| void setDensityQuregFlatAmps | ( | Qureg | qureg, |
| qindex | startInd, | ||
| qcomp * | amps, | ||
| qindex | numAmps ) |
Overwrites a contiguous range of density-matrix amplitudes, indexing qureg as a column-linearised form.
Let \( \dmrho = \) qureg contain \(N\) qubits, with amplitudes \( \alpha_{ij} \).
\[ \dmrho = \sum\limits_i^{2^N} \sum\limits_j^{2^N} \alpha_{ij} \ket{i}\bra{j}. \]
Internally, this matrix of dimension \( 2^N \times 2^N \) is stored in a vectorised form \( \ket{\rho} \) of dimension \( 2^{2N} \times 1 \), which concatenates the columns of \( \dmrho \).
\[ \begin{aligned} \ket{\rho} &= \sum\limits_i^{2^N} \sum\limits_j^{2^N} \alpha_{ij} \ket{j} \ket{i} \\ &= \sum\limits_k^{2^{2N}} \beta_k \ket{k} \end{aligned} \]
Let \(s = \) startInd, \(n = \) numAmps, and \(\gamma_i = \) amps[i]. This function overwrites amplitudes \(\beta_k : s \le k < s + n \) with \(\gamma_k\).
qureg, with identical parameters, when treating the column-wise linearised qureg as a statevector.| [in,out] | qureg | the density matrix to modify. |
| [in] | startInd | the first flattened, global index to overwrite. |
| [in] | amps | an array of numAmps amplitudes. |
| [in] | numAmps | the number of flattened amplitudes to overwrite. |
| error |
|
Definition at line 166 of file initialisations.cpp.
Referenced by TEST_CASE().
| void setQuregAmps | ( | Qureg | qureg, |
| qindex | startInd, | ||
| qcomp * | amps, | ||
| qindex | numAmps ) |
Overwrites a contiguous range of statevector amplitudes.
qureg is distributed, startInd and numAmps are treated globally and use of this function is ergo agnostic to distribution. Therefore, every process should contain identical amps, although only elements which fall within a process' statevector partition will be consulted by a particular process.qureg is GPU-accelerated, only its GPU amplitudes are updated.The equivalent function for a density matrix is setDensityQuregAmps().
Let \(\svpsi=\) qureg with \(N\) qubits, and with \(i\)-th global amplitude \(\alpha_i\). Let \(s=\) startInd, \(n=\) numAmps, and let \(\beta_j\) be the \(j\)-th element of amps.
This function overwrites qureg from \(\svpsi=\sum_{i=0}^{2^N-1} \alpha_i \ket{i}\) to
\[ \svpsi \rightarrow \sum\limits_{i=0}^{s-1} \alpha_i \ket{i} + \sum\limits_{j=0}^{n-1} \beta_j \ket{j + s} + \sum\limits_{i=s+n}^{2^N-1} \alpha_i \ket{i} \]
where amplitudes at global indices in \([s,s+n)\) have been modified. Expressed as a row-vector,
\[ \svpsi = \begin{pmatrix} \alpha_0 & \alpha_1 & \dots & \alpha_{2^N-1} \end{pmatrix} \]
is modified to become
\[ \svpsi \rightarrow \begin{pmatrix} \alpha_0 & \alpha_1 & \dots & \alpha_{s-1} & \beta_0 & \beta_1 & \dots & \beta_{n-1} & \alpha_{s + n} & \dots & \alpha_{2^N-1} \end{pmatrix}. \]
qureg must be a statevector, and ergo compatible with a 1D range. Density matrices can be overwritten at a 2D range with setDensityQuregAmps(), or with a 1D contiguous range when flattening the density matrix column-major with setDensityQuregFlatAmps(). Alternatively, setQuregAmps() can be called with validation disabled via setQuESTValidationOff(), accepting density matrices, and behaving identically to setDensityQuregFlatAmps().qureg is **_not_** distributed, this function is equivalent to (but much faster than) manual modification of the CPU elements, followed by a copy to GPU (except that this function does not modify Qureg::cpuAmps when qureg is not GPU-accelerated). When qureg is distributed, the logic is complicated by the specified global range of amplitudes overlapping some, none or all of a node's partition.
When numAmps is sufficiently small such that the array amps can fit onto every distributed node, this function can be used in a manner totally agnostic to distribution and/or qureg deployments.
numAmps is large, one can avoid the superfluous storing of all amps simultaneously, by repeatedly calling setQuregAmps(), each time passing a tractable sub-range, regardless of how qureg is distributed. | [in,out] | qureg | the statevector to modify. |
| [in] | startInd | the first global computational-basis index to overwrite. |
| [in] | amps | an array of numAmps amplitudes. |
| [in] | numAmps | the total number of amplitudes to overwrite. |
| error |
|
Definition at line 148 of file initialisations.cpp.
Referenced by TEST_CASE(), and TEST_CASE().
Definition at line 175 of file initialisations.cpp.
Referenced by createCloneQureg().
Definition at line 253 of file initialisations.cpp.
Definition at line 216 of file initialisations.cpp.
| void setQuregToPauliStrSum | ( | Qureg | qureg, |
| PauliStrSum | sum ) |
Definition at line 203 of file initialisations.cpp.
Referenced by TEST_CASE().
| void setQuregToReducedDensityMatrix | ( | Qureg | out, |
| Qureg | in, | ||
| int * | retainQubits, | ||
| int | numRetainQubits ) |
Definition at line 229 of file initialisations.cpp.
| qreal setQuregToRenormalized | ( | Qureg | qureg | ) |
Definition at line 189 of file initialisations.cpp.
Referenced by initRandomPureState(), and TEST_CASE().
Definition at line 242 of file initialisations.cpp.