QuEST_internal.h
1// Distributed under MIT licence. See https://github.com/QuEST-Kit/QuEST/blob/master/LICENCE.txt for details
2
11# ifndef QUEST_INTERNAL_H
12# define QUEST_INTERNAL_H
13
14# include "QuEST.h"
15# include "QuEST_precision.h"
16
17# ifdef __cplusplus
18extern "C" {
19# endif
20
21
22/*
23 * general functions
24 */
25
26long long int getQubitBitMask(int* controlQubits, int numControlQubits);
27
28long long int getControlFlipMask(int* controlQubits, int* controlState, int numControlQubits);
29
30unsigned long int hashString(char *str);
31
32qreal getVectorMagnitude(Vector vec);
33
34Complex getConjugateScalar(Complex scalar);
35
36ComplexMatrix2 getConjugateMatrix2(ComplexMatrix2 src);
37
38ComplexMatrix4 getConjugateMatrix4(ComplexMatrix4 src);
39
40void setConjugateMatrixN(ComplexMatrixN m);
41
42void ensureIndsIncrease(int* ind1, int* ind2);
43
44void getComplexPairFromRotation(qreal angle, Vector axis, Complex* alpha, Complex* beta);
45
46void getZYZRotAnglesFromComplexPair(Complex alpha, Complex beta, qreal* rz2, qreal* ry, qreal* rz1);
47
48void getComplexPairAndPhaseFromUnitary(ComplexMatrix2 u, Complex* alpha, Complex* beta, qreal* globalPhase);
49
50void shiftIndices(int* indices, int numIndices, int shift);
51
52void shiftSubregIndices(int* allInds, int* numIndsPerReg, int numRegs, int shift);
53
54void conjugateMatrixN(ComplexMatrixN u);
55
56void getQuESTDefaultSeedKey(unsigned long int *key);
57
58
59/*
60 * operations upon density matrices
61 */
62
63void densmatr_initPlusState(Qureg targetQureg);
64
65void densmatr_initClassicalState(Qureg qureg, long long int stateInd);
66
67void densmatr_initPureState(Qureg targetQureg, Qureg copyQureg);
68
69qreal densmatr_calcTotalProb(Qureg qureg);
70
71qreal densmatr_calcPurity(Qureg qureg);
72
73qreal densmatr_calcFidelity(Qureg qureg, Qureg pureState);
74
75qreal densmatr_calcHilbertSchmidtDistance(Qureg a, Qureg b);
76
77qreal densmatr_calcInnerProduct(Qureg a, Qureg b);
78
79qreal densmatr_calcProbOfOutcome(Qureg qureg, int measureQubit, int outcome);
80
81void densmatr_calcProbOfAllOutcomes(qreal* retProbs, Qureg qureg, int* qubits, int numQubits);
82
83void densmatr_collapseToKnownProbOutcome(Qureg qureg, int measureQubit, int outcome, qreal outcomeProb);
84
85int densmatr_measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb);
86
87void densmatr_mixDephasing(Qureg qureg, int targetQubit, qreal dephase);
88
89void densmatr_mixTwoQubitDephasing(Qureg qureg, int qubit1, int qubit2, qreal dephase);
90
91void densmatr_mixDepolarising(Qureg qureg, int targetQubit, qreal depolLevel);
92
93void densmatr_mixDamping(Qureg qureg, int targetQubit, qreal damping);
94
95void densmatr_mixTwoQubitDepolarising(Qureg qureg, int qubit1, int qubit2, qreal depolLevel);
96
97void densmatr_mixPauli(Qureg qureg, int qubit, qreal pX, qreal pY, qreal pZ);
98
99void densmatr_mixDensityMatrix(Qureg combineQureg, qreal otherProb, Qureg otherQureg);
100
101void densmatr_mixKrausMap(Qureg qureg, int target, ComplexMatrix2 *ops, int numOps);
102
103void densmatr_mixTwoQubitKrausMap(Qureg qureg, int target1, int target2, ComplexMatrix4 *ops, int numOps);
104
105void densmatr_mixMultiQubitKrausMap(Qureg qureg, int* targets, int numTargets, ComplexMatrixN* ops, int numOps);
106
107void densmatr_applyDiagonalOp(Qureg qureg, DiagonalOp op);
108
109Complex densmatr_calcExpecDiagonalOp(Qureg qureg, DiagonalOp op);
110
111void densmatr_applyMultiQubitKrausSuperoperator(Qureg qureg, int *targets, int numTargets, ComplexMatrixN superOp); // exposed for QuESTlink Monte Carlo
112
113void densmatr_setQuregToPauliHamil(Qureg qureg, PauliHamil hamil);
114
115
116/*
117 * operations upon state vectors
118 */
119
120void statevec_reportStateToScreen(Qureg qureg, QuESTEnv env, int reportRank);
121
122void statevec_createQureg(Qureg *qureg, int numQubits, QuESTEnv env);
123
124void statevec_destroyQureg(Qureg qureg, QuESTEnv env);
125
126void statevec_initBlankState(Qureg qureg);
127
128void statevec_initZeroState(Qureg qureg);
129
130void statevec_initPlusState(Qureg qureg);
131
132void statevec_initDebugState(Qureg qureg);
133
134void statevec_initClassicalState(Qureg qureg, long long int stateInd);
135
136void statevec_setAmps(Qureg qureg, long long int startInd, qreal* reals, qreal* imags, long long int numAmps);
137
138void statevec_cloneQureg(Qureg targetQureg, Qureg copyQureg);
139
140void statevec_multiControlledPhaseFlip(Qureg qureg, int *controlQubits, int numControlQubits);
141
142void statevec_controlledPhaseFlip(Qureg qureg, int idQubit1, int idQubit2);
143
144void statevec_phaseShift(Qureg qureg, int targetQubit, qreal angle);
145
146void statevec_phaseShiftByTerm(Qureg qureg, int targetQubit, Complex term);
147
148void statevec_controlledPhaseShift(Qureg qureg, int idQubit1, int idQubit2, qreal angle);
149
150void statevec_multiControlledPhaseShift(Qureg qureg, int *controlQubits, int numControlQubits, qreal angle);
151
152void statevec_sGate(Qureg qureg, int targetQubit);
153
154void statevec_tGate(Qureg qureg, int targetQubit);
155
156void statevec_sGateConj(Qureg qureg, int targetQubit);
157
158void statevec_tGateConj(Qureg qureg, int targetQubit);
159
160void statevec_pauliX(Qureg qureg, int targetQubit);
161
162void statevec_pauliY(Qureg qureg, int targetQubit);
163
164void statevec_pauliYConj(Qureg qureg, int targetQubit);
165
166void statevec_pauliZ(Qureg qureg, int targetQubit);
167
168void statevec_controlledPauliY(Qureg qureg, int controlQubit, int targetQubit);
169
170void statevec_controlledPauliYConj(Qureg qureg, int controlQubit, int targetQubit);
171
172qreal statevec_getRealAmp(Qureg qureg, long long int index);
173
174qreal statevec_getImagAmp(Qureg qureg, long long int index);
175
176qreal statevec_getProbAmp(Qureg qureg, long long int index);
177
178qreal statevec_calcTotalProb(Qureg qureg);
179
180qreal statevec_calcFidelity(Qureg qureg, Qureg pureState);
181
182Complex statevec_calcInnerProduct(Qureg bra, Qureg ket);
183
184qreal statevec_calcExpecPauliProd(Qureg qureg, int* targetQubits, enum pauliOpType* pauliCodes, int numTargets, Qureg workspace);
185
186qreal statevec_calcExpecPauliSum(Qureg qureg, enum pauliOpType* allCodes, qreal* termCoeffs, int numSumTerms, Qureg workspace);
187
188void statevec_compactUnitary(Qureg qureg, int targetQubit, Complex alpha, Complex beta);
189
190void statevec_unitary(Qureg qureg, int targetQubit, ComplexMatrix2 u);
191
192void statevec_twoQubitUnitary(Qureg qureg, int targetQubit1, int targetQubit2, ComplexMatrix4 u);
193
194void statevec_controlledTwoQubitUnitary(Qureg qureg, int controlQubit, int targetQubit1, int targetQubit2, ComplexMatrix4 u);
195
196void statevec_multiControlledTwoQubitUnitary(Qureg qureg, long long int ctrlMask, int targetQubit1, int targetQubit2, ComplexMatrix4 u);
197
198void statevec_multiQubitUnitary(Qureg qureg, int* targets, int numTargets, ComplexMatrixN u);
199
200void statevec_controlledMultiQubitUnitary(Qureg qureg, int ctrl, int* targets, int numTargets, ComplexMatrixN u);
201
202void statevec_multiControlledMultiQubitUnitary(Qureg qureg, long long int ctrlMask, int* targs, int numTargs, ComplexMatrixN u);
203
204void statevec_rotateX(Qureg qureg, int rotQubit, qreal angle);
205
206void statevec_rotateY(Qureg qureg, int rotQubit, qreal angle);
207
208void statevec_rotateZ(Qureg qureg, int rotQubit, qreal angle);
209
210void statevec_rotateAroundAxis(Qureg qureg, int rotQubit, qreal angle, Vector axis);
211
212void statevec_rotateAroundAxisConj(Qureg qureg, int rotQubit, qreal angle, Vector axis);
213
214void statevec_controlledRotateX(Qureg qureg, int controlQubit, int targetQubit, qreal angle);
215
216void statevec_controlledRotateY(Qureg qureg, int controlQubit, int targetQubit, qreal angle);
217
218void statevec_controlledRotateZ(Qureg qureg, int controlQubit, int targetQubit, qreal angle);
219
220void statevec_controlledRotateAroundAxis(Qureg qureg, int controlQubit, int targetQubit, qreal angle, Vector axis);
221
222void statevec_controlledRotateAroundAxisConj(Qureg qureg, int controlQubit, int targetQubit, qreal angle, Vector axis);
223
224void statevec_controlledCompactUnitary(Qureg qureg, int controlQubit, int targetQubit, Complex alpha, Complex beta);
225
226void statevec_controlledUnitary(Qureg qureg, int controlQubit, int targetQubit, ComplexMatrix2 u);
227
228void statevec_multiControlledUnitary(Qureg qureg, long long int ctrlQubitsMask, long long int ctrlFlipMask, int targetQubit, ComplexMatrix2 u);
229
230void statevec_hadamard(Qureg qureg, int targetQubit);
231
232void statevec_controlledNot(Qureg qureg, int controlQubit, int targetQubit);
233
234void statevec_multiControlledMultiQubitNot(Qureg qureg, int ctrlMask, int targMask);
235
236qreal statevec_calcProbOfOutcome(Qureg qureg, int measureQubit, int outcome);
237
238void statevec_calcProbOfAllOutcomes(qreal* retProbs, Qureg qureg, int* qubits, int numQubits);
239
240void statevec_collapseToKnownProbOutcome(Qureg qureg, int measureQubit, int outcome, qreal outcomeProb);
241
242int statevec_measureWithStats(Qureg qureg, int measureQubit, qreal *outcomeProb);
243
244void statevec_swapQubitAmps(Qureg qureg, int qb1, int qb2);
245
246void statevec_sqrtSwapGate(Qureg qureg, int qb1, int qb2);
247
248void statevec_sqrtSwapGateConj(Qureg qureg, int qb1, int qb2);
249
250void statevec_multiRotateZ(Qureg qureg, long long int mask, qreal angle);
251
252void statevec_multiControlledMultiRotateZ(Qureg qureg, long long int ctrlMask, long long int targMask, qreal angle);
253
254void statevec_multiRotatePauli(Qureg qureg, int* targetQubits, enum pauliOpType* targetPaulis, int numTargets, qreal angle, int applyConj);
255
256void statevec_multiControlledMultiRotatePauli(Qureg qureg, long long int ctrlMask, int* targetQubits, enum pauliOpType* targetPaulis, int numTargets, qreal angle, int applyConj);
257
258void statevec_setWeightedQureg(Complex fac1, Qureg qureg1, Complex fac2, Qureg qureg2, Complex facOut, Qureg out);
259
260void statevec_applyPauliSum(Qureg inQureg, enum pauliOpType* allCodes, qreal* termCoeffs, int numSumTerms, Qureg outQureg);
261
262void statevec_applyDiagonalOp(Qureg qureg, DiagonalOp op);
263
264Complex statevec_calcExpecDiagonalOp(Qureg qureg, DiagonalOp op);
265
266void statevec_applyPhaseFuncOverrides(Qureg qureg, int* qubits, int numQubits, enum bitEncoding encoding, qreal* coeffs, qreal* exponents, int numTerms, long long int* overrideInds, qreal* overridePhases, int numOverrides, int conj);
267
268void statevec_applyMultiVarPhaseFuncOverrides(Qureg qureg, int* qubits, int* numQubitsPerReg, int numRegs, enum bitEncoding encoding, qreal* coeffs, qreal* exponents, int* numTermsPerReg, long long int* overrideInds, qreal* overridePhases, int numOverrides, int conj);
269
270void statevec_applyParamNamedPhaseFuncOverrides(Qureg qureg, int* qubits, int* numQubitsPerReg, int numRegs, enum bitEncoding encoding, enum phaseFunc functionNameCode, qreal* params, int numParams, long long int* overrideInds, qreal* overridePhases, int numOverrides, int conj);
271
272void statevec_copySubstateToGPU(Qureg qureg, long long int startInd, long long int numAmps);
273
274void statevec_copySubstateFromGPU(Qureg qureg, long long int startInd, long long int numAmps);
275
276void statevec_applySubDiagonalOp(Qureg qureg, int* targets, SubDiagonalOp op, int conj);
277
278
279/*
280 * operations which differentiate between state-vectors and density matrices internally
281 * (or do not operate upon Quregs)
282 */
283
284void agnostic_applyTrotterCircuit(Qureg qureg, PauliHamil hamil, qreal time, int order, int reps);
285
286void agnostic_applyQFT(Qureg qureg, int* qubits, int numQubits);
287
288DiagonalOp agnostic_createDiagonalOp(int numQubits, QuESTEnv env);
289
290void agnostic_destroyDiagonalOp(DiagonalOp op);
291
292void agnostic_syncDiagonalOp(DiagonalOp op);
293
294void agnostic_setDiagonalOpElems(DiagonalOp op, long long int startInd, qreal* real, qreal* imag, long long int numElems);
295
296void agnostic_initDiagonalOpFromPauliHamil(DiagonalOp op, PauliHamil hamil);
297
298# ifdef __cplusplus
299}
300# endif
301
302# endif // QUEST_INTERNAL_H
pauliOpType
Codes for specifying Pauli operators.
Definition: QuEST.h:113
#define qreal
A precision-agnostic floating point number, as determined by QuEST_PREC.
bitEncoding
Flags for specifying how the bits in sub-register computational basis states are mapped to indices in...
Definition: QuEST.h:288
phaseFunc
Flags for specifying named phase functions.
Definition: QuEST.h:249
Represents a 2x2 matrix of complex numbers.
Definition: QuEST.h:155
Represents a 4x4 matrix of complex numbers.
Definition: QuEST.h:193
Represents a general 2^N by 2^N matrix of complex numbers.
Definition: QuEST.h:204
Represents one complex number.
Definition: QuEST.h:121
Represents a diagonal complex operator on the full Hilbert state of a Qureg.
Definition: QuEST.h:317
A Pauli Hamiltonian, expressed as a real-weighted sum of pauli products, and which can hence represen...
Definition: QuEST.h:297
Information about the environment the program is running in.
Definition: QuEST.h:406
Represents a system of qubits.
Definition: QuEST.h:361
Represents a diagonal complex operator of a smaller dimension than the full Hilbert state of a Qureg.
Definition: QuEST.h:341
Represents a 3-vector of real numbers.
Definition: QuEST.h:216