Unitaries

Unitary gates. More...

Functions

void compactUnitary (Qureg qureg, const int targetQubit, Complex alpha, Complex beta)
 Apply a single-qubit unitary parameterised by two given complex scalars. More...
 
void controlledCompactUnitary (Qureg qureg, const int controlQubit, const int targetQubit, Complex alpha, Complex beta)
 Apply a controlled unitary (single control, single target) parameterised by two given complex scalars. More...
 
void controlledMultiQubitUnitary (Qureg qureg, int ctrl, int *targs, const int numTargs, ComplexMatrixN u)
 Apply a general controlled multi-qubit unitary (including a global phase factor). More...
 
void controlledNot (Qureg qureg, const int controlQubit, const int targetQubit)
 Apply the controlled not (single control, single target) gate, also known as the c-X, c-sigma-X, c-Pauli-X and c-bit-flip gate. More...
 
void controlledPauliY (Qureg qureg, const int controlQubit, const int targetQubit)
 Apply the controlled pauliY (single control, single target) gate, also known as the c-Y and c-sigma-Y gate. More...
 
void controlledPhaseFlip (Qureg qureg, const int idQubit1, const int idQubit2)
 Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate. More...
 
void controlledPhaseShift (Qureg qureg, const int idQubit1, const int idQubit2, qreal angle)
 Introduce a phase factor $ \exp(i \theta) $ on state $ |11\rangle $ of qubits idQubit1 and idQubit2. More...
 
void controlledRotateAroundAxis (Qureg qureg, const int controlQubit, const int targetQubit, qreal angle, Vector axis)
 Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere. More...
 
void controlledRotateX (Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
 Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere. More...
 
void controlledRotateY (Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
 Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere. More...
 
void controlledRotateZ (Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
 Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere. More...
 
void controlledTwoQubitUnitary (Qureg qureg, const int controlQubit, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
 Apply a general controlled two-qubit unitary (including a global phase factor). More...
 
void controlledUnitary (Qureg qureg, const int controlQubit, const int targetQubit, ComplexMatrix2 u)
 Apply a general controlled unitary (single control, single target), which can include a global phase factor. More...
 
void hadamard (Qureg qureg, const int targetQubit)
 Apply the single-qubit Hadamard gate. More...
 
void multiControlledMultiQubitUnitary (Qureg qureg, int *ctrls, const int numCtrls, int *targs, const int numTargs, ComplexMatrixN u)
 Apply a general multi-controlled multi-qubit unitary (including a global phase factor). More...
 
void multiControlledPhaseFlip (Qureg qureg, int *controlQubits, int numControlQubits)
 Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled pauliZ gate. More...
 
void multiControlledPhaseShift (Qureg qureg, int *controlQubits, int numControlQubits, qreal angle)
 Introduce a phase factor $ \exp(i \theta) $ on state $ |1 \dots 1 \rangle $ of the passed qubits. More...
 
void multiControlledTwoQubitUnitary (Qureg qureg, int *controlQubits, const int numControlQubits, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
 Apply a general multi-controlled two-qubit unitary (including a global phase factor). More...
 
void multiControlledUnitary (Qureg qureg, int *controlQubits, const int numControlQubits, const int targetQubit, ComplexMatrix2 u)
 Apply a general multiple-control single-target unitary, which can include a global phase factor. More...
 
void multiQubitUnitary (Qureg qureg, int *targs, const int numTargs, ComplexMatrixN u)
 Apply a general multi-qubit unitary (including a global phase factor) with any number of target qubits. More...
 
void multiRotatePauli (Qureg qureg, int *targetQubits, enum pauliOpType *targetPaulis, int numTargets, qreal angle)
 Apply a multi-qubit multi-Pauli rotation on a selected number of qubits. More...
 
void multiRotateZ (Qureg qureg, int *qubits, int numQubits, qreal angle)
 Apply a multi-qubit Z rotation on a selected number of qubits. More...
 
void multiStateControlledUnitary (Qureg qureg, int *controlQubits, int *controlState, const int numControlQubits, const int targetQubit, ComplexMatrix2 u)
 Apply a general multiple-control, conditioned on a specific bit sequence, single-target unitary, which can include a global phase factor. More...
 
void pauliX (Qureg qureg, const int targetQubit)
 Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate. More...
 
void pauliY (Qureg qureg, const int targetQubit)
 Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate. More...
 
void pauliZ (Qureg qureg, const int targetQubit)
 Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate. More...
 
void phaseShift (Qureg qureg, const int targetQubit, qreal angle)
 Shift the phase between $ |0\rangle $ and $ |1\rangle $ of a single qubit by a given angle. More...
 
void rotateAroundAxis (Qureg qureg, const int rotQubit, qreal angle, Vector axis)
 Rotate a single qubit by a given angle around a given Vector on the Bloch-sphere. More...
 
void rotateX (Qureg qureg, const int rotQubit, qreal angle)
 Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere. More...
 
void rotateY (Qureg qureg, const int rotQubit, qreal angle)
 Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere. More...
 
void rotateZ (Qureg qureg, const int rotQubit, qreal angle)
 Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase shift gate). More...
 
void sGate (Qureg qureg, const int targetQubit)
 Apply the single-qubit S gate. More...
 
void sqrtSwapGate (Qureg qureg, int qb1, int qb2)
 Performs a sqrt SWAP gate between qubit1 and qubit2. More...
 
void swapGate (Qureg qureg, int qubit1, int qubit2)
 Performs a SWAP gate between qubit1 and qubit2. More...
 
void tGate (Qureg qureg, const int targetQubit)
 Apply the single-qubit T gate. More...
 
void twoQubitUnitary (Qureg qureg, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
 Apply a general two-qubit unitary (including a global phase factor). More...
 
void unitary (Qureg qureg, const int targetQubit, ComplexMatrix2 u)
 Apply a general single-qubit unitary (including a global phase factor). More...
 

Detailed Description

Unitary gates.

Function Documentation

◆ compactUnitary()

void compactUnitary ( Qureg  qureg,
const int  targetQubit,
Complex  alpha,
Complex  beta 
)

Apply a single-qubit unitary parameterised by two given complex scalars.

Given valid complex numbers $\alpha$ and $\beta$, applies the unitary

\[ U = \begin{pmatrix} \alpha & -\beta^* \\ \beta & \alpha^* \end{pmatrix} \]

which is general up to a global phase factor.
Valid $\alpha$, $\beta$ satisfy $|\alpha|^2 + |\beta|^2 = 1$.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {U}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate on
[in]alphacomplex unitary parameter (row 1, column 1)
[in]betacomplex unitary parameter (row 2, column 1)
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented), or if alpha, beta don't satisfy |alpha|^2 + |beta|^2 = 1.
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 403 of file QuEST.c.

403  {
404  validateTarget(qureg, targetQubit, __func__);
405  validateUnitaryComplexPair(alpha, beta, __func__);
406 
407  statevec_compactUnitary(qureg, targetQubit, alpha, beta);
408  if (qureg.isDensityMatrix) {
409  int shift = qureg.numQubitsRepresented;
410  statevec_compactUnitary(qureg, targetQubit+shift, getConjugateScalar(alpha), getConjugateScalar(beta));
411  }
412 
413  qasm_recordCompactUnitary(qureg, alpha, beta, targetQubit);
414 }

References getConjugateScalar(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordCompactUnitary(), statevec_compactUnitary(), validateTarget(), and validateUnitaryComplexPair().

Referenced by TEST_CASE().

◆ controlledCompactUnitary()

void controlledCompactUnitary ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit,
Complex  alpha,
Complex  beta 
)

Apply a controlled unitary (single control, single target) parameterised by two given complex scalars.

Given valid complex numbers $\alpha$ and $\beta$, applies the two-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\ & & \alpha & -\beta^* \\ & & \beta & \alpha^* \end{pmatrix} \]

to the control and target qubits. Valid $\alpha$, $\beta$ satisfy $|\alpha|^2 + |\beta|^2 = 1$. The target unitary is general up to a global phase factor.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$U_{\alpha, \beta}$}; \end{tikzpicture} } \]


Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitapply the target unitary if this qubit has value 1
[in]targetQubitqubit on which to apply the target unitary
[in]alphacomplex unitary parameter (row 1, column 1)
[in]betacomplex unitary parameter (row 2, column 1)
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented) or are equal, or if alpha, beta don't satisfy |alpha|^2 + |beta|^2 = 1.
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 416 of file QuEST.c.

416  {
417  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
418  validateUnitaryComplexPair(alpha, beta, __func__);
419 
420  statevec_controlledCompactUnitary(qureg, controlQubit, targetQubit, alpha, beta);
421  if (qureg.isDensityMatrix) {
422  int shift = qureg.numQubitsRepresented;
424  controlQubit+shift, targetQubit+shift,
425  getConjugateScalar(alpha), getConjugateScalar(beta));
426  }
427 
428  qasm_recordControlledCompactUnitary(qureg, alpha, beta, controlQubit, targetQubit);
429 }

References getConjugateScalar(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledCompactUnitary(), statevec_controlledCompactUnitary(), validateControlTarget(), and validateUnitaryComplexPair().

Referenced by TEST_CASE().

◆ controlledMultiQubitUnitary()

void controlledMultiQubitUnitary ( Qureg  qureg,
int  ctrl,
int *  targs,
const int  numTargs,
ComplexMatrixN  u 
)

Apply a general controlled multi-qubit unitary (including a global phase factor).

One control and any number of target qubits can be specified. This effects the many-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & 1 \\ & & & 1 \\ & & & & u_{00} & u_{01} & \dots \\ & & & & u_{10} & u_{11} & \dots \\ & & & & \vdots & \vdots & \ddots \end{pmatrix} \]

on the control and target qubits.

The target qubits in targs are treated as ordered least sigifnicant to most significant in u.

The passed ComplexMatrix must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 1) {targets}; \node[draw=none] at (-3.5, 4) {control}; \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} } \]

Note that in multithreaded mode, each thread will clone 2^numTargs amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^numTargs. For many targets (e.g. 16 qubits), this may cause a stack-overflow / seg-fault (e.g. on a 1 MiB stack).

Note too that in distributed mode, this routine requires that each node contains at least 2^numTargs amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^numTargs nodes.

Parameters
[in,out]quregobject representing the set of all qubits
[in]ctrlthe control qubit
[in]targsa list of the target qubits, ordered least to most significant
[in]numTargsthe number of target qubits
[in]uunitary matrix to apply
Exceptions
exitWithErrorif ctrl or any index in targs is outside of [0, qureg.numQubitsRepresented), or if targs are not unique, or if targs contains ctrl, or if matrix u is not unitary, or if a node cannot fit the required number of target amplitudes in distributed mode.
Author
Tyson Jones

Definition at line 312 of file QuEST.c.

312  {
313  validateMultiControlsMultiTargets(qureg, (int[]) {ctrl}, 1, targs, numTargs, __func__);
314  validateMultiQubitUnitaryMatrix(qureg, u, numTargs, __func__);
315 
316  statevec_controlledMultiQubitUnitary(qureg, ctrl, targs, numTargs, u);
317  if (qureg.isDensityMatrix) {
318  int shift = qureg.numQubitsRepresented;
319  shiftIndices(targs, numTargs, shift);
321  statevec_controlledMultiQubitUnitary(qureg, ctrl+shift, targs, numTargs, u);
322  shiftIndices(targs, numTargs, -shift);
324  }
325 
326  qasm_recordComment(qureg, "Here, an undisclosed controlled multi-qubit unitary was applied.");
327 }

References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), setConjugateMatrixN(), shiftIndices(), statevec_controlledMultiQubitUnitary(), validateMultiControlsMultiTargets(), and validateMultiQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ controlledNot()

void controlledNot ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit 
)

Apply the controlled not (single control, single target) gate, also known as the c-X, c-sigma-X, c-Pauli-X and c-bit-flip gate.

This applies pauliX to the target qubit if the control qubit has value 1. This effects the two-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & & 1 \\ & & 1 \end{pmatrix} \]

on the control and target qubits.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, -.5); \draw (-2,0) -- (2, 0); \draw (0, 0) circle (.5); \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitnots the target if this qubit is 1
[in]targetQubitqubit to not
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented), or are equal.
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 523 of file QuEST.c.

523  {
524  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
525 
526  statevec_controlledNot(qureg, controlQubit, targetQubit);
527  if (qureg.isDensityMatrix) {
528  int shift = qureg.numQubitsRepresented;
529  statevec_controlledNot(qureg, controlQubit+shift, targetQubit+shift);
530  }
531 
532  qasm_recordControlledGate(qureg, GATE_SIGMA_X, controlQubit, targetQubit);
533 }

References GATE_SIGMA_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_controlledNot(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledPauliY()

void controlledPauliY ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit 
)

Apply the controlled pauliY (single control, single target) gate, also known as the c-Y and c-sigma-Y gate.

This applies pauliY to the target qubit if the control qubit has value 1. This effects the two-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & & -i \\ & & i \end{pmatrix} \]

on the control and target qubits.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {Y}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitapplies pauliY to the target if this qubit is 1
[in]targetQubitqubit to not
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented), or are equal.
Author
Tyson Jones
Ania Brown (debug)

Definition at line 535 of file QuEST.c.

535  {
536  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
537 
538  statevec_controlledPauliY(qureg, controlQubit, targetQubit);
539  if (qureg.isDensityMatrix) {
540  int shift = qureg.numQubitsRepresented;
541  statevec_controlledPauliYConj(qureg, controlQubit+shift, targetQubit+shift);
542  }
543 
544  qasm_recordControlledGate(qureg, GATE_SIGMA_Y, controlQubit, targetQubit);
545 }

References GATE_SIGMA_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_controlledPauliY(), statevec_controlledPauliYConj(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledPhaseFlip()

void controlledPhaseFlip ( Qureg  qureg,
const int  idQubit1,
const int  idQubit2 
)

Apply the (two-qubit) controlled phase flip gate, also known as the controlled pauliZ gate.

For each state, if both input qubits have value one, multiply the amplitude of that state by -1. This applies the two-qubit unitary:

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & 1 \\ & & & -1 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {idQubit1}; \node[draw=none] at (-3.5, 0) {idQubit2}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 0); \draw (-2,0) -- (2, 0); \draw[fill=black] (0, 0) circle (.2); \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]idQubit1,idQubit2qubits to operate upon
Exceptions
exitWithErrorif idQubit1 or idQubit2 are outside [0, qureg.numQubitsRepresented), or are equal
Author
Tyson Jones

Definition at line 547 of file QuEST.c.

547  {
548  validateControlTarget(qureg, idQubit1, idQubit2, __func__);
549 
550  statevec_controlledPhaseFlip(qureg, idQubit1, idQubit2);
551  if (qureg.isDensityMatrix) {
552  int shift = qureg.numQubitsRepresented;
553  statevec_controlledPhaseFlip(qureg, idQubit1+shift, idQubit2+shift);
554  }
555 
556  qasm_recordControlledGate(qureg, GATE_SIGMA_Z, idQubit1, idQubit2);
557 }

References GATE_SIGMA_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_controlledPhaseFlip(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledPhaseShift()

void controlledPhaseShift ( Qureg  qureg,
const int  idQubit1,
const int  idQubit2,
qreal  angle 
)

Introduce a phase factor $ \exp(i \theta) $ on state $ |11\rangle $ of qubits idQubit1 and idQubit2.

For angle $\theta$, this effects the unitary

\[ \begin{pmatrix} 1 & & & \\ & 1 & & \\ & & 1 & \\ & & & \exp(i \theta) \end{pmatrix} \]

on idQubit1 and idQubit2.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {qubit1}; \node[draw=none] at (-3.5, 0) {qubit2}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_\theta$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]idQubit1first qubit in the state to phase shift
[in]idQubit2second qubit in the state to phase shift
[in]angleamount by which to shift the phase in radians
Exceptions
exitWithErrorif idQubit1 or idQubit2 are outside [0, qureg.numQubitsRepresented), or are equal
Author
Tyson Jones

Definition at line 497 of file QuEST.c.

497  {
498  validateControlTarget(qureg, idQubit1, idQubit2, __func__);
499 
500  statevec_controlledPhaseShift(qureg, idQubit1, idQubit2, angle);
501  if (qureg.isDensityMatrix) {
502  int shift = qureg.numQubitsRepresented;
503  statevec_controlledPhaseShift(qureg, idQubit1+shift, idQubit2+shift, -angle);
504  }
505 
506  qasm_recordControlledParamGate(qureg, GATE_PHASE_SHIFT, idQubit1, idQubit2, angle);
507 }

References GATE_PHASE_SHIFT, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledPhaseShift(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledRotateAroundAxis()

void controlledRotateAroundAxis ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit,
qreal  angle,
Vector  axis 
)

Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.


The vector must not be zero (else an error is thrown), but needn't be unit magnitude.

For angle $\theta$ and axis vector $\vec{n}$, applies $R_{\hat{n}} = \exp \left(- i \frac{\theta}{2} \hat{n} \cdot \vec{\sigma} \right) $ to states where the target qubit is 1 ( $\vec{\sigma}$ is the vector of Pauli matrices).

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_{\hat{n}}(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitqubit with value 1 in the rotated states
[in]targetQubitqubit to rotate
[in]angleangle by which to rotate in radians
[in]axisvector around which to rotate (can be non-unit; will be normalised)
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented) or are equal or if axis is the zero vector
Author
Tyson Jones

Definition at line 586 of file QuEST.c.

586  {
587  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
588  validateVector(axis, __func__);
589 
590  statevec_controlledRotateAroundAxis(qureg, controlQubit, targetQubit, angle, axis);
591  if (qureg.isDensityMatrix) {
592  int shift = qureg.numQubitsRepresented;
593  statevec_controlledRotateAroundAxisConj(qureg, controlQubit+shift, targetQubit+shift, angle, axis);
594  }
595 
596  qasm_recordControlledAxisRotation(qureg, angle, axis, controlQubit, targetQubit);
597 }

References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledAxisRotation(), statevec_controlledRotateAroundAxis(), statevec_controlledRotateAroundAxisConj(), validateControlTarget(), and validateVector().

Referenced by TEST_CASE().

◆ controlledRotateX()

void controlledRotateX ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit,
qreal  angle 
)

Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere.

The target qubit is rotated in states where the control qubit has value 1.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_x(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitqubit which has value 1 in the rotated states
[in]targetQubitqubit to rotate
[in]angleangle by which to rotate the target qubit in radians
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented) or are equal.
Author
Tyson Jones

Definition at line 219 of file QuEST.c.

219  {
220  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
221 
222  statevec_controlledRotateX(qureg, controlQubit, targetQubit, angle);
223  if (qureg.isDensityMatrix) {
224  int shift = qureg.numQubitsRepresented;
225  statevec_controlledRotateX(qureg, controlQubit+shift, targetQubit+shift, -angle);
226  }
227 
228  qasm_recordControlledParamGate(qureg, GATE_ROTATE_X, controlQubit, targetQubit, angle);
229 }

References GATE_ROTATE_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledRotateX(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledRotateY()

void controlledRotateY ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit,
qreal  angle 
)

Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere.

The target qubit is rotated in states where the control qubit has value 1.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_y(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitqubit which has value 1 in the rotated states
[in]targetQubitqubit to rotate
[in]angleangle by which to rotate the target qubit in radians
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented) or are equal.
Author
Tyson Jones

Definition at line 231 of file QuEST.c.

231  {
232  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
233 
234  statevec_controlledRotateY(qureg, controlQubit, targetQubit, angle);
235  if (qureg.isDensityMatrix) {
236  int shift = qureg.numQubitsRepresented;
237  statevec_controlledRotateY(qureg, controlQubit+shift, targetQubit+shift, angle); // rotateY is real
238  }
239 
240  qasm_recordControlledParamGate(qureg, GATE_ROTATE_Y, controlQubit, targetQubit, angle);
241 }

References GATE_ROTATE_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledRotateY(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledRotateZ()

void controlledRotateZ ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit,
qreal  angle 
)

Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere.

The target qubit is rotated in states where the control qubit has value 1.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_z(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitqubit which has value 1 in the rotated states
[in]targetQubitqubit to rotate
[in]angleangle by which to rotate the target qubit in radians
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented) or are equal.
Author
Tyson Jones

Definition at line 243 of file QuEST.c.

243  {
244  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
245 
246  statevec_controlledRotateZ(qureg, controlQubit, targetQubit, angle);
247  if (qureg.isDensityMatrix) {
248  int shift = qureg.numQubitsRepresented;
249  statevec_controlledRotateZ(qureg, controlQubit+shift, targetQubit+shift, -angle);
250  }
251 
252  qasm_recordControlledParamGate(qureg, GATE_ROTATE_Z, controlQubit, targetQubit, angle);
253 }

References GATE_ROTATE_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledParamGate(), statevec_controlledRotateZ(), and validateControlTarget().

Referenced by TEST_CASE().

◆ controlledTwoQubitUnitary()

void controlledTwoQubitUnitary ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit1,
const int  targetQubit2,
ComplexMatrix4  u 
)

Apply a general controlled two-qubit unitary (including a global phase factor).

The given unitary is applied to the target amplitudes where the control qubit has value 1. This effects the many-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\ & & 1 \\ & & & 1 \\ & & & & u_{00} & u_{01} & u_{02} & u_{03} \\ & & & & u_{10} & u_{11} & u_{12} & u_{13} \\ & & & & u_{20} & u_{21} & u_{22} & u_{23} \\ & & & & u_{30} & u_{31} & u_{32} & u_{33} \end{pmatrix} \]

on the control and target qubits.

targetQubit1 is treated as the least significant qubit in u, such that a row in u is dotted with the vector $ |\text{targetQubit2} \;\; \text{targetQubit1}\rangle : \{ |00\rangle, |01\rangle, |10\rangle, |11\rangle \} $

The passed 4x4 ComplexMatrix must be unitary, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target1}; \node[draw=none] at (-3.5, 2) {target2}; \node[draw=none] at (-3.5, 4) {control}; \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)--cycle; \node[draw=none] at (0, 1) {U}; \end{tikzpicture} } \]

Note that in distributed mode, this routine requires that each node contains at least 4 amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q/4 nodes.


Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitthe control qubit which must be in state 1 to effect the given unitary
[in]targetQubit1first qubit to operate on, treated as least significant in u
[in]targetQubit2second qubit to operate on, treated as most significant in u
[in]uunitary matrix to apply
Exceptions
exitWithErrorif controlQubit, targetQubit1 or targetQubit2 are outside [0, qureg.numQubitsRepresented), or if any of controlQubit, targetQubit1 and targetQubit2 are equal, or matrix u is not unitary, or if each node cannot fit 4 amplitudes in distributed mode.
Author
Tyson Jones

Definition at line 268 of file QuEST.c.

268  {
269  validateMultiControlsMultiTargets(qureg, (int[]) {controlQubit}, 1, (int[]) {targetQubit1, targetQubit2}, 2, __func__);
270  validateTwoQubitUnitaryMatrix(qureg, u, __func__);
271 
272  statevec_controlledTwoQubitUnitary(qureg, controlQubit, targetQubit1, targetQubit2, u);
273  if (qureg.isDensityMatrix) {
274  int shift = qureg.numQubitsRepresented;
275  statevec_controlledTwoQubitUnitary(qureg, controlQubit+shift, targetQubit1+shift, targetQubit2+shift, getConjugateMatrix4(u));
276  }
277 
278  qasm_recordComment(qureg, "Here, an undisclosed controlled 2-qubit unitary was applied.");
279 }

References getConjugateMatrix4(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_controlledTwoQubitUnitary(), validateMultiControlsMultiTargets(), and validateTwoQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ controlledUnitary()

void controlledUnitary ( Qureg  qureg,
const int  controlQubit,
const int  targetQubit,
ComplexMatrix2  u 
)

Apply a general controlled unitary (single control, single target), which can include a global phase factor.

The given unitary is applied to the target qubit if the control qubit has value 1, effecting the two-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\ & & u_{00} & u_{01}\\ & & u_{10} & u_{11} \end{pmatrix} \]

on the control and target qubits.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {control}; \node[draw=none] at (-3.5, 0) {target}; \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {U}; \end{tikzpicture} } \]


Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitapply unitary if this qubit is 1
[in]targetQubitqubit to operate on
[in]usingle-qubit unitary matrix to apply
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, qureg.numQubitsRepresented) or are equal, or if u is not unitary.
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 359 of file QuEST.c.

359  {
360  validateControlTarget(qureg, controlQubit, targetQubit, __func__);
361  validateOneQubitUnitaryMatrix(u, __func__);
362 
363  statevec_controlledUnitary(qureg, controlQubit, targetQubit, u);
364  if (qureg.isDensityMatrix) {
365  int shift = qureg.numQubitsRepresented;
366  statevec_controlledUnitary(qureg, controlQubit+shift, targetQubit+shift, getConjugateMatrix2(u));
367  }
368 
369  qasm_recordControlledUnitary(qureg, u, controlQubit, targetQubit);
370 }

References getConjugateMatrix2(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledUnitary(), statevec_controlledUnitary(), validateControlTarget(), and validateOneQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ hadamard()

void hadamard ( Qureg  qureg,
const int  targetQubit 
)

Apply the single-qubit Hadamard gate.

This takes $|0\rangle$ to $|+\rangle$ and $|1\rangle$ to $|-\rangle$, and is equivalent to a rotation of $\pi$ around the x-axis then $\pi/2$ about the y-axis on the Bloch-sphere. I.e.

\[ \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {H}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 175 of file QuEST.c.

175  {
176  validateTarget(qureg, targetQubit, __func__);
177 
178  statevec_hadamard(qureg, targetQubit);
179  if (qureg.isDensityMatrix) {
180  statevec_hadamard(qureg, targetQubit+qureg.numQubitsRepresented);
181  }
182 
183  qasm_recordGate(qureg, GATE_HADAMARD, targetQubit);
184 }

References GATE_HADAMARD, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_hadamard(), and validateTarget().

Referenced by TEST_CASE().

◆ multiControlledMultiQubitUnitary()

void multiControlledMultiQubitUnitary ( Qureg  qureg,
int *  ctrls,
const int  numCtrls,
int *  targs,
const int  numTargs,
ComplexMatrixN  u 
)

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

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & \ddots \\ & & & u_{00} & u_{01} & \dots \\ & & & u_{10} & u_{11} & \dots \\ & & & \vdots & \vdots & \ddots \end{pmatrix} \]

on the control and target qubits.

The target qubits in targs are treated as ordered least sigifnicant to most significant in u.

The passed ComplexMatrix must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \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} } \]

Note that in multithreaded mode, each thread will clone 2^numTargs amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^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^numTargs amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^numTargs nodes.

Parameters
[in,out]quregobject representing the set of all qubits
[in]ctrlsa list of the control qubits
[in]numCtrlsthe number of control qubits
[in]targsa list of the target qubits, ordered least to most significant
[in]numTargsthe number of target qubits
[in]uunitary matrix to apply
Exceptions
exitWithErrorif any index in ctrls and targs is outside of [0, qureg.numQubitsRepresented), or if ctrls and targs are not unique, or if matrix u is not unitary, or if a node cannot fit the required number of target amplitudes in distributed mode.
Author
Tyson Jones

Definition at line 329 of file QuEST.c.

329  {
330  validateMultiControlsMultiTargets(qureg, ctrls, numCtrls, targs, numTargs, __func__);
331  validateMultiQubitUnitaryMatrix(qureg, u, numTargs, __func__);
332 
333  long long int ctrlMask = getQubitBitMask(ctrls, numCtrls);
334  statevec_multiControlledMultiQubitUnitary(qureg, ctrlMask, targs, numTargs, u);
335  if (qureg.isDensityMatrix) {
336  int shift = qureg.numQubitsRepresented;
337  shiftIndices(targs, numTargs, shift);
339  statevec_multiControlledMultiQubitUnitary(qureg, ctrlMask<<shift, targs, numTargs, u);
340  shiftIndices(targs, numTargs, -shift);
342  }
343 
344  qasm_recordComment(qureg, "Here, an undisclosed multi-controlled multi-qubit unitary was applied.");
345 }

References getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), setConjugateMatrixN(), shiftIndices(), statevec_multiControlledMultiQubitUnitary(), validateMultiControlsMultiTargets(), and validateMultiQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ multiControlledPhaseFlip()

void multiControlledPhaseFlip ( Qureg  qureg,
int *  controlQubits,
int  numControlQubits 
)

Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled pauliZ gate.

For each state, if all control qubits have value one, multiply the amplitude of that state by -1. This applies the many-qubit unitary:

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & \ddots \\ & & & 1 \\ & & & & -1 \end{pmatrix} \]

on the control qubits.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {controls}; \node[draw=none] at (0, 6) {$\vdots$}; \draw (0, 5) -- (0, 4); \draw (-2, 4) -- (2, 4); \draw[fill=black] (0, 4) circle (.2); \draw (0, 4) -- (0, 2); \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 0); \draw (-2,0) -- (2, 0); \draw[fill=black] (0, 0) circle (.2); \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitsarray of input qubits
[in]numControlQubitsnumber of input qubits
Exceptions
exitWithErrorif numControlQubits is outside [1, qureg.numQubitsRepresented), or if any qubit in controlQubits is outside [0, qureg.numQubitsRepresented), or if any qubit in qubits is repeated.
Author
Tyson Jones

Definition at line 559 of file QuEST.c.

559  {
560  validateMultiQubits(qureg, controlQubits, numControlQubits, __func__);
561 
562  statevec_multiControlledPhaseFlip(qureg, controlQubits, numControlQubits);
563  if (qureg.isDensityMatrix) {
564  int shift = qureg.numQubitsRepresented;
565  shiftIndices(controlQubits, numControlQubits, shift);
566  statevec_multiControlledPhaseFlip(qureg, controlQubits, numControlQubits);
567  shiftIndices(controlQubits, numControlQubits, -shift);
568  }
569 
570  qasm_recordMultiControlledGate(qureg, GATE_SIGMA_Z, controlQubits, numControlQubits-1, controlQubits[numControlQubits-1]);
571 }

References GATE_SIGMA_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiControlledGate(), shiftIndices(), statevec_multiControlledPhaseFlip(), and validateMultiQubits().

Referenced by TEST_CASE().

◆ multiControlledPhaseShift()

void multiControlledPhaseShift ( Qureg  qureg,
int *  controlQubits,
int  numControlQubits,
qreal  angle 
)

Introduce a phase factor $ \exp(i \theta) $ on state $ |1 \dots 1 \rangle $ of the passed qubits.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {controls}; \node[draw=none] at (1, .7) {$\theta$}; \node[draw=none] at (0, 6) {$\vdots$}; \draw (0, 5) -- (0, 4); \draw (-2, 4) -- (2, 4); \draw[fill=black] (0, 4) circle (.2); \draw (0, 4) -- (0, 2); \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 0); \draw (-2,0) -- (2, 0); \draw[fill=black] (0, 0) circle (.2); \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitsarray of qubits to phase shift
[in]numControlQubitsthe length of array controlQubits
[in]angleamount by which to shift the phase in radians
Exceptions
exitWithErrorif numControlQubits is outside [1, qureg.numQubitsRepresented]), or if any qubit index in controlQubits is outside [0, qureg.numQubitsRepresented]), or if any qubit in controlQubits is repeated.
Author
Tyson Jones

Definition at line 509 of file QuEST.c.

509  {
510  validateMultiQubits(qureg, controlQubits, numControlQubits, __func__);
511 
512  statevec_multiControlledPhaseShift(qureg, controlQubits, numControlQubits, angle);
513  if (qureg.isDensityMatrix) {
514  int shift = qureg.numQubitsRepresented;
515  shiftIndices(controlQubits, numControlQubits, shift);
516  statevec_multiControlledPhaseShift(qureg, controlQubits, numControlQubits, -angle);
517  shiftIndices(controlQubits, numControlQubits, -shift);
518  }
519 
520  qasm_recordMultiControlledParamGate(qureg, GATE_PHASE_SHIFT, controlQubits, numControlQubits-1, controlQubits[numControlQubits-1], angle);
521 }

References GATE_PHASE_SHIFT, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiControlledParamGate(), shiftIndices(), statevec_multiControlledPhaseShift(), and validateMultiQubits().

Referenced by TEST_CASE().

◆ multiControlledTwoQubitUnitary()

void multiControlledTwoQubitUnitary ( Qureg  qureg,
int *  controlQubits,
const int  numControlQubits,
const int  targetQubit1,
const int  targetQubit2,
ComplexMatrix4  u 
)

Apply a general multi-controlled two-qubit unitary (including a global phase factor).

Any number of control qubits can be specified, and if all have value 1, the given unitary is applied to the target qubit. This effects the many-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & \ddots \\ & & & u_{00} & u_{01} & u_{02} & u_{03} \\ & & & u_{10} & u_{11} & u_{12} & u_{13} \\ & & & u_{20} & u_{21} & u_{22} & u_{23} \\ & & & u_{30} & u_{31} & u_{32} & u_{33} \end{pmatrix} \]

on the control and target qubits.

targetQubit1 is treated as the least significant qubit in u, such that a row in u is dotted with the vector $ |\text{targetQubit2} \;\; \text{targetQubit1}\rangle : \{ |00\rangle, |01\rangle, |10\rangle, |11\rangle \} $

The passed 4x4 ComplexMatrix must be unitary, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target1}; \node[draw=none] at (-3.5, 2) {target2}; \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)--cycle; \node[draw=none] at (0, 1) {U}; \end{tikzpicture} } \]

Note that in distributed mode, this routine requires that each node contains at least 4 amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q/4 nodes.

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitsthe control qubits which all must be in state 1 to effect the given unitary
[in]numControlQubitsthe number of control qubits
[in]targetQubit1first target qubit, treated as least significant in u
[in]targetQubit2second target qubit, treated as most significant in u
[in]uunitary matrix to apply
Exceptions
exitWithErrorif targetQubit1 or targetQubit2 are outside [0, qureg.numQubitsRepresented), or if targetQubit1 equals targetQubit2, or if any qubit in controlQubits is outside [0, qureg.numQubitsRepresented), or if controlQubits are not unique, or if either targetQubit1 and targetQubit2 are in controlQubits, or if matrix u is not unitary, or if each node cannot fit 4 amplitudes in distributed mode.
Author
Tyson Jones

Definition at line 281 of file QuEST.c.

281  {
282  validateMultiControlsMultiTargets(qureg, controlQubits, numControlQubits, (int[]) {targetQubit1, targetQubit2}, 2, __func__);
283  validateTwoQubitUnitaryMatrix(qureg, u, __func__);
284 
285  long long int ctrlQubitsMask = getQubitBitMask(controlQubits, numControlQubits);
286  statevec_multiControlledTwoQubitUnitary(qureg, ctrlQubitsMask, targetQubit1, targetQubit2, u);
287  if (qureg.isDensityMatrix) {
288  int shift = qureg.numQubitsRepresented;
289  statevec_multiControlledTwoQubitUnitary(qureg, ctrlQubitsMask<<shift, targetQubit1+shift, targetQubit2+shift, getConjugateMatrix4(u));
290  }
291 
292  qasm_recordComment(qureg, "Here, an undisclosed multi-controlled 2-qubit unitary was applied.");
293 }

References getConjugateMatrix4(), getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_multiControlledTwoQubitUnitary(), validateMultiControlsMultiTargets(), and validateTwoQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ multiControlledUnitary()

void multiControlledUnitary ( Qureg  qureg,
int *  controlQubits,
const int  numControlQubits,
const int  targetQubit,
ComplexMatrix2  u 
)

Apply a general multiple-control single-target unitary, which can include a global phase factor.

Any number of control qubits can be specified, and if all have value 1, the given unitary is applied to the target qubit. This effects the many-qubit unitary

\[ \begin{pmatrix} 1 \\ & 1 \\\ & & \ddots \\ & & & u_{00} & u_{01}\\ & & & u_{10} & u_{11} \end{pmatrix} \]

on the control and target qubits. The given 2x2 ComplexMatrix must be unitary, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 3) {controls}; \node[draw=none] at (-3.5, 0) {target}; \node[draw=none] at (0, 6) {$\vdots$}; \draw (0, 5) -- (0, 4); \draw (-2, 4) -- (2, 4); \draw[fill=black] (0, 4) circle (.2); \draw (0, 4) -- (0, 2); \draw (-2, 2) -- (2, 2); \draw[fill=black] (0, 2) circle (.2); \draw (0, 2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {U}; \end{tikzpicture} } \]


Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitsapplies unitary if all qubits in this array equal 1
[in]numControlQubitsnumber of control qubits
[in]targetQubitqubit to operate on
[in]usingle-qubit unitary matrix to apply
Exceptions
exitWithErrorif numControlQubits is outside [1, qureg.numQubitsRepresented]), or if any qubit index (targetQubit or one in controlQubits) is outside [0, qureg.numQubitsRepresented]), or if any qubit in controlQubits is repeated, or if controlQubits contains targetQubit, or if u is not unitary.
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 372 of file QuEST.c.

372  {
373  validateMultiControlsTarget(qureg, controlQubits, numControlQubits, targetQubit, __func__);
374  validateOneQubitUnitaryMatrix(u, __func__);
375 
376  long long int ctrlQubitsMask = getQubitBitMask(controlQubits, numControlQubits);
377  long long int ctrlFlipMask = 0;
378  statevec_multiControlledUnitary(qureg, ctrlQubitsMask, ctrlFlipMask, targetQubit, u);
379  if (qureg.isDensityMatrix) {
380  int shift = qureg.numQubitsRepresented;
381  statevec_multiControlledUnitary(qureg, ctrlQubitsMask<<shift, ctrlFlipMask<<shift, targetQubit+shift, getConjugateMatrix2(u));
382  }
383 
384  qasm_recordMultiControlledUnitary(qureg, u, controlQubits, numControlQubits, targetQubit);
385 }

References getConjugateMatrix2(), getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiControlledUnitary(), statevec_multiControlledUnitary(), validateMultiControlsTarget(), and validateOneQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ multiQubitUnitary()

void multiQubitUnitary ( Qureg  qureg,
int *  targs,
const int  numTargs,
ComplexMatrixN  u 
)

Apply a general multi-qubit unitary (including a global phase factor) with any number of target qubits.

The first target qubit in targs is treated as least sigifnicant in u. For example,

multiQubitUnitary(qureg, (int []) {a, b, c}, 3, u);

will invoke multiplication

\[ \begin{pmatrix} u_{00} & u_{01} & u_{02} & u_{03} & u_{04} & u_{05} & u_{06} & u_{07} \\ u_{10} & u_{11} & u_{12} & u_{13} & u_{14} & u_{15} & u_{16} & u_{17} \\ u_{20} & u_{21} & u_{22} & u_{23} & u_{24} & u_{25} & u_{26} & u_{27} \\ u_{30} & u_{31} & u_{32} & u_{33} & u_{34} & u_{35} & u_{36} & u_{37} \\ u_{40} & u_{41} & u_{42} & u_{43} & u_{44} & u_{45} & u_{46} & u_{47} \\ u_{50} & u_{51} & u_{52} & u_{53} & u_{54} & u_{55} & u_{56} & u_{57} \\ u_{60} & u_{61} & u_{62} & u_{63} & u_{64} & u_{65} & u_{66} & u_{67} \\ u_{70} & u_{71} & u_{72} & u_{73} & u_{74} & u_{75} & u_{76} & u_{77} \\ \end{pmatrix} \begin{pmatrix} |cba\rangle = |000\rangle \\ |cba\rangle = |001\rangle \\ |cba\rangle = |010\rangle \\ |cba\rangle = |011\rangle \\ |cba\rangle = |100\rangle \\ |cba\rangle = |101\rangle \\ |cba\rangle = |110\rangle \\ |cba\rangle = |111\rangle \end{pmatrix} \]

The passed ComplexMatrix must be unitary and be a compatible size with the specified number of target qubits, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 1) {targets}; \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} } \]

Note that in multithreaded mode, each thread will clone 2^numTargs amplitudes, and store these in the runtime stack. Using t threads, the total memory overhead of this function is t*2^numTargs. For many targets (e.g. 16 qubits), this may cause a stack-overflow / seg-fault (e.g. on a 1 MiB stack).

Note too that in distributed mode, this routine requires that each node contains at least 2^numTargs amplitudes in the register. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q / 2^numTargs nodes.

Parameters
[in,out]quregobject representing the set of all qubits
[in]targsa list of the target qubits, ordered least significant to most in u
[in]numTargsthe number of target qubits
[in]uunitary matrix to apply
Exceptions
exitWithErrorif any index in targs is outside of [0, qureg.numQubitsRepresented), or if targs are not unique, or if matrix u is not unitary, or if a node cannot fit the required number of target amplitudes in distributed mode.
Author
Tyson Jones

Definition at line 295 of file QuEST.c.

295  {
296  validateMultiTargets(qureg, targs, numTargs, __func__);
297  validateMultiQubitUnitaryMatrix(qureg, u, numTargs, __func__);
298 
299  statevec_multiQubitUnitary(qureg, targs, numTargs, u);
300  if (qureg.isDensityMatrix) {
301  int shift = qureg.numQubitsRepresented;
302  shiftIndices(targs, numTargs, shift);
304  statevec_multiQubitUnitary(qureg, targs, numTargs, u);
305  shiftIndices(targs, numTargs, -shift);
307  }
308 
309  qasm_recordComment(qureg, "Here, an undisclosed multi-qubit unitary was applied.");
310 }

References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), setConjugateMatrixN(), shiftIndices(), statevec_multiQubitUnitary(), validateMultiQubitUnitaryMatrix(), and validateMultiTargets().

Referenced by TEST_CASE().

◆ multiRotatePauli()

void multiRotatePauli ( Qureg  qureg,
int *  targetQubits,
enum pauliOpType targetPaulis,
int  numTargets,
qreal  angle 
)

Apply a multi-qubit multi-Pauli rotation on a selected number of qubits.

This is the unitary

\[ \exp \left( - i \theta/2 \bigotimes_{j} \hat{\sigma}_j\right) \]

where $\hat{\sigma}_j \in \{X, Y, Z\}$ is a Pauli operator (indicated by codes 1, 2, 3 respectively in targetPaulis, or by enums PAULI_X, PAULI_Y and PAULI_Z) operating upon the qubit targetQubits[j], and $\theta$ is the passed angle. The operators specified in targetPaulis act on the corresponding qubit in targetQubits. For example:

multiRotatePauli(qureg, (int[]) {4,5,8,9}, (int[]) {0,1,2,3}, 4, .1)

effects

\[ \exp \left( - i .1/2 X_5 Y_8 Z_9 \right) \]

on qureg, where unspecified qubits (along with those specified with Pauli code 0) are assumed to receive the identity operator (excluded from exponentiation). Note that specifying the identity Pauli (code=0 or PAULI_I) on a qubit is superfluous but allowed for convenience. This is means a global phase factor of $ exp(-i \theta/2) $ is NOT induced by supplying 0 pauli-codes. Hence, if all targetPaulis are identity, then this function does nothing to qureg.

This function effects this unitary by first rotating the qubits which are nominated to receive X or Y Paulis into alternate basis, performing multiRotateZ on all target qubits receiving X, Y or Z Paulis, then restoring the original basis. In the worst case, this means that 1+2*numTargets primitive unitaries are performed on the statevector, and double this on density matrices.

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitsa list of the indices of the target qubits
[in]targetPaulisa list of the Pauli codes (0=PAULI_I, 1=PAULI_X, 2=PAULI_Y, 3=PAULI_Z) to apply to the corresponding qubits in targetQubits
[in]numTargetsnumber of target qubits, i.e. the length of targetQubits and targetPaulis
[in]anglethe angle by which the multi-qubit state is rotated
Exceptions
exitWithErrorif numQubits is outside [1, qureg.numQubitsRepresented]), or if any qubit in qubits is outside [0, qureg.numQubitsRepresented)) or if any qubit in qubits is repeated.
Author
Tyson Jones

Definition at line 640 of file QuEST.c.

640  {
641  validateMultiTargets(qureg, targetQubits, numTargets, __func__);
642  validatePauliCodes(targetPaulis, numTargets, __func__);
643 
644  int conj=0;
645  statevec_multiRotatePauli(qureg, targetQubits, targetPaulis, numTargets, angle, conj);
646  if (qureg.isDensityMatrix) {
647  conj = 1;
648  int shift = qureg.numQubitsRepresented;
649  shiftIndices(targetQubits, numTargets, shift);
650  statevec_multiRotatePauli(qureg, targetQubits, targetPaulis, numTargets, angle, conj);
651  shiftIndices(targetQubits, numTargets, -shift);
652  }
653 
654  // @TODO: create actual QASM
655  qasm_recordComment(qureg,
656  "Here a %d-qubit multiRotatePauli of angle %g was performed (QASM not yet implemented)",
657  numTargets, angle);
658 }

References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), shiftIndices(), statevec_multiRotatePauli(), validateMultiTargets(), and validatePauliCodes().

Referenced by TEST_CASE().

◆ multiRotateZ()

void multiRotateZ ( Qureg  qureg,
int *  qubits,
int  numQubits,
qreal  angle 
)

Apply a multi-qubit Z rotation on a selected number of qubits.

This is the unitary

\[ \exp \left( - i \theta/2 \bigotimes_{j} Z_j\right) \]

where the Pauli Z gates operate upon the passed list $j \in$ qubits, and cause rotations of $\theta =$ angle. All qubits not appearing in qubits are assumed to receive the identity operator. This has the effect of premultiplying every amplitude with $\exp(\pm i \theta/2)$ where the sign is determined by the parity of the target qubits for that amplitude.

Parameters
[in,out]quregobject representing the set of all qubits
[in]qubitsa list of the indices of the target qubits
[in]numQubitsnumber of target qubits
[in]anglethe angle by which the multi-qubit state is rotated around the Z axis
Exceptions
exitWithErrorif numQubits is outside [1, qureg.numQubitsRepresented]), or if any qubit in qubits is outside [0, qureg.numQubitsRepresented]) or if any qubit in qubits is repeated.
Author
Tyson Jones

Definition at line 624 of file QuEST.c.

624  {
625  validateMultiTargets(qureg, qubits, numQubits, __func__);
626 
627  long long int mask = getQubitBitMask(qubits, numQubits);
628  statevec_multiRotateZ(qureg, mask, angle);
629  if (qureg.isDensityMatrix) {
630  int shift = qureg.numQubitsRepresented;
631  statevec_multiRotateZ(qureg, mask << shift, -angle);
632  }
633 
634  // @TODO: create actual QASM
635  qasm_recordComment(qureg,
636  "Here a %d-qubit multiRotateZ of angle %g was performed (QASM not yet implemented)",
637  numQubits, angle);
638 }

References getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_multiRotateZ(), and validateMultiTargets().

Referenced by TEST_CASE().

◆ multiStateControlledUnitary()

void multiStateControlledUnitary ( Qureg  qureg,
int *  controlQubits,
int *  controlState,
const int  numControlQubits,
const int  targetQubit,
ComplexMatrix2  u 
)

Apply a general multiple-control, conditioned on a specific bit sequence, single-target unitary, which can include a global phase factor.

Any number of control qubits can be specified, along with which of their states (0 or 1) to condition upon; when the specified controls are in the specified state, the given unitary is applied to the target qubit. This is equivalent to NOTing the control bits which are conditioned on 0, calling multiControlledUnitary then NOTing the same control bits.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 3) {controls}; \node[draw=none] at (-3.5, 0) {target}; \node[draw=none] at (0, 6) {$\vdots$}; \draw (0, 5) -- (0, 4); \draw (-2, 4) -- (2, 4); \draw[fill=black] (0, 4) circle (.2); \draw (0, 4) -- (0, 2); \draw (-2, 2) -- (2, 2); \draw[fill=white] (0, 2) circle (.2); \draw (0, 2-.2) -- (0, 1); \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {U}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]controlQubitsthe indices of the control qubits
[in]controlStatethe bit values (0 or 1) of each control qubit, upon which to condition
[in]numControlQubitsnumber of control qubits
[in]targetQubitqubit to operate the unitary upon
[in]usingle-qubit unitary matrix to apply
Exceptions
exitWithErrorif numControlQubits is outside [1, qureg.numQubitsRepresented]), or if any qubit index (targetQubit or one in controlQubits) is outside [0, qureg.numQubitsRepresented]), or if any qubit in controlQubits is repeated., or if controlQubits contains targetQubit, or if any element of controlState is not a bit (0 or 1), or if u is not unitary.
Author
Tyson Jones

Definition at line 387 of file QuEST.c.

387  {
388  validateMultiControlsTarget(qureg, controlQubits, numControlQubits, targetQubit, __func__);
389  validateOneQubitUnitaryMatrix(u, __func__);
390  validateControlState(controlState, numControlQubits, __func__);
391 
392  long long int ctrlQubitsMask = getQubitBitMask(controlQubits, numControlQubits);
393  long long int ctrlFlipMask = getControlFlipMask(controlQubits, controlState, numControlQubits);
394  statevec_multiControlledUnitary(qureg, ctrlQubitsMask, ctrlFlipMask, targetQubit, u);
395  if (qureg.isDensityMatrix) {
396  int shift = qureg.numQubitsRepresented;
397  statevec_multiControlledUnitary(qureg, ctrlQubitsMask<<shift, ctrlFlipMask<<shift, targetQubit+shift, getConjugateMatrix2(u));
398  }
399 
400  qasm_recordMultiStateControlledUnitary(qureg, u, controlQubits, controlState, numControlQubits, targetQubit);
401 }

References getConjugateMatrix2(), getControlFlipMask(), getQubitBitMask(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordMultiStateControlledUnitary(), statevec_multiControlledUnitary(), validateControlState(), validateMultiControlsTarget(), and validateOneQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ pauliX()

void pauliX ( Qureg  qureg,
const int  targetQubit 
)

Apply the single-qubit Pauli-X (also known as the X, sigma-X, NOT or bit-flip) gate.

This is a rotation of $\pi$ around the x-axis on the Bloch sphere. I.e.

\[ \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (2, 0); \draw (0, 0) circle (.5); \draw (0, .5) -- (0, -.5); \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 431 of file QuEST.c.

431  {
432  validateTarget(qureg, targetQubit, __func__);
433 
434  statevec_pauliX(qureg, targetQubit);
435  if (qureg.isDensityMatrix) {
436  statevec_pauliX(qureg, targetQubit+qureg.numQubitsRepresented);
437  }
438 
439  qasm_recordGate(qureg, GATE_SIGMA_X, targetQubit);
440 }

References GATE_SIGMA_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_pauliX(), and validateTarget().

Referenced by TEST_CASE().

◆ pauliY()

void pauliY ( Qureg  qureg,
const int  targetQubit 
)

Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate.

This is a rotation of $\pi$ around the Y-axis on the Bloch sphere. I.e.

\[ \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$\sigma_y$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 442 of file QuEST.c.

442  {
443  validateTarget(qureg, targetQubit, __func__);
444 
445  statevec_pauliY(qureg, targetQubit);
446  if (qureg.isDensityMatrix) {
447  statevec_pauliYConj(qureg, targetQubit + qureg.numQubitsRepresented);
448  }
449 
450  qasm_recordGate(qureg, GATE_SIGMA_Y, targetQubit);
451 }

References GATE_SIGMA_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_pauliY(), statevec_pauliYConj(), and validateTarget().

Referenced by TEST_CASE().

◆ pauliZ()

void pauliZ ( Qureg  qureg,
const int  targetQubit 
)

Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate.

This is a rotation of $\pi$ around the Z-axis (a phase shift) on the Bloch sphere. I.e.

\[ \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$\sigma_z$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 453 of file QuEST.c.

453  {
454  validateTarget(qureg, targetQubit, __func__);
455 
456  statevec_pauliZ(qureg, targetQubit);
457  if (qureg.isDensityMatrix) {
458  statevec_pauliZ(qureg, targetQubit+qureg.numQubitsRepresented);
459  }
460 
461  qasm_recordGate(qureg, GATE_SIGMA_Z, targetQubit);
462 }

References GATE_SIGMA_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_pauliZ(), and validateTarget().

Referenced by TEST_CASE().

◆ phaseShift()

void phaseShift ( Qureg  qureg,
const int  targetQubit,
qreal  angle 
)

Shift the phase between $ |0\rangle $ and $ |1\rangle $ of a single qubit by a given angle.

This is equivalent to a rotation Z-axis of the Bloch-sphere up to a global phase factor. For angle $\theta$, applies

\[ \begin{pmatrix} 1 & 0 \\ 0 & \exp(i \theta) \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {rot}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_\theta$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to undergo a phase shift
[in]angleamount by which to shift the phase in radians
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented).
Author
Tyson Jones

Definition at line 486 of file QuEST.c.

486  {
487  validateTarget(qureg, targetQubit, __func__);
488 
489  statevec_phaseShift(qureg, targetQubit, angle);
490  if (qureg.isDensityMatrix) {
491  statevec_phaseShift(qureg, targetQubit+qureg.numQubitsRepresented, -angle);
492  }
493 
494  qasm_recordParamGate(qureg, GATE_PHASE_SHIFT, targetQubit, angle);
495 }

References GATE_PHASE_SHIFT, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_phaseShift(), and validateTarget().

Referenced by TEST_CASE().

◆ rotateAroundAxis()

void rotateAroundAxis ( Qureg  qureg,
const int  rotQubit,
qreal  angle,
Vector  axis 
)

Rotate a single qubit by a given angle around a given Vector on the Bloch-sphere.


The vector must not be zero (else an error is thrown), but needn't be unit magnitude, since it will be normalised by QuEST.

For angle $\theta$ and axis vector $\vec{n}$, applies $R_{\hat{n}} = \exp \left(- i \frac{\theta}{2} \hat{n} \cdot \vec{\sigma} \right) $ where $\vec{\sigma}$ is the vector of Pauli matrices.

Parameters
[in,out]quregobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
[in]axisvector around which to rotate (can be non-unit; will be normalised)
Exceptions
exitWithErrorif rotQubit is outside [0, qureg.numQubitsRepresented), or if axis is the zero vector
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 573 of file QuEST.c.

573  {
574  validateTarget(qureg, rotQubit, __func__);
575  validateVector(axis, __func__);
576 
577  statevec_rotateAroundAxis(qureg, rotQubit, angle, axis);
578  if (qureg.isDensityMatrix) {
579  int shift = qureg.numQubitsRepresented;
580  statevec_rotateAroundAxisConj(qureg, rotQubit+shift, angle, axis);
581  }
582 
583  qasm_recordAxisRotation(qureg, angle, axis, rotQubit);
584 }

References Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordAxisRotation(), statevec_rotateAroundAxis(), statevec_rotateAroundAxisConj(), validateTarget(), and validateVector().

Referenced by TEST_CASE().

◆ rotateX()

void rotateX ( Qureg  qureg,
const int  rotQubit,
qreal  angle 
)

Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere.

For angle $\theta$, applies

\[ \begin{pmatrix} \cos\theta/2 & -i \sin \theta/2\\ -i \sin \theta/2 & \cos \theta/2 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {rot}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_x(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
Exceptions
exitWithErrorif rotQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 186 of file QuEST.c.

186  {
187  validateTarget(qureg, targetQubit, __func__);
188 
189  statevec_rotateX(qureg, targetQubit, angle);
190  if (qureg.isDensityMatrix) {
191  statevec_rotateX(qureg, targetQubit+qureg.numQubitsRepresented, -angle);
192  }
193 
194  qasm_recordParamGate(qureg, GATE_ROTATE_X, targetQubit, angle);
195 }

References GATE_ROTATE_X, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_rotateX(), and validateTarget().

Referenced by TEST_CASE().

◆ rotateY()

void rotateY ( Qureg  qureg,
const int  rotQubit,
qreal  angle 
)

Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere.

For angle $\theta$, applies

\[ \begin{pmatrix} \cos\theta/2 & - \sin \theta/2\\ \sin \theta/2 & \cos \theta/2 \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {rot}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_y(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
Exceptions
exitWithErrorif rotQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc, debug)

Definition at line 197 of file QuEST.c.

197  {
198  validateTarget(qureg, targetQubit, __func__);
199 
200  statevec_rotateY(qureg, targetQubit, angle);
201  if (qureg.isDensityMatrix) {
202  statevec_rotateY(qureg, targetQubit+qureg.numQubitsRepresented, angle);
203  }
204 
205  qasm_recordParamGate(qureg, GATE_ROTATE_Y, targetQubit, angle);
206 }

References GATE_ROTATE_Y, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_rotateY(), and validateTarget().

Referenced by TEST_CASE().

◆ rotateZ()

void rotateZ ( Qureg  qureg,
const int  rotQubit,
qreal  angle 
)

Rotate a single qubit by a given angle around the Z-axis of the Bloch-sphere (also known as a phase shift gate).


For angle $\theta$, applies

\[ \begin{pmatrix} \exp(-i \theta/2) & 0 \\ 0 & \exp(i \theta/2) \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {rot}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {$R_z(\theta)$}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
Exceptions
exitWithErrorif rotQubit is outside [0, qureg.numQubitsRepresented).
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 208 of file QuEST.c.

208  {
209  validateTarget(qureg, targetQubit, __func__);
210 
211  statevec_rotateZ(qureg, targetQubit, angle);
212  if (qureg.isDensityMatrix) {
213  statevec_rotateZ(qureg, targetQubit+qureg.numQubitsRepresented, -angle);
214  }
215 
216  qasm_recordParamGate(qureg, GATE_ROTATE_Z, targetQubit, angle);
217 }

References GATE_ROTATE_Z, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordParamGate(), statevec_rotateZ(), and validateTarget().

Referenced by TEST_CASE().

◆ sGate()

void sGate ( Qureg  qureg,
const int  targetQubit 
)

Apply the single-qubit S gate.

This is a rotation of $\pi/2$ around the Z-axis on the Bloch sphere, or the unitary:

\[ \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {S}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate upon
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented)
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 464 of file QuEST.c.

464  {
465  validateTarget(qureg, targetQubit, __func__);
466 
467  statevec_sGate(qureg, targetQubit);
468  if (qureg.isDensityMatrix) {
469  statevec_sGateConj(qureg, targetQubit+qureg.numQubitsRepresented);
470  }
471 
472  qasm_recordGate(qureg, GATE_S, targetQubit);
473 }

References GATE_S, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_sGate(), statevec_sGateConj(), and validateTarget().

Referenced by TEST_CASE().

◆ sqrtSwapGate()

void sqrtSwapGate ( Qureg  qureg,
int  qb1,
int  qb2 
)

Performs a sqrt SWAP gate between qubit1 and qubit2.

This effects

\[ \begin{pmatrix} 1 \\ & \frac{1}{2}(1+i) & \frac{1}{2}(1-i) \\\ & \frac{1}{2}(1-i) & \frac{1}{2}(1+i) \\ & & & 1 \end{pmatrix} \]

on the designated qubits, though is performed internally by three CNOT gates.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {qubit1}; \node[draw=none] at (-3.5, 0) {qubit2}; \draw (-2, 2) -- (2, 2); \draw (0, 2) -- (0, 0); \draw (-2,0) -- (2, 0); \draw (-.35,-.35) -- (.35,.35); \draw (-.35,.35) -- (.35,-.35); \draw (-.35,-.35 + 2) -- (.35,.35 + 2); \draw (-.35,.35 + 2) -- (.35,-.35 + 2); \draw[fill=white] (0, 1) circle (.5); \node[draw=none] at (0, 1) {1/2}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]qubit1qubit to sqrt swap
[in]qubit2other qubit to sqrt swap
Exceptions
exitWithErrorif either qubit1 or qubit2 are outside [0, qureg.numQubitsRepresented), or are equal.
Author
Tyson Jones

Definition at line 611 of file QuEST.c.

611  {
612  validateUniqueTargets(qureg, qb1, qb2, __func__);
613  validateMultiQubitMatrixFitsInNode(qureg, 2, __func__); // uses 2qb unitary in QuEST_common
614 
615  statevec_sqrtSwapGate(qureg, qb1, qb2);
616  if (qureg.isDensityMatrix) {
617  int shift = qureg.numQubitsRepresented;
618  statevec_sqrtSwapGateConj(qureg, qb1+shift, qb2+shift);
619  }
620 
621  qasm_recordControlledGate(qureg, GATE_SQRT_SWAP, qb1, qb2);
622 }

References GATE_SQRT_SWAP, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_sqrtSwapGate(), statevec_sqrtSwapGateConj(), validateMultiQubitMatrixFitsInNode(), and validateUniqueTargets().

Referenced by TEST_CASE().

◆ swapGate()

void swapGate ( Qureg  qureg,
int  qubit1,
int  qubit2 
)

Performs a SWAP gate between qubit1 and qubit2.

This effects

\[ \begin{pmatrix} 1 \\ & & 1 \\\ & 1 \\ & & & 1 \end{pmatrix} \]

on the designated qubits, though is performed internally by three CNOT gates.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 2) {qubit1}; \node[draw=none] at (-3.5, 0) {qubit2}; \draw (-2, 2) -- (2, 2); \draw (0, 2) -- (0, 0); \draw (-2,0) -- (2, 0); \draw (-.35,-.35) -- (.35,.35); \draw (-.35,.35) -- (.35,-.35); \draw (-.35,-.35 + 2) -- (.35,.35 + 2); \draw (-.35,.35 + 2) -- (.35,-.35 + 2); \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]qubit1qubit to swap
[in]qubit2other qubit to swap
Exceptions
exitWithErrorif either qubit1 or qubit2 are outside [0, qureg.numQubitsRepresented), or are equal.
Author
Tyson Jones

Definition at line 599 of file QuEST.c.

599  {
600  validateUniqueTargets(qureg, qb1, qb2, __func__);
601 
602  statevec_swapQubitAmps(qureg, qb1, qb2);
603  if (qureg.isDensityMatrix) {
604  int shift = qureg.numQubitsRepresented;
605  statevec_swapQubitAmps(qureg, qb1+shift, qb2+shift);
606  }
607 
608  qasm_recordControlledGate(qureg, GATE_SWAP, qb1, qb2);
609 }

References GATE_SWAP, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordControlledGate(), statevec_swapQubitAmps(), and validateUniqueTargets().

Referenced by TEST_CASE().

◆ tGate()

void tGate ( Qureg  qureg,
const int  targetQubit 
)

Apply the single-qubit T gate.

This is a rotation of $\pi/4$ around the Z-axis on the Bloch sphere, or the unitary:

\[ \begin{pmatrix} 1 & 0 \\ 0 & \exp\left(i \frac{\pi}{4}\right) \end{pmatrix} \]

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {T}; \end{tikzpicture} } \]

Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate upon
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented)
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 475 of file QuEST.c.

475  {
476  validateTarget(qureg, targetQubit, __func__);
477 
478  statevec_tGate(qureg, targetQubit);
479  if (qureg.isDensityMatrix) {
480  statevec_tGateConj(qureg, targetQubit+qureg.numQubitsRepresented);
481  }
482 
483  qasm_recordGate(qureg, GATE_T, targetQubit);
484 }

References GATE_T, Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordGate(), statevec_tGate(), statevec_tGateConj(), and validateTarget().

Referenced by TEST_CASE().

◆ twoQubitUnitary()

void twoQubitUnitary ( Qureg  qureg,
const int  targetQubit1,
const int  targetQubit2,
ComplexMatrix4  u 
)

Apply a general two-qubit unitary (including a global phase factor).

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target2}; \node[draw=none] at (-3.5, 2) {target1}; \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)--cycle; \node[draw=none] at (0, 1) {U}; \end{tikzpicture} } \]

targetQubit1 is treated as the least significant qubit in u, such that a row in u is dotted with the vector $ |\text{targetQubit2} \;\; \text{targetQubit1}\rangle : \{ |00\rangle, |01\rangle, |10\rangle, |11\rangle \} $

For example,

twoQubitUnitary(qureg, a, b, u);

will invoke multiplication

\[ \begin{pmatrix} u_{00} & u_{01} & u_{02} & u_{03} \\ u_{10} & u_{11} & u_{12} & u_{13} \\ u_{20} & u_{21} & u_{22} & u_{23} \\ u_{30} & u_{31} & u_{32} & u_{33} \end{pmatrix} \begin{pmatrix} |ba\rangle = |00\rangle \\ |ba\rangle = |01\rangle \\ |ba\rangle = |10\rangle \\ |ba\rangle = |11\rangle \end{pmatrix} \]

The passed 4x4 ComplexMatrix must be unitary, otherwise an error is thrown.

Note that in distributed mode, this routine requires that each node contains at least 4 amplitudes. This means an q-qubit register (state vector or density matrix) can be distributed by at most 2^q/4 nodes.


Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubit1first qubit to operate on, treated as least significant in u
[in]targetQubit2second qubit to operate on, treated as most significant in u
[in]uunitary matrix to apply
Exceptions
exitWithErrorif targetQubit1 or targetQubit2 are outside [0, qureg.numQubitsRepresented), or if targetQubit1 equals targetQubit2, or matrix u is not unitary, or if each node cannot fit 4 amplitudes in distributed mode.
Author
Tyson Jones

Definition at line 255 of file QuEST.c.

255  {
256  validateMultiTargets(qureg, (int []) {targetQubit1, targetQubit2}, 2, __func__);
257  validateTwoQubitUnitaryMatrix(qureg, u, __func__);
258 
259  statevec_twoQubitUnitary(qureg, targetQubit1, targetQubit2, u);
260  if (qureg.isDensityMatrix) {
261  int shift = qureg.numQubitsRepresented;
262  statevec_twoQubitUnitary(qureg, targetQubit1+shift, targetQubit2+shift, getConjugateMatrix4(u));
263  }
264 
265  qasm_recordComment(qureg, "Here, an undisclosed 2-qubit unitary was applied.");
266 }

References getConjugateMatrix4(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordComment(), statevec_twoQubitUnitary(), validateMultiTargets(), and validateTwoQubitUnitaryMatrix().

Referenced by TEST_CASE().

◆ unitary()

void unitary ( Qureg  qureg,
const int  targetQubit,
ComplexMatrix2  u 
)

Apply a general single-qubit unitary (including a global phase factor).

The passed 2x2 ComplexMatrix must be unitary, otherwise an error is thrown.

\[ \setlength{\fboxrule}{0.01pt} \fbox{ \begin{tikzpicture}[scale=.5] \node[draw=none] at (-3.5, 0) {target}; \draw (-2,0) -- (-1, 0); \draw (1, 0) -- (2, 0); \draw (-1,-1)--(-1,1)--(1,1)--(1,-1)--cycle; \node[draw=none] at (0, 0) {U}; \end{tikzpicture} } \]


Parameters
[in,out]quregobject representing the set of all qubits
[in]targetQubitqubit to operate on
[in]uunitary matrix to apply
Exceptions
exitWithErrorif targetQubit is outside [0, qureg.numQubitsRepresented), or matrix u is not unitary.
Author
Ania Brown (state-vector)
Tyson Jones (density matrix, doc)

Definition at line 347 of file QuEST.c.

347  {
348  validateTarget(qureg, targetQubit, __func__);
349  validateOneQubitUnitaryMatrix(u, __func__);
350 
351  statevec_unitary(qureg, targetQubit, u);
352  if (qureg.isDensityMatrix) {
353  statevec_unitary(qureg, targetQubit+qureg.numQubitsRepresented, getConjugateMatrix2(u));
354  }
355 
356  qasm_recordUnitary(qureg, u, targetQubit);
357 }

References getConjugateMatrix2(), Qureg::isDensityMatrix, Qureg::numQubitsRepresented, qasm_recordUnitary(), statevec_unitary(), validateOneQubitUnitaryMatrix(), and validateTarget().

Referenced by TEST_CASE().

void statevec_pauliYConj(Qureg qureg, const int targetQubit)
void validateTarget(Qureg qureg, int targetQubit, const char *caller)
void statevec_multiQubitUnitary(Qureg qureg, int *targets, const int numTargets, ComplexMatrixN u)
Definition: QuEST_common.c:528
void statevec_pauliY(Qureg qureg, const int targetQubit)
void statevec_hadamard(Qureg qureg, const int targetQubit)
void qasm_recordParamGate(Qureg qureg, TargetGate gate, int targetQubit, qreal param)
Definition: QuEST_qasm.c:186
void shiftIndices(int *indices, int numIndices, int shift)
Definition: QuEST_common.c:149
@ GATE_T
Definition: QuEST_qasm.h:24
@ GATE_PHASE_SHIFT
Definition: QuEST_qasm.h:32
void qasm_recordUnitary(Qureg qureg, ComplexMatrix2 u, int targetQubit)
Definition: QuEST_qasm.c:207
void statevec_controlledRotateAroundAxisConj(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle, Vector axis)
Definition: QuEST_common.c:333
void statevec_controlledTwoQubitUnitary(Qureg qureg, const int controlQubit, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
Definition: QuEST_common.c:522
void validateMultiQubitMatrixFitsInNode(Qureg qureg, int numTargets, const char *caller)
void statevec_phaseShift(Qureg qureg, const int targetQubit, qreal angle)
Definition: QuEST_common.c:250
ComplexMatrix4 getConjugateMatrix4(ComplexMatrix4 src)
Definition: QuEST_common.c:103
@ GATE_ROTATE_X
Definition: QuEST_qasm.h:27
void validateMultiQubitUnitaryMatrix(Qureg qureg, ComplexMatrixN u, int numTargs, const char *caller)
void statevec_multiRotateZ(Qureg qureg, long long int mask, qreal angle)
Definition: QuEST_cpu.c:3069
void statevec_multiControlledMultiQubitUnitary(Qureg qureg, long long int ctrlMask, int *targs, const int numTargs, ComplexMatrixN u)
This calls swapQubitAmps only when it would involve a distributed communication; if the qubit chunks ...
void qasm_recordControlledCompactUnitary(Qureg qureg, Complex alpha, Complex beta, int controlQubit, int targetQubit)
Definition: QuEST_qasm.c:264
@ GATE_ROTATE_Z
Definition: QuEST_qasm.h:29
@ GATE_SIGMA_Z
Definition: QuEST_qasm.h:23
void statevec_pauliX(Qureg qureg, const int targetQubit)
Complex getConjugateScalar(Complex scalar)
Definition: QuEST_common.c:84
@ GATE_HADAMARD
Definition: QuEST_qasm.h:26
ComplexMatrix2 getConjugateMatrix2(ComplexMatrix2 src)
Definition: QuEST_common.c:98
void statevec_rotateZ(Qureg qureg, const int rotQubit, qreal angle)
Definition: QuEST_common.c:304
void statevec_controlledNot(Qureg qureg, const int controlQubit, const int targetQubit)
void validateMultiTargets(Qureg qureg, int *targetQubits, const int numTargetQubits, const char *caller)
void statevec_multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle)
Definition: QuEST_cpu.c:3019
long long int getControlFlipMask(int *controlQubits, int *controlState, const int numControlQubits)
Definition: QuEST_common.c:53
void statevec_sqrtSwapGate(Qureg qureg, int qb1, int qb2)
Definition: QuEST_common.c:383
void qasm_recordMultiControlledParamGate(Qureg qureg, TargetGate gate, int *controlQubits, const int numControlQubits, const int targetQubit, qreal param)
Definition: QuEST_qasm.c:324
void qasm_recordAxisRotation(Qureg qureg, qreal angle, Vector axis, const int targetQubit)
Definition: QuEST_qasm.c:223
void statevec_swapQubitAmps(Qureg qureg, int qb1, int qb2)
void statevec_tGate(Qureg qureg, const int targetQubit)
Definition: QuEST_common.c:271
void validateVector(Vector vec, const char *caller)
void statevec_rotateAroundAxisConj(Qureg qureg, const int rotQubit, qreal angle, Vector axis)
Definition: QuEST_common.c:317
long long int getQubitBitMask(int *qubits, const int numQubits)
Definition: QuEST_common.c:43
void qasm_recordControlledGate(Qureg qureg, TargetGate gate, int controlQubit, int targetQubit)
Definition: QuEST_qasm.c:238
void qasm_recordMultiStateControlledUnitary(Qureg qureg, ComplexMatrix2 u, int *controlQubits, int *controlState, const int numControlQubits, const int targetQubit)
Definition: QuEST_qasm.c:362
void validateControlTarget(Qureg qureg, int controlQubit, int targetQubit, const char *caller)
void statevec_rotateX(Qureg qureg, const int rotQubit, qreal angle)
Definition: QuEST_common.c:292
@ GATE_SQRT_SWAP
Definition: QuEST_qasm.h:34
void statevec_twoQubitUnitary(Qureg qureg, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
Definition: QuEST_common.c:516
@ GATE_SIGMA_X
Definition: QuEST_qasm.h:21
void statevec_pauliZ(Qureg qureg, const int targetQubit)
Definition: QuEST_common.c:257
void statevec_controlledRotateZ(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
Definition: QuEST_common.c:354
void qasm_recordControlledParamGate(Qureg qureg, TargetGate gate, int controlQubit, int targetQubit, qreal param)
Definition: QuEST_qasm.c:247
void setConjugateMatrixN(ComplexMatrixN m)
Definition: QuEST_common.c:108
void qasm_recordControlledAxisRotation(Qureg qureg, qreal angle, Vector axis, int controlQubit, int targetQubit)
Definition: QuEST_qasm.c:300
void qasm_recordMultiControlledUnitary(Qureg qureg, ComplexMatrix2 u, int *controlQubits, const int numControlQubits, const int targetQubit)
additionally performs Rz on target to restore the global phase lost from u in QASM U(a,...
Definition: QuEST_qasm.c:341
void statevec_multiRotatePauli(Qureg qureg, int *targetQubits, enum pauliOpType *targetPaulis, int numTargets, qreal angle, int applyConj)
applyConj=1 will apply conjugate operation, else applyConj=0
Definition: QuEST_common.c:410
void statevec_multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits)
Definition: QuEST_cpu.c:3291
void qasm_recordComment(Qureg qureg, char *comment,...)
Definition: QuEST_qasm.c:120
void statevec_sGateConj(Qureg qureg, const int targetQubit)
Definition: QuEST_common.c:278
void statevec_multiControlledUnitary(Qureg qureg, long long int ctrlQubitsMask, long long int ctrlFlipMask, const int targetQubit, ComplexMatrix2 u)
void statevec_rotateY(Qureg qureg, const int rotQubit, qreal angle)
Definition: QuEST_common.c:298
void statevec_controlledUnitary(Qureg qureg, const int controlQubit, const int targetQubit, ComplexMatrix2 u)
void validateMultiQubits(Qureg qureg, int *qubits, const int numQubits, const char *caller)
void statevec_controlledPhaseShift(Qureg qureg, const int idQubit1, const int idQubit2, qreal angle)
Definition: QuEST_cpu.c:2980
void statevec_controlledPhaseFlip(Qureg qureg, const int idQubit1, const int idQubit2)
Definition: QuEST_cpu.c:3260
void validateTwoQubitUnitaryMatrix(Qureg qureg, ComplexMatrix4 u, const char *caller)
void statevec_controlledRotateY(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
Definition: QuEST_common.c:348
int isDensityMatrix
Whether this instance is a density-state representation.
Definition: QuEST.h:163
void statevec_controlledCompactUnitary(Qureg qureg, const int controlQubit, const int targetQubit, Complex alpha, Complex beta)
void statevec_sGate(Qureg qureg, const int targetQubit)
Definition: QuEST_common.c:264
void statevec_tGateConj(Qureg qureg, const int targetQubit)
Definition: QuEST_common.c:285
void validateOneQubitUnitaryMatrix(ComplexMatrix2 u, const char *caller)
void statevec_sqrtSwapGateConj(Qureg qureg, int qb1, int qb2)
Definition: QuEST_common.c:396
void statevec_controlledMultiQubitUnitary(Qureg qureg, int ctrl, int *targets, const int numTargets, ComplexMatrixN u)
Definition: QuEST_common.c:534
int numQubitsRepresented
The number of qubits represented in either the state-vector or density matrix.
Definition: QuEST.h:165
@ GATE_S
Definition: QuEST_qasm.h:25
@ GATE_SWAP
Definition: QuEST_qasm.h:33
void validateControlState(int *controlState, const int numControlQubits, const char *caller)
void statevec_controlledRotateX(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle)
Definition: QuEST_common.c:342
void statevec_controlledPauliYConj(Qureg qureg, const int controlQubit, const int targetQubit)
@ GATE_SIGMA_Y
Definition: QuEST_qasm.h:22
void statevec_unitary(Qureg qureg, const int targetQubit, ComplexMatrix2 u)
void qasm_recordCompactUnitary(Qureg qureg, Complex alpha, Complex beta, int targetQubit)
Definition: QuEST_qasm.c:195
void statevec_controlledRotateAroundAxis(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle, Vector axis)
Definition: QuEST_common.c:326
void qasm_recordControlledUnitary(Qureg qureg, ComplexMatrix2 u, int controlQubit, int targetQubit)
additionally performs Rz on target to restore the global phase lost from u in QASM U(a,...
Definition: QuEST_qasm.c:278
void statevec_rotateAroundAxis(Qureg qureg, const int rotQubit, qreal angle, Vector axis)
Definition: QuEST_common.c:310
void statevec_multiControlledTwoQubitUnitary(Qureg qureg, long long int ctrlMask, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
This calls swapQubitAmps only when it would involve a distributed communication; if the qubit chunks ...
void qasm_recordMultiControlledGate(Qureg qureg, TargetGate gate, int *controlQubits, const int numControlQubits, const int targetQubit)
Definition: QuEST_qasm.c:316
void qasm_recordGate(Qureg qureg, TargetGate gate, int targetQubit)
Definition: QuEST_qasm.c:178
void validatePauliCodes(enum pauliOpType *pauliCodes, int numPauliCodes, const char *caller)
void validateUnitaryComplexPair(Complex alpha, Complex beta, const char *caller)
@ GATE_ROTATE_Y
Definition: QuEST_qasm.h:28
void validateMultiControlsMultiTargets(Qureg qureg, int *controlQubits, const int numControlQubits, int *targetQubits, const int numTargetQubits, const char *caller)
void statevec_controlledPauliY(Qureg qureg, const int controlQubit, const int targetQubit)
void validateUniqueTargets(Qureg qureg, int qubit1, int qubit2, const char *caller)
void statevec_compactUnitary(Qureg qureg, const int targetQubit, Complex alpha, Complex beta)
void validateMultiControlsTarget(Qureg qureg, int *controlQubits, const int numControlQubits, const int targetQubit, const char *caller)