19 #include "common/cudaengine.cuh"
31 class QPager :
public QEngine,
public std::enable_shared_from_this<QPager> {
72 template <
typename Qubit1Fn>
74 template <
typename Qubit1Fn>
76 const complex* mtrx,
bool isSqiCtrl =
false,
bool isIntraCtrled =
false);
77 template <
typename Qubit1Fn>
81 template <
typename F>
void CombineAndOp(F fn, std::vector<bitLenInt> bits);
97 bool ignored =
false,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
98 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devList = {},
103 int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
108 rgp, phaseFac, doNorm, ignored, useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh,
109 devList, qubitThreshold, separation_thresh)
112 rgp, phaseFac, doNorm, ignored, useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh,
113 devList, qubitThreshold, separation_thresh)
115 :
QPager({
QINTERFACE_CPU }, qBitCount, initState, rgp, phaseFac, doNorm, ignored, useHostMem, deviceId,
116 useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold, separation_thresh)
123 bool ignored2 =
false,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
124 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devList = {},
131 qPages[i]->SetConcurrency(threadsPerEngine);
160 qPages[i]->ZeroAmplitudes();
167 src->CombineEngines(qpp);
168 src->SeparateEngines(qpp,
true);
171 qPages[i]->CopyStateVec(src->qPages[i]);
194 SetAmplitudePage(std::dynamic_pointer_cast<QPager>(pageEnginePtr), srcOffset, dstOffset, length);
199 pageEnginePtr->CombineEngines();
200 qPages[0
U]->SetAmplitudePage(pageEnginePtr->qPages[0
U], srcOffset, dstOffset, length);
206 bitLenInt tcqpp = engine->qubitsPerPage();
207 engine->SeparateEngines(qpp,
true);
210 if (
qPages.size() == 1U) {
211 qPages[0
U]->ShuffleBuffers(engine->qPages[0
U]);
217 qPages[offset + i].swap(engine->qPages[i]);
234 return qPages[0
U]->ProbReg(start, length, permutation);
240 return qPages[0
U]->ApplyM(regMask, result, nrm);
245 return qPages[0
U]->GetExpectation(valueStart, valueLength);
251 qPages[0
U]->Apply2x2(offset1, offset2, mtrx, bitCount, qPowersSorted, doCalcNorm, norm_thresh);
257 toRet +=
qPages[i]->GetRunningNorm();
267 return qPages[i]->FirstNonzeroPhase();
281 return qPages[subIndex]->GetAmplitude(perm & (pmqp -
ONE_BCI));
287 qPages[subIndex]->SetAmplitude(perm & (pmqp -
ONE_BCI), amp);
337 bool ForceM(
bitLenInt qubit,
bool result,
bool doForce =
true,
bool doApply =
true);
357 const std::vector<bitLenInt>& controls);
359 const std::vector<bitLenInt>& controls);
361 const std::vector<bitLenInt>& controls);
363 const std::vector<bitLenInt>& controls);
365 const std::vector<bitLenInt>& controls);
368 const unsigned char* values,
bool resetValue =
true);
370 bitLenInt carryIndex,
const unsigned char* values);
372 bitLenInt carryIndex,
const unsigned char* values);
394 return qPages[0
U]->ProbParity(mask);
403 return qPages[0
U]->ForceMParity(mask, result, doForce);
444 qPages[i]->SetDevice(dID);
int GetDeviceCount()
Get the count of devices in the current list.
Definition: oclengine.hpp:292
static OCLEngine & Instance()
Get a pointer to the Instance of the singleton. (The instance will be instantiated,...
Definition: oclengine.hpp:248
Abstract QEngine implementation, for all "Schroedinger method" engines.
Definition: qengine.hpp:31
virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2)=0
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
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 Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Swap values of two bits in register.
Definition: gates.cpp:153
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void ApplyM(bitCapInt qPower, bool result, complex nrm)
Definition: qengine.hpp:154
bitCapInt maxQPower
Definition: qinterface.hpp:154
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:249
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:434
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:338
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:159
bitLenInt qubitCount
Definition: qinterface.hpp:151
bool doNormalize
Definition: qinterface.hpp:148
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
Definition: complex16x2simd.hpp:25
constexpr uint8_t ONE_BCI
Definition: qrack_types.hpp:90
std::complex< half_float::half > complex
Definition: qrack_types.hpp:62
QInterfaceEngine
Enumerated list of supported engines.
Definition: qinterface.hpp:50
@ QINTERFACE_CUDA
Create a QEngineCUDA, leveraging CUDA hardware to increase the speed of certain calculations.
Definition: qinterface.hpp:65
@ QINTERFACE_OPENCL
Create a QEngineOCL, leveraging OpenCL hardware to increase the speed of certain calculations.
Definition: qinterface.hpp:60
@ QINTERFACE_CPU
Create a QEngineCPU leveraging only local CPU and memory resources.
Definition: qinterface.hpp:55
std::shared_ptr< QEngine > QEnginePtr
Definition: qrack_types.hpp:141
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:28
constexpr real1_f ZERO_R1_F
Definition: qrack_types.hpp:152
constexpr real1_f FP_NORM_EPSILON_F
Definition: qrack_types.hpp:245
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:22
const real1 REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:155
const real1 PI_R1
Definition: qrack_types.hpp:158
float real1_f
Definition: qrack_types.hpp:64
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:242
std::shared_ptr< QPager > QPagerPtr
Definition: qpager.hpp:24
const real1 REAL1_EPSILON
Definition: qrack_types.hpp:157
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:23
bitLenInt log2(bitCapInt n)
Definition: qrack_functions.hpp:26
#define bitLenInt
Definition: qrack_types.hpp:44
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:146
#define bitCapInt
Definition: qrack_types.hpp:105
#define bitCapIntOcl
Definition: qrack_types.hpp:91