QuEST.h
Go to the documentation of this file.
1 // Distributed under MIT licence. See https://github.com/QuEST-Kit/QuEST/blob/master/LICENCE.txt for details
2 
32 # ifndef QUEST_H
33 # define QUEST_H
34 
35 # include "QuEST_precision.h"
36 
37 // prevent C++ name mangling
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /*
44  * private structures
45  */
46 
47 // hide these from doxygen
49 
55 enum phaseGateType {SIGMA_Z=0, S_GATE=1, T_GATE=2};
56 
62 typedef struct {
63 
64  char* buffer; // generated QASM string
65  int bufferSize; // maximum number of chars before overflow
66  int bufferFill; // number of chars currently in buffer
67  int isLogging; // whether gates are being added to buffer
68 
69 } QASMLogger;
70 
77 typedef struct ComplexArray
78 {
79  qreal *real;
80  qreal *imag;
81 } ComplexArray;
82 
84 
85 
86 
87 /*
88  * public structures
89  */
90 
97 
103 typedef struct Complex
104 {
107 } Complex;
108 
114 typedef struct ComplexMatrix2
115 {
116  qreal real[2][2];
117  qreal imag[2][2];
119 
125 typedef struct ComplexMatrix4
126 {
127  qreal real[4][4];
128  qreal imag[4][4];
130 
136 typedef struct ComplexMatrixN
137 {
142 
148 typedef struct Vector
149 {
150  qreal x, y, z;
151 } Vector;
152 
160 typedef struct Qureg
161 {
170  long long int numAmpsPerChunk;
172  long long int numAmpsTotal;
174  int chunkId;
177 
179  ComplexArray stateVec;
181  ComplexArray pairStateVec;
182 
184  ComplexArray deviceStateVec;
187 
189  QASMLogger* qasmLog;
190 
191 } Qureg;
192 
199 typedef struct QuESTEnv
200 {
201  int rank;
202  int numRanks;
203 } QuESTEnv;
204 
205 
206 
207 /*
208  * public functions
209  */
210 
223 Qureg createQureg(int numQubits, QuESTEnv env);
224 
237 Qureg createDensityQureg(int numQubits, QuESTEnv env);
238 
251 
261 void destroyQureg(Qureg qureg, QuESTEnv env);
262 
279 ComplexMatrixN createComplexMatrixN(int numQubits);
280 
292 
293 #ifndef __cplusplus
294 
315 void initComplexMatrixN(ComplexMatrixN m, qreal real[][1<<m.numQubits], qreal imag[][1<<m.numQubits]);
316 #endif
317 
341 void reportState(Qureg qureg);
342 
350 void reportStateToScreen(Qureg qureg, QuESTEnv env, int reportRank);
351 
358 void reportQuregParams(Qureg qureg);
359 
365 int getNumQubits(Qureg qureg);
366 
372 long long int getNumAmps(Qureg qureg);
373 
382 void initBlankState(Qureg qureg);
383 
392 void initZeroState(Qureg qureg);
393 
408 void initPlusState(Qureg qureg);
409 
434 void initClassicalState(Qureg qureg, long long int stateInd);
435 
447 void initPureState(Qureg qureg, Qureg pure);
448 
458 void initDebugState(Qureg qureg);
459 
473 void initStateFromAmps(Qureg qureg, qreal* reals, qreal* imags);
474 
493 void setAmps(Qureg qureg, long long int startInd, qreal* reals, qreal* imags, long long int numAmps);
494 
505 void cloneQureg(Qureg targetQureg, Qureg copyQureg);
506 
539 void phaseShift(Qureg qureg, const int targetQubit, qreal angle);
540 
582 void controlledPhaseShift(Qureg qureg, const int idQubit1, const int idQubit2, qreal angle);
583 
623 void multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle);
624 
660 void controlledPhaseFlip (Qureg qureg, const int idQubit1, const int idQubit2);
661 
708 void multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits);
709 
740 void sGate(Qureg qureg, const int targetQubit);
741 
772 void tGate(Qureg qureg, const int targetQubit);
773 
785 
794 void destroyQuESTEnv(QuESTEnv env);
795 
802 void syncQuESTEnv(QuESTEnv env);
803 
812 int syncQuESTSuccess(int successCode);
813 
820 void reportQuESTEnv(QuESTEnv env);
821 
831 void getEnvironmentString(QuESTEnv env, Qureg qureg, char str[200]);
832 
854 void copyStateToGPU(Qureg qureg);
855 
877 void copyStateFromGPU(Qureg qureg);
878 
890 Complex getAmp(Qureg qureg, long long int index);
891 
903 qreal getRealAmp(Qureg qureg, long long int index);
904 
916 qreal getImagAmp(Qureg qureg, long long int index);
917 
929 qreal getProbAmp(Qureg qureg, long long int index);
930 
943 Complex getDensityAmp(Qureg qureg, long long int row, long long int col);
944 
970 qreal calcTotalProb(Qureg qureg);
971 
1009 void compactUnitary(Qureg qureg, const int targetQubit, Complex alpha, Complex beta);
1010 
1038 void unitary(Qureg qureg, const int targetQubit, ComplexMatrix2 u);
1039 
1071 void rotateX(Qureg qureg, const int rotQubit, qreal angle);
1072 
1105 void rotateY(Qureg qureg, const int rotQubit, qreal angle);
1106 
1139 void rotateZ(Qureg qureg, const int rotQubit, qreal angle);
1140 
1159 void rotateAroundAxis(Qureg qureg, const int rotQubit, qreal angle, Vector axis);
1160 
1161 
1193 void controlledRotateX(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle);
1194 
1226 void controlledRotateY(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle);
1227 
1259 void controlledRotateZ(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle);
1260 
1297 void controlledRotateAroundAxis(Qureg qureg, const int controlQubit, const int targetQubit, qreal angle, Vector axis);
1298 
1344 void controlledCompactUnitary(Qureg qureg, const int controlQubit, const int targetQubit, Complex alpha, Complex beta);
1345 
1389 void controlledUnitary(Qureg qureg, const int controlQubit, const int targetQubit, ComplexMatrix2 u);
1390 
1449 void multiControlledUnitary(Qureg qureg, int* controlQubits, const int numControlQubits, const int targetQubit, ComplexMatrix2 u);
1450 
1481 void pauliX(Qureg qureg, const int targetQubit);
1482 
1514 void pauliY(Qureg qureg, const int targetQubit);
1515 
1547 void pauliZ(Qureg qureg, const int targetQubit);
1548 
1582 void hadamard(Qureg qureg, const int targetQubit);
1583 
1624 void controlledNot(Qureg qureg, const int controlQubit, const int targetQubit);
1625 
1668 void controlledPauliY(Qureg qureg, const int controlQubit, const int targetQubit);
1669 
1693 qreal calcProbOfOutcome(Qureg qureg, const int measureQubit, int outcome);
1694 
1720 qreal collapseToOutcome(Qureg qureg, const int measureQubit, int outcome);
1721 
1735 int measure(Qureg qureg, int measureQubit);
1736 
1752 int measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb);
1753 
1777 
1826 
1840 void seedQuESTDefault(void);
1841 
1857 void seedQuEST(unsigned long int *seedArray, int numSeeds);
1858 
1867 void startRecordingQASM(Qureg qureg);
1868 
1878 void stopRecordingQASM(Qureg qureg);
1879 
1886 void clearRecordedQASM(Qureg qureg);
1887 
1895 void printRecordedQASM(Qureg qureg);
1896 
1905 void writeRecordedQASMToFile(Qureg qureg, char* filename);
1906 
1928 void mixDephasing(Qureg qureg, const int targetQubit, qreal prob);
1929 
1957 void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob);
1958 
1992 void mixDepolarising(Qureg qureg, const int targetQubit, qreal prob);
1993 
2023 void mixDamping(Qureg qureg, const int targetQubit, qreal prob);
2024 
2087 void mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal prob);
2088 
2122 void mixPauli(Qureg qureg, int targetQubit, qreal probX, qreal probY, qreal probZ);
2123 
2137 void mixDensityMatrix(Qureg combineQureg, qreal prob, Qureg otherQureg);
2138 
2160 qreal calcPurity(Qureg qureg);
2161 
2188 qreal calcFidelity(Qureg qureg, Qureg pureState);
2189 
2231 void swapGate(Qureg qureg, int qubit1, int qubit2);
2232 
2233 
2278 void sqrtSwapGate(Qureg qureg, int qb1, int qb2);
2279 
2332  Qureg qureg, int* controlQubits, int* controlState, const int numControlQubits,
2333  const int targetQubit, ComplexMatrix2 u
2334 );
2335 
2359 void multiRotateZ(Qureg qureg, int* qubits, int numQubits, qreal angle);
2360 
2407 void multiRotatePauli(Qureg qureg, int* targetQubits, enum pauliOpType* targetPaulis, int numTargets, qreal angle);
2408 
2453 qreal calcExpecPauliProd(Qureg qureg, int* targetQubits, enum pauliOpType* pauliCodes, int numTargets, Qureg workspace);
2454 
2503 qreal calcExpecPauliSum(Qureg qureg, enum pauliOpType* allPauliCodes, qreal* termCoeffs, int numSumTerms, Qureg workspace);
2504 
2566 void twoQubitUnitary(Qureg qureg, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u);
2567 
2630 void controlledTwoQubitUnitary(Qureg qureg, const int controlQubit, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u);
2631 
2705 void multiControlledTwoQubitUnitary(Qureg qureg, int* controlQubits, const int numControlQubits, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u);
2706 
2781 void multiQubitUnitary(Qureg qureg, int* targs, const int numTargs, ComplexMatrixN u);
2782 
2852 void controlledMultiQubitUnitary(Qureg qureg, int ctrl, int* targs, const int numTargs, ComplexMatrixN u);
2853 
2929 void multiControlledMultiQubitUnitary(Qureg qureg, int* ctrls, const int numCtrls, int* targs, const int numTargs, ComplexMatrixN u);
2930 
2964 void mixKrausMap(Qureg qureg, int target, ComplexMatrix2 *ops, int numOps);
2965 
2998 void mixTwoQubitKrausMap(Qureg qureg, int target1, int target2, ComplexMatrix4 *ops, int numOps);
2999 
3042 void mixMultiQubitKrausMap(Qureg qureg, int* targets, int numTargets, ComplexMatrixN* ops, int numOps);
3043 
3071 
3095 void setWeightedQureg(Complex fac1, Qureg qureg1, Complex fac2, Qureg qureg2, Complex facOut, Qureg out);
3096 
3150 void applyPauliSum(Qureg inQureg, enum pauliOpType* allPauliCodes, qreal* termCoeffs, int numSumTerms, Qureg outQureg);
3151 
3190 void invalidQuESTInputError(const char* errMsg, const char* errFunc);
3191 
3192 #ifndef __cplusplus
3193  // hide this function from doxygen
3195 
3234  int numQubits, qreal re[][1<<numQubits], qreal im[][1<<numQubits],
3235  qreal** reStorage, qreal** imStorage);
3236 #endif
3237 
3239 // hide this function from doxygen
3241 #define UNPACK_ARR(...) __VA_ARGS__
3242 
3244 #ifndef __cplusplus
3245 
3284 #define getStaticComplexMatrixN(numQubits, re, im) \
3285  bindArraysToStackComplexMatrixN( \
3286  numQubits, \
3287  (qreal[1<<numQubits][1<<numQubits]) UNPACK_ARR re, \
3288  (qreal[1<<numQubits][1<<numQubits]) UNPACK_ARR im, \
3289  (double*[1<<numQubits]) {NULL}, (double*[1<<numQubits]) {NULL} \
3290  )
3291 #endif
3292 
3293 
3294 // end prevention of C++ name mangling
3295 #ifdef __cplusplus
3296 }
3297 #endif
3298 
3299 #endif // QUEST_H
3300 
qreal getProbAmp(Qureg qureg, long long int index)
Get the probability of a state-vector at an index in the full state vector.
Definition: QuEST.c:690
void initBlankState(Qureg qureg)
Initialises a qureg to have all-zero-amplitudes.
Definition: QuEST.c:117
Represents a 3-vector of real numbers.
Definition: QuEST.h:148
void destroyQuESTEnv(QuESTEnv env)
Destroy the QuEST environment.
pauliOpType
Codes for specifying Pauli operators.
Definition: QuEST.h:96
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...
Definition: QuEST.c:535
void reportQuregParams(Qureg qureg)
Report metainformation about a set of qubits: number of qubits, number of probability amplitudes.
Definition: QuEST_common.c:233
void copyStateFromGPU(Qureg qureg)
In GPU mode, this copies the state-vector (or density matrix) from GPU memory (qureg....
Definition: QuEST_cpu.c:39
qreal real[4][4]
Definition: QuEST.h:127
void syncQuESTEnv(QuESTEnv env)
Guarantees that all code up to the given point has been executed on all nodes (if running in distribu...
void initPureState(Qureg qureg, Qureg pure)
Initialise a set of qubits, which can be a state vector or density matrix, to a given pure state.
Definition: QuEST.c:143
@ PAULI_Z
Definition: QuEST.h:96
void tGate(Qureg qureg, const int targetQubit)
Apply the single-qubit T gate.
Definition: QuEST.c:475
int rank
Definition: QuEST.h:201
qreal calcTotalProb(Qureg qureg)
A debugging function which calculates the probability of the qubits in qureg being in any state,...
Definition: QuEST.c:822
void destroyComplexMatrixN(ComplexMatrixN matr)
Destroy a ComplexMatrixN instance created with createComplexMatrixN()
Definition: QuEST.c:1021
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 s...
Definition: QuEST.c:208
ComplexArray pairStateVec
Temporary storage for a chunk of the state vector received from another process in the MPI version.
Definition: QuEST.h:181
@ PAULI_I
Definition: QuEST.h:96
Complex getDensityAmp(Qureg qureg, long long int row, long long int col)
Get an amplitude from a density matrix at a given row and column.
Definition: QuEST.c:707
void getEnvironmentString(QuESTEnv env, Qureg qureg, char str[200])
Sets str to a string containing the number of qubits in qureg, and the hardware facilities used (e....
Definition: QuEST_gpu.cu:393
ComplexMatrixN createComplexMatrixN(int numQubits)
Create (dynamically) a square complex matrix which can be passed to the multi-qubit general unitary f...
Definition: QuEST.c:1000
qreal getImagAmp(Qureg qureg, long long int index)
Get the imaginary component of the complex probability amplitude at an index in the state vector.
Definition: QuEST.c:683
void mixKrausMap(Qureg qureg, int target, ComplexMatrix2 *ops, int numOps)
Apply a general single-qubit Kraus map to a density matrix, as specified by at most four Kraus operat...
Definition: QuEST.c:966
qreal z
Definition: QuEST.h:150
void mixDephasing(Qureg qureg, const int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit dephasing noise.
Definition: QuEST.c:902
int numChunks
Number of chunks the state vector is broken up into – the number of MPI processes used.
Definition: QuEST.h:176
qreal calcPurity(Qureg qureg)
Calculates the purity of a density matrix, by the trace of the density matrix squared.
Definition: QuEST.c:855
void clearRecordedQASM(Qureg qureg)
Clear all QASM so far recorded.
Definition: QuEST.c:93
int measure(Qureg qureg, int measureQubit)
Measures a single qubit, collapsing it randomly to 0 or 1.
Definition: QuEST.c:756
qreal calcFidelity(Qureg qureg, Qureg pureState)
Calculates the fidelity of qureg (a statevector or density matrix) against a reference pure state (ne...
Definition: QuEST.c:861
ComplexArray deviceStateVec
Storage for wavefunction amplitudes in the GPU version.
Definition: QuEST.h:184
void seedQuEST(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_common.c:208
void mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit homogeneous depolarising noise.
Definition: QuEST.c:943
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.
Definition: QuEST.c:186
void cloneQureg(Qureg targetQureg, Qureg copyQureg)
Set targetQureg to be a clone of copyQureg.
Definition: QuEST.c:163
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).
Definition: QuEST.c:281
Represents a 4x4 matrix of complex numbers.
Definition: QuEST.h:125
Information about the environment the program is running in.
Definition: QuEST.h:199
void pauliZ(Qureg qureg, const int targetQubit)
Apply the single-qubit Pauli-Z (also known as the Z, sigma-Z or phase-flip) gate.
Definition: QuEST.c:453
void multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle)
Introduce a phase factor on state of the passed qubits.
Definition: QuEST.c:509
ComplexMatrixN bindArraysToStackComplexMatrixN(int numQubits, qreal re[][1<< numQubits], qreal im[][1<< numQubits], qreal **reStorage, qreal **imStorage)
Definition: QuEST_common.c:606
Represents a general 2^N by 2^N matrix of complex numbers.
Definition: QuEST.h:136
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.
Definition: QuEST.c:547
#define qreal
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.
Definition: QuEST.c:640
void stopRecordingQASM(Qureg qureg)
Disable QASM recording.
Definition: QuEST.c:89
void setAmps(Qureg qureg, long long int startInd, qreal *reals, qreal *imags, long long int numAmps)
Overwrites a subset of the amplitudes in qureg, with those passed in reals and imags.
Definition: QuEST.c:779
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.
Definition: QuEST.c:372
void multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits)
Apply the multiple-qubit controlled phase flip gate, also known as the multiple-qubit controlled paul...
Definition: QuEST.c:559
@ PAULI_X
Definition: QuEST.h:96
Complex getAmp(Qureg qureg, long long int index)
Get the complex amplitude at a given index in the state vector.
Definition: QuEST.c:697
void reportState(Qureg qureg)
Print the current state vector of probability amplitudes for a set of qubits to file.
Definition: QuEST_common.c:215
void initComplexMatrixN(ComplexMatrixN m, qreal real[][1<< m.numQubits], qreal imag[][1<< m.numQubits])
Initialises a ComplexMatrixN instance to have the passed real and imag values.
Definition: QuEST.c:1037
int measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb)
Measures a single qubit, collapsing it randomly to 0 or 1, and additionally gives the probability of ...
Definition: QuEST.c:743
int numQubitsInStateVec
Number of qubits in the state-vector - this is double the number represented for mixed states.
Definition: QuEST.h:167
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).
Definition: QuEST.c:312
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,...
Definition: QuEST.c:387
void invalidQuESTInputError(const char *errMsg, const char *errFunc)
An internal function called when invalid arguments are passed to a QuEST API call,...
void setWeightedQureg(Complex fac1, Qureg qureg1, Complex fac2, Qureg qureg2, Complex facOut, Qureg out)
Modifies qureg out to the result of (facOut out + fac1 qureg1 + fac2 qureg2), imposing no constraints...
Definition: QuEST.c:795
int chunkId
The position of the chunk of the state vector held by this process in the full state vector.
Definition: QuEST.h:174
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).
Definition: QuEST.c:329
void phaseShift(Qureg qureg, const int targetQubit, qreal angle)
Shift the phase between and of a single qubit by a given angle.
Definition: QuEST.c:486
qreal calcHilbertSchmidtDistance(Qureg a, Qureg b)
Computes the Hilbert Schmidt distance between two density matrices a and b, defined as the Frobenius ...
Definition: QuEST.c:889
qreal y
Definition: QuEST.h:150
qreal imag[2][2]
Definition: QuEST.h:117
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 qubit...
Definition: QuEST.c:295
qreal x
Definition: QuEST.h:150
void compactUnitary(Qureg qureg, const int targetQubit, Complex alpha, Complex beta)
Apply a single-qubit unitary parameterised by two given complex scalars.
Definition: QuEST.c:403
long long int numAmpsPerChunk
Number of probability amplitudes held in stateVec by this process In the non-MPI version,...
Definition: QuEST.h:170
void hadamard(Qureg qureg, const int targetQubit)
Apply the single-qubit Hadamard gate.
Definition: QuEST.c:175
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.
Definition: QuEST.c:197
void swapGate(Qureg qureg, int qubit1, int qubit2)
Performs a SWAP gate between qubit1 and qubit2.
Definition: QuEST.c:599
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 ...
Definition: QuEST.c:359
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.
Definition: QuEST.c:231
void initStateFromAmps(Qureg qureg, qreal *reals, qreal *imags)
Initialise qureg by specifying the complete statevector.
Definition: QuEST.c:155
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,...
Definition: QuEST.c:523
void copyStateToGPU(Qureg qureg)
In GPU mode, this copies the state-vector (or density matrix) from RAM (qureg.stateVec) to VRAM / GPU...
Definition: QuEST_cpu.c:36
void writeRecordedQASMToFile(Qureg qureg, char *filename)
Writes recorded QASM to a file, throwing an error if inaccessible.
Definition: QuEST.c:101
int numRanks
Definition: QuEST.h:202
qreal imag[4][4]
Definition: QuEST.h:128
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.
Definition: QuEST.c:586
qreal getRealAmp(Qureg qureg, long long int index)
Get the real component of the complex probability amplitude at an index in the state vector.
Definition: QuEST.c:676
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).
Definition: QuEST.c:268
@ PAULI_Y
Definition: QuEST.h:96
int getNumQubits(Qureg qureg)
Get the number of qubits in a qureg object.
Definition: QuEST.c:666
Complex calcInnerProduct(Qureg bra, Qureg ket)
Computes the inner product of two equal-size state vectors, given by.
Definition: QuEST.c:829
void controlledPhaseShift(Qureg qureg, const int idQubit1, const int idQubit2, qreal angle)
Introduce a phase factor on state of qubits idQubit1 and idQubit2.
Definition: QuEST.c:497
void destroyQureg(Qureg qureg, QuESTEnv env)
Deallocate a Qureg object representing a set of qubits.
Definition: QuEST.c:75
void mixTwoQubitKrausMap(Qureg qureg, int target1, int target2, ComplexMatrix4 *ops, int numOps)
Apply a general two-qubit Kraus map to a density matrix, as specified by at most sixteen Kraus operat...
Definition: QuEST.c:976
qreal ** real
Definition: QuEST.h:139
void initDebugState(Qureg qureg)
Initialises qureg to be in the un-normalised, non-physical state with with n-th complex amplitude (2n...
Definition: QuEST.c:1057
QASMLogger * qasmLog
Storage for generated QASM output.
Definition: QuEST.h:189
qreal * secondLevelReduction
Definition: QuEST.h:186
void startRecordingQASM(Qureg qureg)
Enable QASM recording.
Definition: QuEST.c:85
void applyPauliSum(Qureg inQureg, enum pauliOpType *allPauliCodes, qreal *termCoeffs, int numSumTerms, Qureg outQureg)
Modifies outQureg to be the result of applying the weighted sum of Pauli products (a Hermitian but no...
Definition: QuEST.c:806
void mixDamping(Qureg qureg, const int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit amplitude damping (decay to 0 state).
Definition: QuEST.c:935
void initClassicalState(Qureg qureg, long long int stateInd)
Initialise a set of qubits to the classical state (also known as a "computational basis state") with...
Definition: QuEST.c:132
void unitary(Qureg qureg, const int targetQubit, ComplexMatrix2 u)
Apply a general single-qubit unitary (including a global phase factor).
Definition: QuEST.c:347
Represents a system of qubits.
Definition: QuEST.h:160
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.
Definition: QuEST.c:243
void mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal prob)
Mixes a density matrix qureg to induce two-qubit dephasing noise.
Definition: QuEST.c:912
qreal ** imag
Definition: QuEST.h:140
ComplexArray stateVec
Computational state amplitudes - a subset thereof in the MPI version.
Definition: QuEST.h:179
qreal real[2][2]
Definition: QuEST.h:116
long long int getNumAmps(Qureg qureg)
Get the number of probability amplitudes in a qureg object, given by 2^numQubits.
Definition: QuEST.c:670
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...
Definition: QuEST.c:416
void seedQuESTDefault(void)
Seed the Mersenne Twister used for random number generation in the QuEST environment with an example ...
int isDensityMatrix
Whether this instance is a density-state representation.
Definition: QuEST.h:163
void reportQuESTEnv(QuESTEnv env)
Report information about the QuEST environment.
int numQubits
Definition: QuEST.h:138
Qureg createCloneQureg(Qureg qureg, QuESTEnv env)
Create a new Qureg which is an exact clone of the passed qureg, which can be either a statevector or ...
Definition: QuEST.c:62
qreal collapseToOutcome(Qureg qureg, const int measureQubit, int outcome)
Updates qureg to be consistent with measuring measureQubit in the given outcome (0 or 1),...
Definition: QuEST.c:724
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.
Definition: QuEST.c:219
qreal calcExpecPauliSum(Qureg qureg, enum pauliOpType *allPauliCodes, qreal *termCoeffs, int numSumTerms, Qureg workspace)
Computes the expected value of a sum of products of Pauli operators.
Definition: QuEST.c:880
int numQubitsRepresented
The number of qubits represented in either the state-vector or density matrix.
Definition: QuEST.h:165
long long int numAmpsTotal
Total number of amplitudes, which are possibly distributed among machines.
Definition: QuEST.h:172
int syncQuESTSuccess(int successCode)
Performs a logical AND on all successCodes held by all processes.
qreal real
Definition: QuEST.h:105
void mixDensityMatrix(Qureg combineQureg, qreal prob, Qureg otherQureg)
Modifies combineQureg to become (1-prob)combineProb + prob otherQureg.
Definition: QuEST.c:770
Qureg createQureg(int numQubits, QuESTEnv env)
Create a Qureg object representing a set of qubits which will remain in a pure state.
Definition: QuEST.c:34
qreal calcProbOfOutcome(Qureg qureg, const int measureQubit, int outcome)
Gives the probability of a specified qubit being measured in the given outcome (0 or 1).
Definition: QuEST.c:845
void multiRotateZ(Qureg qureg, int *qubits, int numQubits, qreal angle)
Apply a multi-qubit Z rotation on a selected number of qubits.
Definition: QuEST.c:624
qreal imag
Definition: QuEST.h:106
void pauliY(Qureg qureg, const int targetQubit)
Apply the single-qubit Pauli-Y (also known as the Y or sigma-Y) gate.
Definition: QuEST.c:442
void mixPauli(Qureg qureg, int targetQubit, qreal probX, qreal probY, qreal probZ)
Mixes a density matrix qureg to induce general single-qubit Pauli noise.
Definition: QuEST.c:955
Represents one complex number.
Definition: QuEST.h:103
void twoQubitUnitary(Qureg qureg, const int targetQubit1, const int targetQubit2, ComplexMatrix4 u)
Apply a general two-qubit unitary (including a global phase factor).
Definition: QuEST.c:255
QuESTEnv createQuESTEnv(void)
Create the QuEST execution environment.
void sGate(Qureg qureg, const int targetQubit)
Apply the single-qubit S gate.
Definition: QuEST.c:464
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.
Definition: QuEST.c:573
void initZeroState(Qureg qureg)
Initialise a set of qubits to the classical zero state .
Definition: QuEST.c:111
qreal calcDensityInnerProduct(Qureg rho1, Qureg rho2)
Computes the Hilbert-Schmidt scalar product (which is equivalent to the Frobenius inner product of ma...
Definition: QuEST.c:837
Qureg createDensityQureg(int numQubits, QuESTEnv env)
Create a Qureg for qubits which are represented by a density matrix, and can be in mixed states.
Definition: QuEST.c:48
qreal * firstLevelReduction
Storage for reduction of probabilities on GPU.
Definition: QuEST.h:186
void initPlusState(Qureg qureg)
Initialise a set of qubits to the plus state (and similarly for density matrices).
Definition: QuEST.c:123
qreal calcExpecPauliProd(Qureg qureg, int *targetQubits, enum pauliOpType *pauliCodes, int numTargets, Qureg workspace)
Computes the expected value of a product of Pauli operators.
Definition: QuEST.c:871
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.
Definition: QuEST.c:431
void sqrtSwapGate(Qureg qureg, int qb1, int qb2)
Performs a sqrt SWAP gate between qubit1 and qubit2.
Definition: QuEST.c:611
void mixMultiQubitKrausMap(Qureg qureg, int *targets, int numTargets, ComplexMatrixN *ops, int numOps)
Apply a general N-qubit Kraus map to a density matrix, as specified by at most (2N)^2 Kraus operators...
Definition: QuEST.c:986
void printRecordedQASM(Qureg qureg)
Print recorded QASM to stdout.
Definition: QuEST.c:97
void reportStateToScreen(Qureg qureg, QuESTEnv env, int reportRank)
Print the current state vector of probability amplitudes for a set of qubits to standard out.
Definition: QuEST.c:1073
Represents a 2x2 matrix of complex numbers.
Definition: QuEST.h:114
void mixDepolarising(Qureg qureg, const int targetQubit, qreal prob)
Mixes a density matrix qureg to induce single-qubit homogeneous depolarising noise.
Definition: QuEST.c:924