Function quest_sys::multiControlledMultiQubitUnitary
source · pub unsafe extern "C" fn multiControlledMultiQubitUnitary(
qureg: Qureg,
ctrls: *mut c_int,
numCtrls: c_int,
targs: *mut c_int,
numTargs: c_int,
u: ComplexMatrixN
)Expand description
Apply a general multi-controlled multi-qubit unitary (including a global phase factor).
Any number of control and target qubits can be specified.
This effects the many-qubit unitary
\f[
\begin{pmatrix}
1 \
& 1 \
& & \ddots \
& & & u_{00} & u_{01} & \dots \
& & & u_{10} & u_{11} & \dots \
& & & \vdots & \vdots & \ddots
\end{pmatrix}
\f]
on the control and target qubits.
The target qubits in \p targs are treated as ordered least significant to most significant in \p u.
The passed ::ComplexMatrixN must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.
To left-multiply a non-unitary ::ComplexMatrixN, including control qubits, use applyMultiControlledMatrixN()
\f[ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 1) {targets}; \node[draw=none] at (-3.5, 5) {controls};
\node[draw=none] at (0, 8) {$\vdots$}; \draw (0, 7) – (0, 6);
\draw (-2, 6) – (2, 6); \draw[fill=black] (0, 6) circle (.2); \draw (0, 6) – (0, 4);
\draw (-2, 4) – (2, 4); \draw[fill=black] (0, 4) circle (.2); \draw(0, 4) – (0, 3);
\draw (-2,0) – (-1, 0); \draw (1, 0) – (2, 0); \draw (-2,2) – (-1, 2); \draw (1, 2) – (2, 2); \draw (-1,-1)–(-1,3)–(1,3)–(1,-1); \node[draw=none] at (0, 1) {U}; \node[draw=none] at (0, -1) {$\vdots$};
\end{tikzpicture} \f]
Note that in multithreaded mode, each thread will clone 2^\p numTargs amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^\p numTargs. For many targets (e.g. 16 qubits), this may cause a stack-overflow / seg-fault (e.g. on a 1 MiB stack).
Note that in distributed mode, this routine requires that each node contains at least 2^\p numTargs amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^\p numTargs nodes.
@see
- createComplexMatrixN()
- applyMultiControlledMatrixN()
- multiControlledMultiQubitNot()
- controlledMultiQubitUnitary()
- multiQubitUnitary()
@ingroup unitary @param[in,out] qureg object representing the set of all qubits @param[in] ctrls a list of the control qubits @param[in] numCtrls the number of control qubits @param[in] targs a list of the target qubits, ordered least to most significant @param[in] numTargs the number of target qubits @param[in] u unitary matrix to apply @throws invalidQuESTInputError()
- if any qubit in \p ctrls and \p targs is invalid, i.e. outside [0,
qureg.numQubitsRepresented) - if \p ctrls or \p targs contain any repetitions
- if any qubit in \p ctrls is also in \p targs (and vice versa)
- if \p numTargs < 1
- if \p numCtrls < 1 (use multiQubitUnitary() for no controls)
- if matrix \p u is not unitary
- if a node cannot fit the required number of target amplitudes in distributed mode @throws segmentation-fault
- if \p ctrls contains fewer elements than \p numCtrls
- if \p targs contains fewer elements than \p numTargs @author Tyson Jones