19 #include "common/cudaengine.cuh"
31 class QPager :
public QEngine,
public std::enable_shared_from_this<QPager> {
77 template <
typename Qubit1Fn>
79 template <
typename Qubit1Fn>
81 Qubit1Fn fn,
const complex* mtrx,
bool isSqiCtrl =
false,
bool isIntraCtrled =
false);
82 template <
typename Qubit1Fn>
84 const bitCapInt& controlPerm, std::vector<bitLenInt> controls,
bitLenInt target, Qubit1Fn fn);
87 template <
typename F>
void CombineAndOp(F fn, std::vector<bitLenInt> bits);
105 bool ignored =
false,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
106 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devList = {},
111 int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
116 rgp, phaseFac, doNorm, ignored, useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh,
117 devList, qubitThreshold, separation_thresh)
120 rgp, phaseFac, doNorm, ignored, useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh,
121 devList, qubitThreshold, separation_thresh)
123 :
QPager({
QINTERFACE_CPU }, qBitCount, initState, rgp, phaseFac, doNorm, ignored, useHostMem, deviceId,
124 useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold, separation_thresh)
132 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
140 qPages[i]->SetConcurrency(threadsPerEngine);
170 qPages[i]->ZeroAmplitudes();
177 src->CombineEngines(qpp);
178 src->SeparateEngines(qpp,
true);
181 qPages[i]->CopyStateVec(src->qPages[i]);
204 SetAmplitudePage(std::dynamic_pointer_cast<QPager>(pageEnginePtr), srcOffset, dstOffset, length);
209 pageEnginePtr->CombineEngines();
210 qPages[0
U]->SetAmplitudePage(pageEnginePtr->qPages[0
U], srcOffset, dstOffset, length);
216 bitLenInt tcqpp = engine->qubitsPerPage();
217 engine->SeparateEngines(qpp,
true);
220 if (
qPages.size() == 1U) {
221 qPages[0
U]->ShuffleBuffers(engine->qPages[0
U]);
227 qPages[offset + i].swap(engine->qPages[i]);
244 return qPages[0
U]->ProbReg(start, length, permutation);
250 return qPages[0
U]->ApplyM(regMask, result, nrm);
255 return qPages[0
U]->GetExpectation(valueStart, valueLength);
261 qPages[0
U]->Apply2x2(offset1, offset2, mtrx, bitCount, qPowersSorted, doCalcNorm, norm_thresh);
267 toRet +=
qPages[i]->GetRunningNorm();
277 return qPages[i]->FirstNonzeroPhase();
349 bool ForceM(
bitLenInt qubit,
bool result,
bool doForce =
true,
bool doApply =
true);
374 const std::vector<bitLenInt>& controls);
376 const std::vector<bitLenInt>& controls);
378 bitLenInt length,
const std::vector<bitLenInt>& controls);
380 bitLenInt length,
const std::vector<bitLenInt>& controls);
382 bitLenInt length,
const std::vector<bitLenInt>& controls);
385 const unsigned char* values,
bool resetValue =
true);
387 bitLenInt carryIndex,
const unsigned char* values);
389 bitLenInt carryIndex,
const unsigned char* values);
411 return qPages[0
U]->ProbParity(mask);
420 return qPages[0
U]->ForceMParity(mask, result, doForce);
460 qPages[i]->SetDevice(dID);
463 #if ENABLE_OPENCL || ENABLE_CUDA
470 log2Ocl(CUDAEngine::Instance().GetDeviceContextPtr(
devID)->GetMaxAlloc() /
sizeof(
complex)) - 1U;
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:229
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:179
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:134
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:218
int GetDeviceCount()
Get the count of devices in the current list.
Definition: oclengine.hpp:294
static OCLEngine & Instance()
Get a pointer to the Instance of the singleton. (The instance will be instantiated,...
Definition: oclengine.hpp:250
Abstract QEngine implementation, for all "Schroedinger method" engines.
Definition: qengine.hpp:31
virtual void ApplyM(const bitCapInt &qPower, bool result, const complex &nrm)
Definition: qengine.hpp:154
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 FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)=0
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:167
bitCapInt maxQPower
Definition: qinterface.hpp:146
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:257
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:452
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:346
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:250
bitLenInt qubitCount
Definition: qinterface.hpp:143
bool doNormalize
Definition: qinterface.hpp:140
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:147
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:213
bitLenInt log2Ocl(bitCapIntOcl n)
Definition: qrack_functions.hpp:83
std::complex< real1 > complex
Definition: qrack_types.hpp:124
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:114
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:187
float real1_f
Definition: qrack_types.hpp:91
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:242
std::shared_ptr< QPager > QPagerPtr
Definition: qpager.hpp:24
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:170
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:126
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:115
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:169
#define bitLenInt
Definition: qrack_types.hpp:38
#define ZERO_R1_F
Definition: qrack_types.hpp:156
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:152
#define bitCapInt
Definition: qrack_types.hpp:62
#define bitCapIntOcl
Definition: qrack_types.hpp:50