QuEST_cpu_internal.h
1// Distributed under MIT licence. See https://github.com/QuEST-Kit/QuEST/blob/master/LICENCE.txt for details
2
13# ifndef QUEST_CPU_INTERNAL_H
14# define QUEST_CPU_INTERNAL_H
15
16# include "QuEST_precision.h"
17
18
19/*
20* Bit twiddling functions are defined seperately here in the CPU backend,
21* since the GPU backend needs a device-specific redefinition to be callable
22* from GPU kernels. These are called in both QuEST_cpu and QuEST_cpu_distributed
23* and defined in here since public inline methods in C must go in the header
24*/
25
26static inline int extractBit (const int locationOfBitFromRight, const long long int theEncodedNumber) {
27 return (theEncodedNumber & ( 1LL << locationOfBitFromRight )) >> locationOfBitFromRight;
28}
29
30static inline long long int flipBit(const long long int number, const int bitInd) {
31 return (number ^ (1LL << bitInd));
32}
33
34static inline int maskContainsBit(const long long int mask, const int bitInd) {
35 return mask & (1LL << bitInd);
36}
37
38static inline int isOddParity(const long long int number, const int qb1, const int qb2) {
39 return extractBit(qb1, number) != extractBit(qb2, number);
40}
41
42static inline long long int insertZeroBit(const long long int number, const int index) {
43 long long int left, right;
44 left = (number >> index) << index;
45 right = number - left;
46 return (left << 1) ^ right;
47}
48
49static inline long long int insertTwoZeroBits(const long long int number, const int bit1, const int bit2) {
50 int small = (bit1 < bit2)? bit1 : bit2;
51 int big = (bit1 < bit2)? bit2 : bit1;
52 return insertZeroBit(insertZeroBit(number, small), big);
53}
54
55
56/*
57 * density matrix operations
58 */
59
60qreal densmatr_calcPurityLocal(Qureg qureg);
61
62void densmatr_initPureStateLocal(Qureg targetQureg, Qureg copyQureg);
63
64qreal densmatr_calcFidelityLocal(Qureg qureg, Qureg pureState);
65
66qreal densmatr_calcHilbertSchmidtDistanceSquaredLocal(Qureg a, Qureg b);
67
68qreal densmatr_calcInnerProductLocal(Qureg a, Qureg b);
69
70qreal densmatr_findProbabilityOfZeroLocal(Qureg qureg, int measureQubit);
71
72void densmatr_mixDepolarisingLocal(Qureg qureg, int targetQubit, qreal depolLevel);
73
74void densmatr_mixDepolarisingDistributed(Qureg qureg, int targetQubit, qreal depolLevel);
75
76void densmatr_mixDampingLocal(Qureg qureg, int targetQubit, qreal damping);
77
78void densmatr_mixDampingDistributed(Qureg qureg, int targetQubit, qreal damping);
79
80void densmatr_mixTwoQubitDepolarisingLocal(Qureg qureg, int qubit1, int qubit2, qreal delta, qreal gamma);
81
82void densmatr_mixTwoQubitDepolarisingLocalPart1(Qureg qureg, int qubit1, int qubit2, qreal delta);
83
84void densmatr_mixTwoQubitDepolarisingDistributed(Qureg qureg, int targetQubit,
85 int qubit2, qreal delta, qreal gamma);
86
87void densmatr_mixTwoQubitDepolarisingQ1LocalQ2DistributedPart3(Qureg qureg, int targetQubit,
88 int qubit2, qreal delta, qreal gamma);
89
90void densmatr_applyDiagonalOpLocal(Qureg qureg, DiagonalOp op);
91
92Complex densmatr_calcExpecDiagonalOpLocal(Qureg qureg, DiagonalOp op);
93
94void densmatr_calcProbOfAllOutcomesLocal(qreal* retProbs, Qureg qureg, int* qubits, int numQubits);
95
96
97/*
98 * state vector operations
99 */
100
101Complex statevec_calcInnerProductLocal(Qureg bra, Qureg ket);
102
103void statevec_compactUnitaryLocal (Qureg qureg, int targetQubit, Complex alpha, Complex beta);
104
105void statevec_compactUnitaryDistributed (Qureg qureg,
106 Complex rot1, Complex rot2,
107 ComplexArray stateVecUp,
108 ComplexArray stateVecLo,
109 ComplexArray stateVecOut);
110
111void statevec_unitaryLocal(Qureg qureg, int targetQubit, ComplexMatrix2 u);
112
113void statevec_unitaryDistributed (Qureg qureg,
114 Complex rot1, Complex rot2,
115 ComplexArray stateVecUp,
116 ComplexArray stateVecLo,
117 ComplexArray stateVecOut);
118
119void statevec_controlledCompactUnitaryLocal (Qureg qureg, int controlQubit, int targetQubit,
120 Complex alpha, Complex beta);
121
122void statevec_controlledCompactUnitaryDistributed (Qureg qureg, int controlQubit,
123 Complex rot1, Complex rot2,
124 ComplexArray stateVecUp,
125 ComplexArray stateVecLo,
126 ComplexArray stateVecOut);
127
128void statevec_controlledUnitaryLocal(Qureg qureg, int controlQubit, int targetQubit, ComplexMatrix2 u);
129
130void statevec_controlledUnitaryDistributed (Qureg qureg, int controlQubit,
131 Complex rot1, Complex rot2,
132 ComplexArray stateVecUp,
133 ComplexArray stateVecLo,
134 ComplexArray stateVecOut);
135
136void statevec_multiControlledUnitaryLocal(Qureg qureg, int targetQubit,
137 long long int ctrlQubitsMask, long long int ctrlFlipMask, ComplexMatrix2 u);
138
139void statevec_multiControlledUnitaryDistributed (Qureg qureg,
140 int targetQubit,
141 long long int ctrlQubitsMask, long long int ctrlFlipMask,
142 Complex rot1, Complex rot2,
143 ComplexArray stateVecUp,
144 ComplexArray stateVecLo,
145 ComplexArray stateVecOut);
146
147void statevec_pauliXLocal(Qureg qureg, int targetQubit);
148
149void statevec_pauliXDistributed (Qureg qureg,
150 ComplexArray stateVecIn,
151 ComplexArray stateVecOut);
152
153void statevec_pauliYLocal(Qureg qureg, int targetQubit, int conjFac);
154
155void statevec_pauliYDistributed(Qureg qureg,
156 ComplexArray stateVecIn,
157 ComplexArray stateVecOut,
158 int updateUpper, int conjFac);
159
160void statevec_controlledPauliYLocal(Qureg qureg, int controlQubit, int targetQubit, int conjFactor);
161
162void statevec_controlledPauliYDistributed(Qureg qureg, int controlQubit,
163 ComplexArray stateVecIn,
164 ComplexArray stateVecOut, int conjFactor);
165
166void statevec_hadamardLocal (Qureg qureg, int targetQubit);
167
168void statevec_hadamardDistributed (Qureg qureg,
169 ComplexArray stateVecUp,
170 ComplexArray stateVecLo,
171 ComplexArray stateVecOut, int updateUpper);
172
173void statevec_controlledNotLocal(Qureg qureg, int controlQubit, int targetQubit);
174
175void statevec_controlledNotDistributed (Qureg qureg, int controlQubit,
176 ComplexArray stateVecIn,
177 ComplexArray stateVecOut);
178
179void statevec_multiControlledMultiQubitNotLocal(Qureg qureg, int ctrlMask, int targMask);
180
181void statevec_multiControlledMultiQubitNotDistributed(Qureg qureg, int ctrlMask, int targMask,
182 ComplexArray stateVecIn,
183 ComplexArray stateVecOut);
184
185qreal statevec_findProbabilityOfZeroLocal (Qureg qureg, int measureQubit);
186
187qreal statevec_findProbabilityOfZeroDistributed (Qureg qureg);
188
189void statevec_collapseToKnownProbOutcomeLocal(Qureg qureg, int measureQubit, int outcome, qreal totalProbability);
190
191void statevec_collapseToKnownProbOutcomeDistributedRenorm (Qureg qureg, int measureQubit, qreal totalProbability);
192
193void statevec_collapseToOutcomeDistributedSetZero(Qureg qureg);
194
195void statevec_swapQubitAmpsLocal(Qureg qureg, int qb1, int qb2);
196
197void statevec_swapQubitAmpsDistributed(Qureg qureg, int pairRank, int qb1, int qb2);
198
199void statevec_multiControlledTwoQubitUnitaryLocal(Qureg qureg, long long int ctrlMask, int q1, int q2, ComplexMatrix4 u);
200
201void statevec_multiControlledMultiQubitUnitaryLocal(Qureg qureg, long long int ctrlMask, int* targs, int numTargs, ComplexMatrixN u);
202
203Complex statevec_calcExpecDiagonalOpLocal(Qureg qureg, DiagonalOp op);
204
205void statevec_calcProbOfAllOutcomesLocal(qreal* retProbs, Qureg qureg, int* qubits, int numQubits);
206
207
208# endif // QUEST_CPU_INTERNAL_H
#define qreal
A precision-agnostic floating point number, as determined by QuEST_PREC.
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
Represents a system of qubits.
Definition: QuEST.h:361