Distributed QUEST for GPU
QuEST.h
Go to the documentation of this file.
1 // Distributed under MIT licence. See https://github.com/aniabrown/QuEST_GPU/blob/master/LICENCE.txt for details
2 
3 # ifndef QuEST
4 # define QuEST
5 
6 # include "QuEST_precision.h"
7 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
18 typedef struct ComplexArray
19 {
22 } ComplexArray;
23 
26 typedef struct Complex
27 {
30 } Complex;
31 
34 typedef struct ComplexMatrix2
35 {
39 
40 typedef struct Vector
41 {
42  REAL x, y, z;
43 } Vector;
44 
48 typedef struct MultiQubit
49 {
59  int numQubits;
62  long long int numAmps;
64  int chunkId;
66  int numChunks;
67 } MultiQubit;
68 
72 typedef struct QuESTEnv
73 {
74  int rank;
75  int numRanks;
76 } QuESTEnv;
77 
78 // Codes for sigmaZ phase gate variations
80 
81 // QuEST library functions whose implementation is independent of environment (local, MPI)
82 
83 
104 void reportState(MultiQubit multiQubit);
105 
110 void reportMultiQubitParams(MultiQubit multiQubit);
111 
122 void rotateAroundAxis(MultiQubit multiQubit, const int rotQubit, REAL angle, Vector unitAxis);
123 
152 void rotateX(MultiQubit multiQubit, const int rotQubit, REAL angle);
153 
182 void rotateY(MultiQubit multiQubit, const int rotQubit, REAL angle);
183 
212 void rotateZ(MultiQubit multiQubit, const int rotQubit, REAL angle);
213 
242 void controlledRotateX(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle);
243 
272 void controlledRotateY(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle);
273 
302 void controlledRotateZ(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle);
303 
337 void controlledRotateAroundAxis(MultiQubit multiQubit, const int controlQubit, const int targetQubit, REAL angle, Vector axis);
338 
365 void sGate(MultiQubit multiQubit, const int targetQubit);
366 
393 void tGate(MultiQubit multiQubit, const int targetQubit);
394 
395 // QuEST library functions whose implementation depends on environment (local, MPI)
396 
397 void getEnvironmentString(QuESTEnv env, MultiQubit multiQubit, char str[200]);
398 
403 void reportStateToScreen(MultiQubit multiQubit, QuESTEnv env, int reportRank);
404 
437 void controlledPhaseGate(MultiQubit multiQubit, const int idQubit1, const int idQubit2);
438 
481 void multiControlledPhaseGate(MultiQubit multiQubit, int *controlQubits, int numControlQubits);
482 
519 void controlledNot(MultiQubit multiQubit, const int controlQubit, const int targetQubit);
520 
531 void createMultiQubit(MultiQubit *multiQubit, int numQubits, QuESTEnv env);
532 
540 void destroyMultiQubit(MultiQubit multiQubit, QuESTEnv env);
541 
548 void initStateZero(MultiQubit *multiQubit);
549 
560 void initStatePlus(MultiQubit *multiQubit);
561 
571 void initClassicalState(MultiQubit *multiQubit, long long int stateInd);
572 
577 void initQuESTEnv(QuESTEnv *env);
578 
584 void closeQuESTEnv(QuESTEnv env);
585 
589 void syncQuESTEnv(QuESTEnv env);
590 
598 int syncQuESTSuccess(int successCode);
599 
603 void reportQuESTEnv(QuESTEnv env);
604 
612 
646 void compactUnitary(MultiQubit multiQubit, const int rotQubit, Complex alpha, Complex beta);
647 
689 void controlledCompactUnitary(MultiQubit multiQubit, const int controlQubit, const int targetQubit, Complex alpha, Complex beta);
690 
714 void unitary(MultiQubit multiQubit, const int targetQubit, ComplexMatrix2 u);
715 
755 void controlledUnitary(MultiQubit multiQubit, const int controlQubit, const int targetQubit, ComplexMatrix2 u);
756 
810 void multiControlledUnitary(MultiQubit multiQubit, int* controlQubits, const int numControlQubits, const int targetQubit, ComplexMatrix2 u);
811 
838 void sigmaX(MultiQubit multiQubit, const int targetQubit);
839 
867 void sigmaY(MultiQubit multiQubit, const int targetQubit);
868 
896 void sigmaZ(MultiQubit multiQubit, const int targetQubit);
897 
927 void hadamard(MultiQubit multiQubit, const int targetQubit);
928 
940 REAL findProbabilityOfOutcome(MultiQubit multiQubit, const int measureQubit, int outcome);
941 
942 
959 REAL collapseToOutcome(MultiQubit multiQubit, const int measureQubit, int outcome);
960 
971 int measure(MultiQubit multiQubit, int measureQubit);
972 
985 int measureWithStats(MultiQubit multiQubit, int measureQubit, REAL *stateProb);
986 
996 void QuESTSeedRandomDefault(void);
997 
1011 void QuESTSeedRandom(unsigned long int *seedArray, int numSeeds);
1012 
1013 #ifdef __cplusplus
1014 }
1015 #endif
1016 
1017 # endif
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. ...
Definition: QuEST.cpp:91
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...
struct Vector Vector
int numRanks
Definition: QuEST.h:75
REAL * real
Definition: QuEST.h:20
void hadamard(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit Hadamard gate.
REAL x
Definition: QuEST.h:42
Information about the environment the program is running in.
Definition: QuEST.h:72
void initStateZero(MultiQubit *multiQubit)
Initialise a set of qubits to the classical zero state .
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.
Definition: QuEST.cpp:147
void QuESTSeedRandom(unsigned long int *seedArray, int numSeeds)
Seed the Mersenne Twister used for random number generation in the QuEST environment with a user defi...
Definition: QuEST.cpp:231
void controlledPhaseGate(MultiQubit multiQubit, const int idQubit1, const int idQubit2)
Apply the (two-qubit) controlled phase gate, also known as the controlled sigmaZ gate.
REAL * secondLevelReduction
Definition: QuEST.h:57
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 s...
Definition: QuEST.cpp:116
REAL * firstLevelReduction
Storage for reduction of probabilities on GPU.
Definition: QuEST.h:57
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.
Definition: QuEST.cpp:104
int numChunks
Number of chunks the state vector is broken up into – the number of MPI processes used...
Definition: QuEST.h:66
struct QuESTEnv QuESTEnv
Information about the environment the program is running in.
void initClassicalState(MultiQubit *multiQubit, long long int stateInd)
Initialise a set of qubits to the classical state with index stateInd.
void closeQuESTEnv(QuESTEnv env)
Initialize the QuEST environment.
Complex r1c1
Definition: QuEST.h:37
void reportState(MultiQubit multiQubit)
Print the current state vector of probability amplitudes for a set of qubits to file.
Definition: QuEST.cpp:62
int measure(MultiQubit multiQubit, int measureQubit)
Measures a single qubit, collapsing it randomly to 0 or 1.
void destroyMultiQubit(MultiQubit multiQubit, QuESTEnv env)
Deallocate a MultiQubit object representing a set of qubits.
void reportMultiQubitParams(MultiQubit multiQubit)
Report metainformation about a set of qubits: number of qubits, number of probability amplitudes...
Definition: QuEST.cpp:80
Definition: QuEST.h:79
struct ComplexArray ComplexArray
Represents an array of complex numbers grouped into an array of real components and an array of cores...
void reportStateToScreen(MultiQubit multiQubit, QuESTEnv env, int reportRank)
Print the current state vector of probability amplitudes for a set of qubits to standard out...
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.
void reportQuESTEnv(QuESTEnv env)
Report information about the QuEST environment.
int syncQuESTSuccess(int successCode)
Performs a logical AND on all successCodes held by all processes.
void initStatePlus(MultiQubit *multiQubit)
Initialise a set of qubits to the plus state .
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.
Definition: QuEST.cpp:141
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...
void multiControlledPhaseGate(MultiQubit multiQubit, int *controlQubits, int numControlQubits)
Apply the multiple-qubit controlled phase gate, also known as the multiple-qubit controlled sigmaZ ga...
Definition: QuEST.h:79
void sigmaZ(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit sigma-Z (also known as the Z, Pauli-Z or phase-flip) gate. ...
Definition: QuEST.cpp:153
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
void sGate(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit S gate.
Definition: QuEST.cpp:158
void QuESTSeedRandomDefault(void)
Seed the Mersenne Twister used for random number generation in the QuEST environment with an example ...
Definition: QuEST.cpp:206
REAL real
Definition: QuEST.h:28
Complex r0c0
Definition: QuEST.h:36
void compactUnitary(MultiQubit multiQubit, const int rotQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
int numQubits
Number of qubits in the state.
Definition: QuEST.h:59
Definition: QuEST.h:79
void unitary(MultiQubit multiQubit, const int targetQubit, ComplexMatrix2 u)
Apply a general single-qubit unitary (including a global phase factor).
#define REAL
void createMultiQubit(MultiQubit *multiQubit, int numQubits, QuESTEnv env)
Create a MultiQubit object representing a set of qubits.
void sigmaY(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit sigma-Y (also known as the Y or Pauli-Y) gate.
REAL z
Definition: QuEST.h:42
Complex r1c0
Definition: QuEST.h:37
REAL calcTotalProbability(MultiQubit multiQubit)
Calculate the probability of being in any state by taking the norm of the entire state vector...
struct MultiQubit MultiQubit
Represents a system of qubits.
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
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 ...
int rank
Definition: QuEST.h:74
void syncQuESTEnv(QuESTEnv env)
Guarantees that all code up to the given point has been executed on all nodes.
void getEnvironmentString(QuESTEnv env, MultiQubit multiQubit, char str[200])
ComplexArray pairStateVec
Temporary storage for a chunk of the state vector received from another process in the MPI version...
Definition: QuEST.h:53
struct Complex Complex
Represents one complex number.
Represents an array of complex numbers grouped into an array of real components and an array of cores...
Definition: QuEST.h:18
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 ...
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.
ComplexArray deviceStateVec
Storage for probability amplitudes for the multi qubit state on GPU.
Definition: QuEST.h:55
struct ComplexMatrix2 ComplexMatrix2
Represents a 2x2 matrix of complex numbers.
int chunkId
The position of the chunk of the state vector held by this process in the full state vector...
Definition: QuEST.h:64
Represents a system of qubits.
Definition: QuEST.h:48
void initQuESTEnv(QuESTEnv *env)
Initialize QuEST environment.
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
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.
Definition: QuEST.cpp:135
void tGate(MultiQubit multiQubit, const int targetQubit)
Apply the single-qubit T gate.
Definition: QuEST.cpp:163
Represents a 2x2 matrix of complex numbers.
Definition: QuEST.h:34
REAL y
Definition: QuEST.h:42
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.
Definition: QuEST.cpp:110
REAL * imag
Definition: QuEST.h:21
Represents one complex number.
Definition: QuEST.h:26
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)...
Complex r0c1
Definition: QuEST.h:36
phaseGateType
Definition: QuEST.h:79
ComplexArray stateVec
Probablilty amplitudes for the multi qubit state.
Definition: QuEST.h:51