19 #include "common/cudaengine.cuh"
31 class QPager :
public QEngine,
public std::enable_shared_from_this<QPager> {
76 template <
typename Qubit1Fn>
78 template <
typename Qubit1Fn>
80 Qubit1Fn fn,
const complex* mtrx,
bool isSqiCtrl =
false,
bool isIntraCtrled =
false);
81 template <
typename Qubit1Fn>
83 const bitCapInt& controlPerm, std::vector<bitLenInt> controls,
bitLenInt target, Qubit1Fn fn);
86 template <
typename F>
void CombineAndOp(F fn, std::vector<bitLenInt> bits);
127 bool ignored =
false,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
128 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devList = {},
133 int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
138 rgp, phaseFac, doNorm, ignored, useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh,
139 devList, qubitThreshold, separation_thresh)
142 rgp, phaseFac, doNorm, ignored, useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh,
143 devList, qubitThreshold, separation_thresh)
145 :
QPager({
QINTERFACE_CPU }, qBitCount, initState, rgp, phaseFac, doNorm, ignored, useHostMem, deviceId,
146 useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold, separation_thresh)
154 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
162 qPage->SetConcurrency(threadsPerEngine);
192 qPage->ZeroAmplitudes();
199 src->CombineEngines(qpp);
200 src->SeparateEngines(qpp,
true);
202 for (
size_t i = 0
U; i <
qPages.size(); ++i) {
203 qPages[i]->CopyStateVec(src->qPages[i]);
208 for (
size_t i = 0
U; i <
qPages.size(); ++i) {
226 SetAmplitudePage(std::dynamic_pointer_cast<QPager>(pageEnginePtr), srcOffset, dstOffset, length);
231 pageEnginePtr->CombineEngines();
232 qPages[0
U]->SetAmplitudePage(pageEnginePtr->qPages[0
U], srcOffset, dstOffset, length);
238 bitLenInt tcqpp = engine->qubitsPerPage();
239 engine->SeparateEngines(qpp,
true);
242 if (
qPages.size() == 1U) {
243 return qPages[0
U]->ShuffleBuffers(engine->qPages[0
U]);
246 const size_t offset =
qPages.size() >> 1U;
247 for (
size_t i = 0
U; i < offset; ++i) {
248 qPages[offset + i].swap(engine->qPages[i]);
265 return qPages[0
U]->ProbReg(start, length, permutation);
271 return qPages[0
U]->ApplyM(regMask, result, nrm);
276 return qPages[0
U]->GetExpectation(valueStart, valueLength);
282 qPages[0
U]->Apply2x2(offset1, offset2, mtrx, bitCount, qPowersSorted, doCalcNorm, norm_thresh);
288 toRet += qPage->GetRunningNorm();
296 for (
size_t i = 0
U; i <
qPages.size(); ++i) {
298 return qPages[i]->FirstNonzeroPhase();
355 if (
qPages.size() == 1U) {
356 return qPages[0
U]->MCMtrx(controls, mtrx, target);
364 if (
qPages.size() == 1U) {
365 return qPages[0
U]->MACMtrx(controls, mtrx, target);
377 bool ForceM(
bitLenInt qubit,
bool result,
bool doForce =
true,
bool doApply =
true);
402 const std::vector<bitLenInt>& controls);
404 const std::vector<bitLenInt>& controls);
406 bitLenInt length,
const std::vector<bitLenInt>& controls);
408 bitLenInt length,
const std::vector<bitLenInt>& controls);
410 bitLenInt length,
const std::vector<bitLenInt>& controls);
413 const unsigned char* values,
bool resetValue =
true);
415 bitLenInt carryIndex,
const unsigned char* values);
417 bitLenInt carryIndex,
const unsigned char* values);
439 return qPages[0
U]->ProbParity(mask);
448 return qPages[0
U]->ForceMParity(mask, result, doForce);
465 if (!qPage->isFinished()) {
493 for (
size_t i = 0
U; i <
qPages.size(); ++i) {
497 #if ENABLE_OPENCL || ENABLE_CUDA
504 log2Ocl(CUDAEngine::Instance().GetDeviceContextPtr(
devID)->GetMaxAlloc() /
sizeof(
complex)) - 1U;
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:237
void bi_div_mod_small(const BigInteger &left, BIG_INTEGER_HALF_WORD right, BigInteger *quotient, BIG_INTEGER_HALF_WORD *rmndr)
"Schoolbook division" (on half words) Complexity - O(x^2)
Definition: big_integer.cpp:182
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:140
void bi_div_mod(const BigInteger &left, const BigInteger &right, BigInteger *quotient, BigInteger *rmndr)
Adapted from Qrack! (The fundamental algorithm was discovered before.) Complexity - O(log)
Definition: big_integer.cpp:221
int GetDeviceCount()
Get the count of devices in the current list.
Definition: oclengine.hpp:316
static OCLEngine & Instance()
Get a pointer to the Instance of the singleton. (The instance will be instantiated,...
Definition: oclengine.hpp:270
Abstract QEngine implementation, for all "Schroedinger method" engines.
Definition: qengine.hpp:31
virtual void Copy(QInterfacePtr orig)
Copy this QInterface.
Definition: qinterface.hpp:222
virtual void ApplyM(const bitCapInt &qPower, bool result, const complex &nrm)
Definition: qengine.hpp:167
real1 runningNorm
The value stored in runningNorm should always be the total probability implied by the norm of all amp...
Definition: qengine.hpp:39
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
Definition: qinterface.hpp:2389
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:166
bitCapInt maxQPower
Definition: qinterface.hpp:149
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:275
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:477
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:371
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:268
bitLenInt qubitCount
Definition: qinterface.hpp:146
bool doNormalize
Definition: qinterface.hpp:143
Half-precision floating-point type.
Definition: half.hpp:2222
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
QInterfaceEngine
Enumerated list of supported engines.
Definition: qinterface.hpp:37
@ QINTERFACE_CUDA
Create a QEngineCUDA, leveraging CUDA hardware to increase the speed of certain calculations.
Definition: qinterface.hpp:52
@ QINTERFACE_OPENCL
Create a QEngineOCL, leveraging OpenCL hardware to increase the speed of certain calculations.
Definition: qinterface.hpp:47
@ QINTERFACE_CPU
Create a QEngineCPU leveraging only local CPU and memory resources.
Definition: qinterface.hpp:42
std::shared_ptr< QEngine > QEnginePtr
Definition: qrack_types.hpp:159
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:249
bitLenInt log2Ocl(bitCapIntOcl n)
Definition: qrack_functions.hpp:95
std::complex< real1 > complex
Definition: qrack_types.hpp:136
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:143
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:208
float real1_f
Definition: qrack_types.hpp:103
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:267
std::shared_ptr< QPager > QPagerPtr
Definition: qpager.hpp:24
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:186
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:138
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:144
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:185
#define bitLenInt
Definition: qrack_types.hpp:42
#define ZERO_R1_F
Definition: qrack_types.hpp:168
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:164
#define bitCapInt
Definition: qrack_types.hpp:66
#define bitCapIntOcl
Definition: qrack_types.hpp:54