Distributed QUEST for GPU
Data Structures | Typedefs | Enumerations | Functions
QuEST.h File Reference

The QuEST library API and objects. More...

#include "QuEST_precision.h"

Go to the source code of this file.

Data Structures

struct  ComplexArray
 Represents an array of complex numbers grouped into an array of real components and an array of coressponding complex components. More...
 
struct  Complex
 Represents one complex number. More...
 
struct  ComplexMatrix2
 Represents a 2x2 matrix of complex numbers. More...
 
struct  Vector
 
struct  MultiQubit
 Represents a system of qubits. More...
 
struct  QuESTEnv
 Information about the environment the program is running in. More...
 

Typedefs

typedef struct ComplexArray ComplexArray
 Represents an array of complex numbers grouped into an array of real components and an array of coressponding complex components. More...
 
typedef struct Complex Complex
 Represents one complex number. More...
 
typedef struct ComplexMatrix2 ComplexMatrix2
 Represents a 2x2 matrix of complex numbers. More...
 
typedef struct Vector Vector
 
typedef struct MultiQubit MultiQubit
 Represents a system of qubits. More...
 
typedef struct QuESTEnv QuESTEnv
 Information about the environment the program is running in. More...
 

Enumerations

enum  phaseGateType { SIGMA_Z =0, S_GATE =1, T_GATE =2 }
 

Functions

void reportState (MultiQubit multiQubit)
 Print the current state vector of probability amplitudes for a set of qubits to file. More...
 
void reportMultiQubitParams (MultiQubit multiQubit)
 Report metainformation about a set of qubits: number of qubits, number of probability amplitudes. More...
 
void rotateAroundAxis (MultiQubit multiQubit, const int rotQubit, REAL angle, Vector unitAxis)
 Rotate a single qubit by a given angle around a given vector on the Bloch-sphere. More...
 
void rotateX (MultiQubit multiQubit, const int rotQubit, REAL angle)
 Rotate a single qubit by a given angle around the X-axis of the Bloch-sphere. More...
 
void rotateY (MultiQubit multiQubit, const int rotQubit, REAL angle)
 Rotate a single qubit by a given angle around the Y-axis of the Bloch-sphere. More...
 
void rotateZ (MultiQubit multiQubit, const int rotQubit, REAL 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 controlledRotateX (MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle)
 Applies a controlled rotation by a given angle around the X-axis of the Bloch-sphere. More...
 
void controlledRotateY (MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle)
 Applies a controlled rotation by a given angle around the Y-axis of the Bloch-sphere. More...
 
void controlledRotateZ (MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle)
 Applies a controlled rotation by a given angle around the Z-axis of the Bloch-sphere. More...
 
void controlledRotateAroundAxis (MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle, Vector axis)
 Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere. More...
 
void sGate (MultiQubit multiQubit, const int targetQubit)
 Apply the single-qubit S gate. More...
 
void tGate (MultiQubit multiQubit, const int targetQubit)
 Apply the single-qubit T gate. More...
 
void getEnvironmentString (QuESTEnv env, MultiQubit multiQubit, char str[200])
 
void reportStateToScreen (MultiQubit multiQubit, QuESTEnv env, int reportRank)
 Print the current state vector of probability amplitudes for a set of qubits to standard out. More...
 
void controlledPhaseGate (MultiQubit multiQubit, const int idQubit1, const int idQubit2)
 Apply the (two-qubit) controlled phase gate, also known as the controlled sigmaZ gate. More...
 
void multiControlledPhaseGate (MultiQubit multiQubit, int *controlQubits, int numControlQubits)
 Apply the multiple-qubit controlled phase gate, also known as the multiple-qubit controlled sigmaZ gate. More...
 
void controlledNot (MultiQubit multiQubit, 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 createMultiQubit (MultiQubit *multiQubit, int numQubits, QuESTEnv env)
 Create a MultiQubit object representing a set of qubits. More...
 
void destroyMultiQubit (MultiQubit multiQubit, QuESTEnv env)
 Deallocate a MultiQubit object representing a set of qubits. More...
 
void initStateZero (MultiQubit *multiQubit)
 Initialise a set of $ N $ qubits to the classical zero state $ {| 0 \rangle}^{\otimes N} $. More...
 
void initStatePlus (MultiQubit *multiQubit)
 Initialise a set of $ N $ qubits to the plus state $ {| + \rangle}^{\otimes N} = \frac{1}{\sqrt{2^N}} (| 0 \rangle + | 1 \rangle)^{\otimes N} $. More...
 
void initClassicalState (MultiQubit *multiQubit, long long int stateInd)
 Initialise a set of $ N $ qubits to the classical state with index stateInd. More...
 
void initQuESTEnv (QuESTEnv *env)
 Initialize QuEST environment. More...
 
void closeQuESTEnv (QuESTEnv env)
 Initialize the QuEST environment. More...
 
void syncQuESTEnv (QuESTEnv env)
 Guarantees that all code up to the given point has been executed on all nodes. More...
 
int syncQuESTSuccess (int successCode)
 Performs a logical AND on all successCodes held by all processes. More...
 
void reportQuESTEnv (QuESTEnv env)
 Report information about the QuEST environment. More...
 
REAL calcTotalProbability (MultiQubit multiQubit)
 Calculate the probability of being in any state by taking the norm of the entire state vector. More...
 
void compactUnitary (MultiQubit multiQubit, const int rotQubit, Complex alpha, Complex beta)
 Apply a single-qubit unitary parameterised by two given complex scalars. More...
 
void controlledCompactUnitary (MultiQubit multiQubit, 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 unitary (MultiQubit multiQubit, const int targetQubit, ComplexMatrix2 u)
 Apply a general single-qubit unitary (including a global phase factor). More...
 
void controlledUnitary (MultiQubit multiQubit, 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 multiControlledUnitary (MultiQubit multiQubit, 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 sigmaX (MultiQubit multiQubit, const int targetQubit)
 Apply the single-qubit sigma-X (also known as the X, Pauli-X, NOT or bit-flip) gate. More...
 
void sigmaY (MultiQubit multiQubit, const int targetQubit)
 Apply the single-qubit sigma-Y (also known as the Y or Pauli-Y) gate. More...
 
void sigmaZ (MultiQubit multiQubit, const int targetQubit)
 Apply the single-qubit sigma-Z (also known as the Z, Pauli-Z or phase-flip) gate. More...
 
void hadamard (MultiQubit multiQubit, const int targetQubit)
 Apply the single-qubit Hadamard gate. More...
 
REAL findProbabilityOfOutcome (MultiQubit multiQubit, const int measureQubit, int outcome)
 Gives the probability of a specified qubit being measured in the given outcome (0 or 1). More...
 
REAL collapseToOutcome (MultiQubit multiQubit, const int measureQubit, int outcome)
 Updates the state vector to be consistent with measuring the measure qubit in the given outcome (0 or 1), and returns the probability of such a measurement outcome. More...
 
int measure (MultiQubit multiQubit, int measureQubit)
 Measures a single qubit, collapsing it randomly to 0 or 1. More...
 
int measureWithStats (MultiQubit multiQubit, int measureQubit, REAL *stateProb)
 Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of that outcome. More...
 
void QuESTSeedRandomDefault (void)
 Seed the Mersenne Twister used for random number generation in the QuEST environment with an example defualt seed. More...
 
void QuESTSeedRandom (unsigned long int *seedArray, int numSeeds)
 Seed the Mersenne Twister used for random number generation in the QuEST environment with a user defined seed. More...
 

Detailed Description

The QuEST library API and objects.

Definition in file QuEST.h.

Typedef Documentation

◆ Complex

typedef struct Complex Complex

Represents one complex number.

◆ ComplexArray

typedef struct ComplexArray ComplexArray

Represents an array of complex numbers grouped into an array of real components and an array of coressponding complex components.

◆ ComplexMatrix2

Represents a 2x2 matrix of complex numbers.

◆ MultiQubit

typedef struct MultiQubit MultiQubit

Represents a system of qubits.

Qubits are zero-based and the the first qubit is the rightmost

◆ QuESTEnv

typedef struct QuESTEnv QuESTEnv

Information about the environment the program is running in.

In practice, this holds info about MPI ranks and helps to hide MPI initialization code

◆ Vector

typedef struct Vector Vector

Enumeration Type Documentation

◆ phaseGateType

Enumerator
SIGMA_Z 
S_GATE 
T_GATE 

Definition at line 79 of file QuEST.h.

79 {SIGMA_Z=0, S_GATE=1, T_GATE=2};
Definition: QuEST.h:79
Definition: QuEST.h:79
Definition: QuEST.h:79

Function Documentation

◆ calcTotalProbability()

REAL calcTotalProbability ( MultiQubit  multiQubit)

Calculate the probability of being in any state by taking the norm of the entire state vector.

Should be equal to 1.

Parameters
[in]multiQubitobject representing a set of qubits
Returns
total probability

◆ closeQuESTEnv()

void closeQuESTEnv ( QuESTEnv  env)

Initialize the QuEST environment.

If something needs to be done to set up the execution environment, such as initializing MPI when running in distributed mode, it is handled here

Parameters
[in,out]envobject representing the execution environment. A single instance is used for each program

◆ collapseToOutcome()

REAL collapseToOutcome ( MultiQubit  multiQubit,
const int  measureQubit,
int  outcome 
)

Updates the state vector to be consistent with measuring the measure qubit in the given outcome (0 or 1), and returns the probability of such a measurement outcome.

This is effectively performing a measurement and forcing the outcome. This is an irreversible change to the state vector, whereby incompatible states in the state vector are given zero amplitude and the remaining states are renormalised. Exits with error if the given outcome has ~zero probability, and so cannot be collapsed into.

Parameters
[in,out]multiQubitobject representing the set of all qubits
[in]measureQubitqubit to measure
[in]outcometo force the measure qubit to enter
Returns
probability of the (forced) measurement outcome
Exceptions
exitWithErrorif measureQubit is outside [0, multiQubit.numQubits), or if outcome is not in {0, 1}, or if the probability of outcome is zero (within machine epsilon)

◆ compactUnitary()

void compactUnitary ( MultiQubit  multiQubit,
const int  rotQubit,
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]multiQubitobject 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, multiQubit.numQubits), or if alpha, beta don't satisfy |alpha|^2 + |beta|^2 = 1.

Referenced by rotateAroundAxis().

◆ controlledCompactUnitary()

void controlledCompactUnitary ( MultiQubit  multiQubit,
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]multiQubitobject 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, multiQubit.numQubits) or are equal, or if alpha, beta don't satisfy |alpha|^2 + |beta|^2 = 1.

Referenced by controlledRotateAroundAxis().

◆ controlledNot()

void controlledNot ( MultiQubit  multiQubit,
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 sigmaX 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]multiQubitobject 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, multiQubit.numQubits), or are equal.

◆ controlledPhaseGate()

void controlledPhaseGate ( MultiQubit  multiQubit,
const int  idQubit1,
const int  idQubit2 
)

Apply the (two-qubit) controlled phase gate, also known as the controlled sigmaZ 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]multiQubitobject representing the set of all qubits
[in]idQubit1,idQubit2qubits to operate upon
Exceptions
exitWithErrorif idQubit1 or idQubit2 are outside [0, multiQubit.numQubits), or are equal

◆ controlledRotateAroundAxis()

void controlledRotateAroundAxis ( MultiQubit  multiQubit,
const int  controlQubit,
const int  targetQubit,
REAL  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]multiQubitobject 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, multiQubit.numQubits) or are equal or if axis is the zero vector

Definition at line 122 of file QuEST.cpp.

References controlledCompactUnitary(), Complex::imag, Complex::real, Vector::x, Vector::y, and Vector::z.

Referenced by controlledRotateX(), controlledRotateY(), and controlledRotateZ().

122  {
123 
124  double mag = sqrt(pow(axis.x,2) + pow(axis.y,2) + pow(axis.z,2));
125  Vector unitAxis = {axis.x/mag, axis.y/mag, axis.z/mag};
126 
127  Complex alpha, beta;
128  alpha.real = cos(angle/2.0);
129  alpha.imag = -sin(angle/2.0)*unitAxis.z;
130  beta.real = sin(angle/2.0)*unitAxis.y;
131  beta.imag = -sin(angle/2.0)*unitAxis.x;
132  controlledCompactUnitary(multiQubit, controlQubit, targetQubit, alpha, beta);
133 }
REAL x
Definition: QuEST.h:42
void controlledCompactUnitary(MultiQubit multiQubit, const int controlQubit, const int targetQubit, Complex alpha, Complex beta)
Apply a controlled unitary (single control, single target) parameterised by two given complex scalars...
Definition: QuEST.h:40
REAL imag
Definition: QuEST.h:29
REAL real
Definition: QuEST.h:28
REAL z
Definition: QuEST.h:42
REAL y
Definition: QuEST.h:42
Represents one complex number.
Definition: QuEST.h:26

◆ controlledRotateX()

void controlledRotateX ( MultiQubit  multiQubit,
const int  controlQubit,
const int  targetQubit,
REAL  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]multiQubitobject representing the set of all qubits
[in]controlQubitqubit which has value 1 in the rotated states
[in]tagretQubitqubit to rotate
[in]angleangle by which to rotate the target qubit in radians
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, multiQubit.numQubits) or are equal.

Definition at line 135 of file QuEST.cpp.

References controlledRotateAroundAxis().

135  {
136 
137  Vector unitAxis = {1, 0, 0};
138  controlledRotateAroundAxis(multiQubit, controlQubit, targetQubit, angle, unitAxis);
139 }
Definition: QuEST.h:40
void controlledRotateAroundAxis(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
Definition: QuEST.cpp:122

◆ controlledRotateY()

void controlledRotateY ( MultiQubit  multiQubit,
const int  controlQubit,
const int  targetQubit,
REAL  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]multiQubitobject representing the set of all qubits
[in]controlQubitqubit which has value 1 in the rotated states
[in]tagretQubitqubit to rotate
[in]angleangle by which to rotate the target qubit in radians
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, multiQubit.numQubits) or are equal.

Definition at line 141 of file QuEST.cpp.

References controlledRotateAroundAxis().

141  {
142 
143  Vector unitAxis = {0, 1, 0};
144  controlledRotateAroundAxis(multiQubit, controlQubit, targetQubit, angle, unitAxis);
145 }
Definition: QuEST.h:40
void controlledRotateAroundAxis(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
Definition: QuEST.cpp:122

◆ controlledRotateZ()

void controlledRotateZ ( MultiQubit  multiQubit,
const int  controlQubit,
const int  targetQubit,
REAL  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]multiQubitobject representing the set of all qubits
[in]controlQubitqubit which has value 1 in the rotated states
[in]tagretQubitqubit to rotate
[in]angleangle by which to rotate the target qubit in radians
Exceptions
exitWithErrorif either controlQubit or targetQubit are outside [0, multiQubit.numQubits) or are equal.

Definition at line 147 of file QuEST.cpp.

References controlledRotateAroundAxis().

147  {
148 
149  Vector unitAxis = {0, 0, 1};
150  controlledRotateAroundAxis(multiQubit, controlQubit, targetQubit, angle, unitAxis);
151 }
Definition: QuEST.h:40
void controlledRotateAroundAxis(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle, Vector axis)
Applies a controlled rotation by a given angle around a given vector on the Bloch-sphere.
Definition: QuEST.cpp:122

◆ controlledUnitary()

void controlledUnitary ( MultiQubit  multiQubit,
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]multiQubitobject 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, multiQubit.numQubits) or are equal, or if u is not unitary.

◆ createMultiQubit()

void createMultiQubit ( MultiQubit multiQubit,
int  numQubits,
QuESTEnv  env 
)

Create a MultiQubit object representing a set of qubits.

Allocate space for state vector of probability amplitudes, including space for temporary values to be copied from one other chunk if running the distributed version. Define properties related to the size of the set of qubits. initStateZero should be called after this to initialise the qubits to the zero state.

Parameters
[in,out]multiQubita pointer to an object representing the set of qubits
[in]numQubitsnumber of qubits in the system
[in]envobject representing the execution environment (local, multinode etc)
Exceptions
exitWithErrorif numQubits <= 0

◆ destroyMultiQubit()

void destroyMultiQubit ( MultiQubit  multiQubit,
QuESTEnv  env 
)

Deallocate a MultiQubit object representing a set of qubits.

Free memory allocated to state vector of probability amplitudes, including temporary vector for values copied from another chunk if running the distributed version.

Parameters
[in,out]multiQubitobject to be deallocated
[in]envobject representing the execution environment (local, multinode etc)

◆ findProbabilityOfOutcome()

REAL findProbabilityOfOutcome ( MultiQubit  multiQubit,
const int  measureQubit,
int  outcome 
)

Gives the probability of a specified qubit being measured in the given outcome (0 or 1).

This performs no actual measurement and does not change the state of the qubits.

Parameters
[in]multiQubitobject representing the set of all qubits
[in]measureQubitqubit to study
[in]outcomefor which to find the probability of the qubit being measured in
Returns
probability of qubit measureQubit being measured in the given outcome
Exceptions
exitWithErrorif measureQubit is outside [0, multiQubit.numQubits), or if outcome is not in {0, 1}.

◆ getEnvironmentString()

void getEnvironmentString ( QuESTEnv  env,
MultiQubit  multiQubit,
char  str[200] 
)

◆ hadamard()

void hadamard ( MultiQubit  multiQubit,
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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits).

◆ initClassicalState()

void initClassicalState ( MultiQubit multiQubit,
long long int  stateInd 
)

Initialise a set of $ N $ qubits to the classical state with index stateInd.

Note $ | 00 \dots 00 \rangle $ has stateInd 0, $ | 00 \dots 01 \rangle $ has stateInd 1, $ | 11 \dots 11 \rangle $ has stateInd $ 2^N - 1 $, etc. Subsequent calls to getProbEl will yield 0 for all indices except stateInd.

Parameters
[in,out]multiQubita pointer to the object representing the set of qubits to be initialised
[in]stateIndthe index (0 to the number of amplitudes, exclusive) of the state to give probability 1

◆ initQuESTEnv()

void initQuESTEnv ( QuESTEnv env)

Initialize QuEST environment.

If something needs to be done to set up the execution environment, such as initializing MPI when running in distributed mode, it is handled here

Parameters
[in,out]envobject representing the execution environment. A single instance is used for each program

◆ initStatePlus()

void initStatePlus ( MultiQubit multiQubit)

Initialise a set of $ N $ qubits to the plus state $ {| + \rangle}^{\otimes N} = \frac{1}{\sqrt{2^N}} (| 0 \rangle + | 1 \rangle)^{\otimes N} $.

This is the product state of $N$ qubits where every classical state is uniformly populated with real coefficient $\frac{1}{\sqrt{2^N}}$. This is equivalent to applying a Hadamard to every qubit in the zero state: $ \hat{H}^{\otimes N} {|0\rangle}^{\otimes N} $

Parameters
[in,out]multiQubita pointer to the object representing the set of qubits to be initialised

◆ initStateZero()

void initStateZero ( MultiQubit multiQubit)

Initialise a set of $ N $ qubits to the classical zero state $ {| 0 \rangle}^{\otimes N} $.

Parameters
[in,out]multiQubita pointer to the object representing the set of all qubits to initialise

◆ measure()

int measure ( MultiQubit  multiQubit,
int  measureQubit 
)

Measures a single qubit, collapsing it randomly to 0 or 1.

Outcome probabilities are weighted by the state vector, which is irreversibly changed after collapse to be consistent with the outcome.

Parameters
[in,out]multiQubitobject representing the set of all qubits
[in]measureQubitqubit to measure
Returns
the measurement outcome, 0 or 1
Exceptions
exitWithErrorif measureQubit is outside [0, multiQubit.numQubits)

◆ measureWithStats()

int measureWithStats ( MultiQubit  multiQubit,
int  measureQubit,
REAL stateProb 
)

Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of that outcome.

Outcome probabilities are weighted by the state vector, which is irreversibly changed after collapse to be consistent with the outcome.

Parameters
[in,out]multiQubitobject representing the set of all qubits
[in]measureQubitqubit to measure
[out]stateProba pointer to a REAL which is set to the probability of the occurred outcome
Returns
the measurement outcome, 0 or 1
Exceptions
exitWithErrorif measureQubit is outside [0, multiQubit.numQubits)

◆ multiControlledPhaseGate()

void multiControlledPhaseGate ( MultiQubit  multiQubit,
int *  controlQubits,
int  numControlQubits 
)

Apply the multiple-qubit controlled phase gate, also known as the multiple-qubit controlled sigmaZ 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]multiQubitobject representing the set of all qubits
[in]controlQubitsarray of input qubits
[in]numControlQubitsnumber of input qubits
Exceptions
exitWithErrorif numControlQubits is outside [1, multiQubit.numQubits)

◆ multiControlledUnitary()

void multiControlledUnitary ( MultiQubit  multiQubit,
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]multiQubitobject 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, multiQubit.numQubits]), or if any qubit index (targetQubit or one in controlQubits) is outside [0, multiQubit.numQubits]), or if controlQubits contains targetQubit, or if u is not unitary.

◆ QuESTSeedRandom()

void QuESTSeedRandom ( unsigned long int *  seedArray,
int  numSeeds 
)

Seed the Mersenne Twister used for random number generation in the QuEST environment with a user defined seed.

This function uses the mt19937 init_by_array function with numSeeds keys supplied by the user. Subsequent calls to mt19937 genrand functions will use this seeding. For a multi process code, the same seed is given to all process, therefore this seeding is only appropriate to use for functions such as measure where all processes require the same random value.

Parameters
[in]seedArrayArray of integers to use as seed. This allows the MT to be initialised with more than a 32-bit integer if required
[in]numSeedsLength of seedArray

For more information about the MT, see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

Seed the Mersenne Twister used for random number generation in the QuEST environment with a user defined seed.

Definition at line 231 of file QuEST.cpp.

References init_by_array().

231  {
232  // init MT random number generator with user defined list of seeds
233  // for the MPI version, it is ok that all procs will get the same seed as random numbers will only be
234  // used by the master process
235  init_by_array(seedArray, numSeeds);
236 }
void init_by_array(unsigned long init_key[], int key_length)
Definition: mt19937ar.cpp:76

◆ QuESTSeedRandomDefault()

void QuESTSeedRandomDefault ( void  )

Seed the Mersenne Twister used for random number generation in the QuEST environment with an example defualt seed.

This default seeding function uses the mt19937 init_by_array function with three keys – time, pid and hostname. Subsequent calls to mt19937 genrand functions will use this seeding. For a multi process code, the same seed is given to all process, therefore this seeding is only appropriate to use for functions such as measure where all processes require the same random value.

For more information about the MT, see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html

Definition at line 206 of file QuEST.cpp.

References hashString(), and init_by_array().

206  {
207  // init MT random number generator with three keys -- time, pid and a hash of hostname
208  // for the MPI version, it is ok that all procs will get the same seed as random numbers will only be
209  // used by the master process
210 
211  struct timeval tv;
212  gettimeofday(&tv, NULL);
213 
214  double time_in_mill =
215  (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; // convert tv_sec & tv_usec to millisecond
216 
217  unsigned long int pid = getpid();
218  unsigned long int msecs = (unsigned long int) time_in_mill;
219  char hostName[MAXHOSTNAMELEN+1];
220  gethostname(hostName, sizeof(hostName));
221  unsigned long int hostNameInt = hashString(hostName);
222 
223  unsigned long int key[3];
224  key[0] = msecs; key[1] = pid; key[2] = hostNameInt;
225  init_by_array(key, 3);
226 }
unsigned long int hashString(char *str)
Definition: QuEST.cpp:238
void init_by_array(unsigned long init_key[], int key_length)
Definition: mt19937ar.cpp:76

◆ reportMultiQubitParams()

void reportMultiQubitParams ( MultiQubit  multiQubit)

Report metainformation about a set of qubits: number of qubits, number of probability amplitudes.

Parameters
[in,out]multiQubitobject representing the set of qubits
[in]envobject representing the execution environment (local, multinode etc)

Definition at line 80 of file QuEST.cpp.

References MultiQubit::chunkId, MultiQubit::numChunks, and MultiQubit::numQubits.

80  {
81  long long int numAmps = 1L << multiQubit.numQubits;
82  long long int numAmpsPerRank = numAmps/multiQubit.numChunks;
83  if (multiQubit.chunkId==0){
84  printf("QUBITS:\n");
85  printf("Number of qubits is %d.\n", multiQubit.numQubits);
86  printf("Number of amps is %lld.\n", numAmps);
87  printf("Number of amps per rank is %lld.\n", numAmpsPerRank);
88  }
89 }
int numChunks
Number of chunks the state vector is broken up into – the number of MPI processes used...
Definition: QuEST.h:66
int numQubits
Number of qubits in the state.
Definition: QuEST.h:59
int chunkId
The position of the chunk of the state vector held by this process in the full state vector...
Definition: QuEST.h:64

◆ reportQuESTEnv()

void reportQuESTEnv ( QuESTEnv  env)

Report information about the QuEST environment.

Parameters
[in]envobject representing the execution environment. A single instance is used for each program

◆ reportState()

void reportState ( MultiQubit  multiQubit)

Print the current state vector of probability amplitudes for a set of qubits to file.

File format:

real, imag
realComponent1, imagComponent1
realComponent2, imagComponent2
...
realComponentN, imagComponentN

File naming convention:

For each node that the program runs on, a file 'state_rank_[node_rank].csv' is generated. If there is more than one node, ranks after the first do not include the header

real, imag

so that files are easier to combine.

Parameters
[in,out]multiQubitobject representing the set of qubits

Definition at line 62 of file QuEST.cpp.

References MultiQubit::chunkId, ComplexArray::imag, MultiQubit::numAmps, ComplexArray::real, and MultiQubit::stateVec.

62  {
63  FILE *state;
64  char filename[100];
65  long long int index;
66  sprintf(filename, "state_rank_%d.csv", multiQubit.chunkId);
67  state = fopen(filename, "w");
68  if (multiQubit.chunkId==0) fprintf(state, "real, imag\n");
69 
70  for(index=0; index<multiQubit.numAmps; index++){
71  fprintf(state, "%.12f, %.12f\n", multiQubit.stateVec.real[index], multiQubit.stateVec.imag[index]);
72  }
73  fclose(state);
74 }
REAL * real
Definition: QuEST.h:20
long long int numAmps
Number of probability amplitudes held in stateVec by this process In the non-MPI version, this is the total number of amplitudes.
Definition: QuEST.h:62
int chunkId
The position of the chunk of the state vector held by this process in the full state vector...
Definition: QuEST.h:64
REAL * imag
Definition: QuEST.h:21
ComplexArray stateVec
Probablilty amplitudes for the multi qubit state.
Definition: QuEST.h:51

◆ reportStateToScreen()

void reportStateToScreen ( MultiQubit  multiQubit,
QuESTEnv  env,
int  reportRank 
)

Print the current state vector of probability amplitudes for a set of qubits to standard out.

For debugging purposes. Each rank should print output serially. Only print output for systems <= 5 qubits

◆ rotateAroundAxis()

void rotateAroundAxis ( MultiQubit  multiQubit,
const int  rotQubit,
REAL  angle,
Vector  unitAxis 
)

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.
Parameters
[in,out]multiQubitobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
[in]axisvector around which to rotate
Exceptions
exitWithErrorif rotQubit is outside [0, multiQubit.numQubits), or if axis is the zero vector

Definition at line 91 of file QuEST.cpp.

References compactUnitary(), Complex::imag, Complex::real, Vector::x, Vector::y, and Vector::z.

Referenced by rotateX(), rotateY(), and rotateZ().

91  {
92 
93  double mag = sqrt(pow(axis.x,2) + pow(axis.y,2) + pow(axis.z,2));
94  Vector unitAxis = {axis.x/mag, axis.y/mag, axis.z/mag};
95 
96  Complex alpha, beta;
97  alpha.real = cos(angle/2.0);
98  alpha.imag = -sin(angle/2.0)*unitAxis.z;
99  beta.real = sin(angle/2.0)*unitAxis.y;
100  beta.imag = -sin(angle/2.0)*unitAxis.x;
101  compactUnitary(multiQubit, rotQubit, alpha, beta);
102 }
REAL x
Definition: QuEST.h:42
Definition: QuEST.h:40
REAL imag
Definition: QuEST.h:29
REAL real
Definition: QuEST.h:28
void compactUnitary(MultiQubit multiQubit, const int rotQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
REAL z
Definition: QuEST.h:42
REAL y
Definition: QuEST.h:42
Represents one complex number.
Definition: QuEST.h:26

◆ rotateX()

void rotateX ( MultiQubit  multiQubit,
const int  rotQubit,
REAL  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]multiQubitobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
Exceptions
exitWithErrorif rotQubit is outside [0, multiQubit.numQubits).

Definition at line 104 of file QuEST.cpp.

References rotateAroundAxis().

104  {
105 
106  Vector unitAxis = {1, 0, 0};
107  rotateAroundAxis(multiQubit, rotQubit, angle, unitAxis);
108 }
void rotateAroundAxis(MultiQubit multiQubit, const int rotQubit, REAL angle, Vector axis)
Rotate a single qubit by a given angle around a given vector on the Bloch-sphere. ...
Definition: QuEST.cpp:91
Definition: QuEST.h:40

◆ rotateY()

void rotateY ( MultiQubit  multiQubit,
const int  rotQubit,
REAL  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]multiQubitobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
Exceptions
exitWithErrorif rotQubit is outside [0, multiQubit.numQubits).

Definition at line 110 of file QuEST.cpp.

References rotateAroundAxis().

110  {
111 
112  Vector unitAxis = {0, 1, 0};
113  rotateAroundAxis(multiQubit, rotQubit, angle, unitAxis);
114 }
void rotateAroundAxis(MultiQubit multiQubit, const int rotQubit, REAL angle, Vector axis)
Rotate a single qubit by a given angle around a given vector on the Bloch-sphere. ...
Definition: QuEST.cpp:91
Definition: QuEST.h:40

◆ rotateZ()

void rotateZ ( MultiQubit  multiQubit,
const int  rotQubit,
REAL  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]multiQubitobject representing the set of all qubits
[in]rotQubitqubit to rotate
[in]angleangle by which to rotate in radians
Exceptions
exitWithErrorif rotQubit is outside [0, multiQubit.numQubits).

Definition at line 116 of file QuEST.cpp.

References rotateAroundAxis().

116  {
117 
118  Vector unitAxis = {0, 0, 1};
119  rotateAroundAxis(multiQubit, rotQubit, angle, unitAxis);
120 }
void rotateAroundAxis(MultiQubit multiQubit, const int rotQubit, REAL angle, Vector axis)
Rotate a single qubit by a given angle around a given vector on the Bloch-sphere. ...
Definition: QuEST.cpp:91
Definition: QuEST.h:40

◆ sGate()

void sGate ( MultiQubit  multiQubit,
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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate upon
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits)

Definition at line 158 of file QuEST.cpp.

References phaseGate(), and S_GATE.

159 {
160  phaseGate(multiQubit, targetQubit, S_GATE);
161 }
void phaseGate(MultiQubit multiQubit, const int targetQubit, enum phaseGateType type)
Definition: QuEST.h:79

◆ sigmaX()

void sigmaX ( MultiQubit  multiQubit,
const int  targetQubit 
)

Apply the single-qubit sigma-X (also known as the X, Pauli-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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits).

◆ sigmaY()

void sigmaY ( MultiQubit  multiQubit,
const int  targetQubit 
)

Apply the single-qubit sigma-Y (also known as the Y or Pauli-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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits).

◆ sigmaZ()

void sigmaZ ( MultiQubit  multiQubit,
const int  targetQubit 
)

Apply the single-qubit sigma-Z (also known as the Z, Pauli-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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate on
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits).

Definition at line 153 of file QuEST.cpp.

References phaseGate(), and SIGMA_Z.

154 {
155  phaseGate(multiQubit, targetQubit, SIGMA_Z);
156 }
void phaseGate(MultiQubit multiQubit, const int targetQubit, enum phaseGateType type)
Definition: QuEST.h:79

◆ syncQuESTEnv()

void syncQuESTEnv ( QuESTEnv  env)

Guarantees that all code up to the given point has been executed on all nodes.

Parameters
[in]envobject representing the execution environment. A single instance is used for each program

◆ syncQuESTSuccess()

int syncQuESTSuccess ( int  successCode)

Performs a logical AND on all successCodes held by all processes.

If any one process has a zero successCode all processes will return a zero success code.

Parameters
[in]envobject representing the execution environment. A single instance is used for each program
[in]successCode1 if process task succeeded, 0 if process task failed
Returns
1 if all processes succeeded, 0 if any one process failed

◆ tGate()

void tGate ( MultiQubit  multiQubit,
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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate upon
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits)

Definition at line 163 of file QuEST.cpp.

References phaseGate(), and T_GATE.

164 {
165  phaseGate(multiQubit, targetQubit, T_GATE);
166 }
void phaseGate(MultiQubit multiQubit, const int targetQubit, enum phaseGateType type)
Definition: QuEST.h:79

◆ unitary()

void unitary ( MultiQubit  multiQubit,
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]multiQubitobject representing the set of all qubits
[in]targetQubitqubit to operate on
[in]uunitary matrix to apply
Exceptions
exitWithErrorif targetQubit is outside [0, multiQubit.numQubits), or matrix u is not unitary.