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 qPages[i]->SetConcurrency(threadsPerEngine);
192 qPages[i]->ZeroAmplitudes();
199 src->CombineEngines(qpp);
200 src->SeparateEngines(qpp,
true);
203 qPages[i]->CopyStateVec(src->qPages[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 qPages[0
U]->ShuffleBuffers(engine->qPages[0
U]);
249 qPages[offset + i].swap(engine->qPages[i]);
266 return qPages[0
U]->ProbReg(start, length, permutation);
272 return qPages[0
U]->ApplyM(regMask, result, nrm);
277 return qPages[0
U]->GetExpectation(valueStart, valueLength);
283 qPages[0
U]->Apply2x2(offset1, offset2, mtrx, bitCount, qPowersSorted, doCalcNorm, norm_thresh);
289 toRet +=
qPages[i]->GetRunningNorm();
299 return qPages[i]->FirstNonzeroPhase();
355 if (
qPages.size() == 1U) {
356 qPages[0
U]->MCMtrx(controls, mtrx, target);
365 if (
qPages.size() == 1U) {
366 qPages[0
U]->MACMtrx(controls, mtrx, target);
379 bool ForceM(
bitLenInt qubit,
bool result,
bool doForce =
true,
bool doApply =
true);
404 const std::vector<bitLenInt>& controls);
406 const std::vector<bitLenInt>& controls);
408 bitLenInt length,
const std::vector<bitLenInt>& controls);
410 bitLenInt length,
const std::vector<bitLenInt>& controls);
412 bitLenInt length,
const std::vector<bitLenInt>& controls);
415 const unsigned char* values,
bool resetValue =
true);
417 bitLenInt carryIndex,
const unsigned char* values);
419 bitLenInt carryIndex,
const unsigned char* values);
441 return qPages[0
U]->ProbParity(mask);
450 return qPages[0
U]->ForceMParity(mask, result, doForce);
491 qPages[i]->SetDevice(dID);
494 #if ENABLE_OPENCL || ENABLE_CUDA
501 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 Copy(QInterfacePtr orig)
Copy this QInterface.
Definition: qinterface.hpp:222
virtual void ApplyM(const bitCapInt &qPower, bool result, const complex &nrm)
Definition: qengine.hpp:165
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: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:470
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:364
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:151
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:235
bitLenInt log2Ocl(bitCapIntOcl n)
Definition: qrack_functions.hpp:88
std::complex< real1 > complex
Definition: qrack_types.hpp:128
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:136
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:200
float real1_f
Definition: qrack_types.hpp:95
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:257
std::shared_ptr< QPager > QPagerPtr
Definition: qpager.hpp:24
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:178
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:130
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:137
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:177
#define bitLenInt
Definition: qrack_types.hpp:38
#define ZERO_R1_F
Definition: qrack_types.hpp:160
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:156
#define bitCapInt
Definition: qrack_types.hpp:62
#define bitCapIntOcl
Definition: qrack_types.hpp:50