MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / cpu_statevec_packAmpsIntoBuffer

Function cpu_statevec_packAmpsIntoBuffer

quest/src/cpu/cpu_subroutines.cpp:220–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218
219template <int NumQubits>
220qindex cpu_statevec_packAmpsIntoBuffer(Qureg qureg, vector<int> qubitInds, vector<int> qubitStates) {
221
222 assert_numQubitsMatchesQubitStatesAndTemplateParam(qubitInds.size(), qubitStates.size(), NumQubits);
223
224 // each control qubit halves the needed iterations
225 qindex numIts = qureg.numAmpsPerNode / powerOf2(qubitInds.size());
226
227 // amplitudes are packed at an offset into the buffer
228 qindex offset = getSubBufferSendInd(qureg);
229
230 auto sortedQubitInds = util_getSorted(qubitInds);
231 auto qubitStateMask = util_getBitMask(qubitInds, qubitStates);
232
233 // use template param to compile-time unroll loop in insertBits()
234 SET_VAR_AT_COMPILE_TIME(int, numBits, NumQubits, qubitInds.size());
235
236 #pragma omp parallel for if(qureg.isMultithreaded)
237 for (qindex n=0; n<numIts; n++) {
238
239 // i = nth local index where qubits are in specified states
240 qindex i = insertBitsWithMaskedValues(n, sortedQubitInds.data(), numBits, qubitStateMask);
241
242 // pack the potentially-strided amplitudes into a contiguous sub-buffer
243 qureg.cpuCommBuffer[offset + n] = qureg.cpuAmps[i];
244 }
245
246 // return the number of packed amps
247 return numIts;
248}
249
250
251qindex cpu_statevec_packPairSummedAmpsIntoBuffer(Qureg qureg, int qubit1, int qubit2, int qubit3, int bit2) {

Callers

nothing calls this directly

Calls 6

powerOf2Function · 0.85
getSubBufferSendIndFunction · 0.85
util_getSortedFunction · 0.85
util_getBitMaskFunction · 0.85

Tested by

no test coverage detected