Qrack  3.1
General classical-emulating-quantum development framework
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Qrack::QEngineOCL Class Reference

OpenCL enhanced QEngineCPU implementation. More...

#include <qengine_opencl.hpp>

Inheritance diagram for Qrack::QEngineOCL:
Inheritance graph
[legend]
Collaboration diagram for Qrack::QEngineOCL:
Collaboration graph
[legend]

Public Member Functions

 QEngineOCL (bitLenInt qBitCount, bitCapInt initState, qrack_rand_gen_ptr rgp=nullptr, complex phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int devID=-1, bool useHardwareRNG=true, bool ignored=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int > ignored2={}, bitLenInt ignored3=0)
 Initialize a Qrack::QEngineOCL object. More...
 
virtual ~QEngineOCL ()
 
virtual void ZeroAmplitudes ()
 
virtual void SetQubitCount (bitLenInt qb)
 
virtual void FreeStateVec (complex *sv=NULL)
 
virtual bool IsZeroAmplitude ()
 
virtual void CopyStateVec (QEnginePtr src)
 
virtual void GetAmplitudePage (complex *pagePtr, const bitCapInt offset, const bitCapInt length)
 
virtual void SetAmplitudePage (const complex *pagePtr, const bitCapInt offset, const bitCapInt length)
 
virtual void SetAmplitudePage (QEnginePtr pageEnginePtr, const bitCapInt srcOffset, const bitCapInt dstOffset, const bitCapInt length)
 
virtual void ShuffleBuffers (QEnginePtr engine)
 Swap the high half of this engine with the low half of another. More...
 
virtual void QueueSetDoNormalize (const bool &doNorm)
 
virtual void QueueSetRunningNorm (const real1_f &runningNrm)
 
virtual void AddQueueItem (const QueueItem &item)
 
virtual void QueueCall (OCLAPI api_call, size_t workItemCount, size_t localGroupSize, std::vector< BufferPtr > args, size_t localBuffSize=0)
 
bitCapIntOcl GetMaxSize ()
 
virtual void SetPermutation (bitCapInt perm, complex phaseFac=CMPLX_DEFAULT_ARG)
 Set to a specific permutation. More...
 
virtual real1_f ProbAll (bitCapInt fullRegister)
 Direct measure of full permutation probability. More...
 
virtual void UniformlyControlledSingleBit (const bitLenInt *controls, const bitLenInt &controlLen, bitLenInt qubitIndex, const complex *mtrxs, const bitCapInt *mtrxSkipPowers, const bitLenInt mtrxSkipLen, const bitCapInt &mtrxSkipValueMask)
 
virtual void UniformParityRZ (const bitCapInt &mask, const real1_f &angle)
 If the target qubit set parity is odd, this applies a phase factor of e^{i angle}. More...
 
virtual void CUniformParityRZ (const bitLenInt *controls, const bitLenInt &controlLen, const bitCapInt &mask, const real1_f &angle)
 If the controls are set and the target qubit set parity is odd, this applies a phase factor of e^{i angle}. More...
 
virtual void X (bitLenInt target)
 NOT gate, which is also Pauli x matrix. More...
 
virtual void Z (bitLenInt target)
 Apply Pauli Z matrix to bit. More...
 
virtual void ApplySingleInvert (const complex topRight, const complex bottomLeft, bitLenInt qubitIndex)
 Apply a single bit transformation that reverses bit probability and might effect phase. More...
 
virtual void ApplySinglePhase (const complex topLeft, const complex bottomRight, bitLenInt qubitIndex)
 Apply a single bit transformation that only effects phase. More...
 
virtual bitLenInt Compose (QEngineOCLPtr toCopy)
 
virtual bitLenInt Compose (QInterfacePtr toCopy)
 Combine another QInterface with this one, after the last bit index of this one. More...
 
virtual bitLenInt Compose (QEngineOCLPtr toCopy, bitLenInt start)
 
virtual bitLenInt Compose (QInterfacePtr toCopy, bitLenInt start)
 
virtual void Decompose (bitLenInt start, QInterfacePtr dest)
 Minimally decompose a set of contiguous bits from the separably composed unit, into "destination". More...
 
virtual void Dispose (bitLenInt start, bitLenInt length)
 Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separable bits from index "start" for "length.". More...
 
virtual void Dispose (bitLenInt start, bitLenInt length, bitCapInt disposedPerm)
 Dispose a a contiguous set of qubits that are already in a permutation eigenstate. More...
 
virtual void ROL (bitLenInt shift, bitLenInt start, bitLenInt length)
 "Circular shift left" - shift bits left, and carry last bits. More...
 
virtual void INC (bitCapInt toAdd, bitLenInt start, bitLenInt length)
 Increment integer (without sign, with carry) More...
 
virtual void CINC (bitCapInt toAdd, bitLenInt inOutStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Add integer (without sign, with controls) More...
 
virtual void INCS (bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
 Increment integer (without sign, with carry) More...
 
virtual void MUL (bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
 Multiply by integer. More...
 
virtual void DIV (bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
 Divide by integer. More...
 
virtual void MULModNOut (bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
 Multiplication modulo N by integer, (out of place) More...
 
virtual void IMULModNOut (bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
 Inverse: multiplication modulo N by integer, (out of place) More...
 
virtual void POWModNOut (bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
 Raise a classical base to a quantum power, modulo N, (out of place) More...
 
virtual void CMUL (bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Controlled multiplication by integer. More...
 
virtual void CDIV (bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Controlled division by integer. More...
 
virtual void CMULModNOut (bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Controlled multiplication modulo N by integer, (out of place) More...
 
virtual void CIMULModNOut (bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Inverse: controlled multiplication modulo N by integer, (out of place) More...
 
virtual void CPOWModNOut (bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Controlled multiplication modulo N by integer, (out of place) More...
 
virtual void FullAdd (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
 Quantum analog of classical "Full Adder" gate. More...
 
virtual void IFullAdd (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
 Inverse of FullAdd. More...
 
virtual bitCapInt IndexedLDA (bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, unsigned char *values, bool resetValue=true)
 Set 8 bit register bits based on read from classical memory. More...
 
virtual bitCapInt IndexedADC (bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, unsigned char *values)
 Add based on an indexed load from classical memory. More...
 
virtual bitCapInt IndexedSBC (bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, unsigned char *values)
 Subtract based on an indexed load from classical memory. More...
 
virtual void Hash (bitLenInt start, bitLenInt length, unsigned char *values)
 Set 8 bit register bits based on read from classical memory. More...
 
virtual real1_f Prob (bitLenInt qubit)
 PSEUDO-QUANTUM Direct measure of bit probability to be in |1> state. More...
 
virtual real1_f ProbReg (const bitLenInt &start, const bitLenInt &length, const bitCapInt &permutation)
 Direct measure of register permutation probability. More...
 
virtual void ProbRegAll (const bitLenInt &start, const bitLenInt &length, real1 *probsArray)
 
virtual real1_f ProbMask (const bitCapInt &mask, const bitCapInt &permutation)
 Direct measure of masked permutation probability. More...
 
virtual void ProbMaskAll (const bitCapInt &mask, real1 *probsArray)
 Direct measure of masked permutation probability. More...
 
virtual real1_f ProbParity (const bitCapInt &mask)
 Overall probability of any odd permutation of the masked set of bits. More...
 
virtual bool ForceMParity (const bitCapInt &mask, bool result, bool doForce=true)
 Act as if is a measurement of parity of the masked set of qubits was applied, except force the (usually random) result. More...
 
virtual void CPhaseFlipIfLess (bitCapInt greaterPerm, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
 The 6502 uses its carry flag also as a greater-than/less-than flag, for the CMP operation. More...
 
virtual void PhaseFlipIfLess (bitCapInt greaterPerm, bitLenInt start, bitLenInt length)
 This is an expedient for an adaptive Grover's search for a function's global minimum. More...
 
virtual void SetDevice (const int &dID, const bool &forceReInit=false)
 Set the device index, if more than one device is available. More...
 
virtual int GetDeviceID ()
 Get the device index. More...
 
virtual void SetQuantumState (const complex *inputState)
 Set arbitrary pure quantum state, in unsigned int permutation basis. More...
 
virtual void GetQuantumState (complex *outputState)
 Get pure quantum state, in unsigned int permutation basis. More...
 
virtual void GetProbs (real1 *outputProbs)
 Get all probabilities, in unsigned int permutation basis. More...
 
virtual complex GetAmplitude (bitCapInt perm)
 Get the representational amplitude of a full permutation. More...
 
virtual void SetAmplitude (bitCapInt perm, complex amp)
 Sets the representational amplitude of a full permutation. More...
 
virtual real1_f SumSqrDiff (QInterfacePtr toCompare)
 
virtual real1_f SumSqrDiff (QEngineOCLPtr toCompare)
 
virtual void NormalizeState (real1_f nrm=REAL1_DEFAULT_ARG, real1_f norm_thresh=REAL1_DEFAULT_ARG)
 Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate. More...
 
virtual void UpdateRunningNorm (real1_f norm_thresh=REAL1_DEFAULT_ARG)
 Force a calculation of the norm of the state vector, in order to make it unit length before the next probability or measurement operation. More...
 
virtual void Finish ()
 If asynchronous work is still running, block until it finishes. More...
 
virtual bool isFinished ()
 Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynchronous work is done. More...
 
virtual QInterfacePtr Clone ()
 Clone this QInterface. More...
 
void PopQueue (cl_event event, cl_int type)
 
void DispatchQueue (cl_event event, cl_int type)
 
- Public Member Functions inherited from Qrack::QEngine
 QEngine (bitLenInt qBitCount, qrack_rand_gen_ptr rgp=nullptr, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, bool useHardwareRNG=true, real1_f norm_thresh=REAL1_EPSILON)
 
 QEngine ()
 
virtual ~QEngine ()
 
virtual real1_f GetRunningNorm ()
 
virtual bool ForceM (bitLenInt qubitIndex, bool result, bool doForce=true, bool doApply=true)
 PSEUDO-QUANTUM - Acts like a measurement gate, except with a specified forced result. More...
 
virtual bitCapInt ForceM (const bitLenInt *bits, const bitLenInt &length, const bool *values, bool doApply=true)
 Measure permutation state of a register. More...
 
virtual bitCapInt ForceMReg (bitLenInt start, bitLenInt length, bitCapInt result, bool doForce=true, bool doApply=true)
 Measure permutation state of a register. More...
 
virtual void ApplySingleBit (const complex *mtrx, bitLenInt qubit)
 Apply an arbitrary single bit unitary transformation. More...
 
virtual void ApplyControlledSingleBit (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex *mtrx)
 Apply an arbitrary single bit unitary transformation, with arbitrary control bits. More...
 
virtual void ApplyAntiControlledSingleBit (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex *mtrx)
 Apply an arbitrary single bit unitary transformation, with arbitrary (anti-)control bits. More...
 
virtual void CSwap (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &qubit1, const bitLenInt &qubit2)
 Apply a swap with arbitrary control bits. More...
 
virtual void AntiCSwap (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &qubit1, const bitLenInt &qubit2)
 Apply a swap with arbitrary (anti) control bits. More...
 
virtual void CSqrtSwap (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &qubit1, const bitLenInt &qubit2)
 Apply a square root of swap with arbitrary control bits. More...
 
virtual void AntiCSqrtSwap (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &qubit1, const bitLenInt &qubit2)
 Apply a square root of swap with arbitrary (anti) control bits. More...
 
virtual void CISqrtSwap (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &qubit1, const bitLenInt &qubit2)
 Apply an inverse square root of swap with arbitrary control bits. More...
 
virtual void AntiCISqrtSwap (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &qubit1, const bitLenInt &qubit2)
 Apply an inverse square root of swap with arbitrary (anti) control bits. More...
 
virtual void Swap (bitLenInt qubit1, bitLenInt qubit2)
 Swap values of two bits in register. More...
 
virtual void ISwap (bitLenInt qubit1, bitLenInt qubit2)
 Swap values of two bits in register, applying a phase factor of i if bits are different. More...
 
virtual void SqrtSwap (bitLenInt qubit1, bitLenInt qubit2)
 Square root of swap gate. More...
 
virtual void ISqrtSwap (bitLenInt qubit1, bitLenInt qubit2)
 Inverse of square root of swap gate. More...
 
virtual void FSim (real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2)
 "fSim" gate, (useful in the simulation of particles with fermionic statistics) More...
 
virtual void INCC (bitCapInt toAdd, const bitLenInt inOutStart, const bitLenInt length, const bitLenInt carryIndex)
 Add integer (without sign, with carry) More...
 
virtual void DECC (bitCapInt toSub, const bitLenInt inOutStart, const bitLenInt length, const bitLenInt carryIndex)
 Subtract integer (without sign, with carry) More...
 
virtual void INCSC (bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
 Add an integer to the register, with sign and with carry. More...
 
virtual void DECSC (bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
 Subtract an integer from the register, with sign and with carry. More...
 
virtual void INCSC (bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
 Add an integer to the register, with sign and with carry. More...
 
virtual void DECSC (bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
 Subtract an integer from the register, with sign and with carry. More...
 
virtual void ApplyControlled2x2 (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex *mtrx)
 
virtual void ApplyAntiControlled2x2 (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex *mtrx)
 
- Public Member Functions inherited from Qrack::QInterface
 QInterface (bitLenInt n, qrack_rand_gen_ptr rgp=nullptr, bool doNorm=false, bool useHardwareRNG=true, bool randomGlobalPhase=true, real1_f norm_thresh=REAL1_EPSILON)
 
 QInterface ()
 
virtual ~QInterface ()
 
virtual void SetRandomSeed (uint32_t seed)
 
virtual void SetConcurrency (uint32_t threadsPerEngine)
 Set the number of threads in parallel for loops, per component QEngine. More...
 
bitLenInt GetQubitCount ()
 Get the count of bits in this register. More...
 
bitCapInt GetMaxQPower ()
 Get the maximum number of basis states, namely \( n^2 \) for \( n \) qubits. More...
 
real1_f Rand ()
 Generate a random real number between 0 and 1. More...
 
virtual std::map< QInterfacePtr, bitLenIntCompose (std::vector< QInterfacePtr > toCopy)
 
virtual void ApplyControlledSinglePhase (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex topLeft, const complex bottomRight)
 Apply a single bit transformation that only effects phase, with arbitrary control bits. More...
 
virtual void ApplyControlledSingleInvert (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex topRight, const complex bottomLeft)
 Apply a single bit transformation that reverses bit probability and might effect phase, with arbitrary control bits. More...
 
virtual void ApplyAntiControlledSinglePhase (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex topLeft, const complex bottomRight)
 Apply a single bit transformation that only effects phase, with arbitrary (anti-)control bits. More...
 
virtual void ApplyAntiControlledSingleInvert (const bitLenInt *controls, const bitLenInt &controlLen, const bitLenInt &target, const complex topRight, const complex bottomLeft)
 Apply a single bit transformation that reverses bit probability and might effect phase, with arbitrary (anti-)control bits. More...
 
virtual void UniformlyControlledSingleBit (const bitLenInt *controls, const bitLenInt &controlLen, bitLenInt qubitIndex, const complex *mtrxs)
 Apply a "uniformly controlled" arbitrary single bit unitary transformation. More...
 
virtual void TimeEvolve (Hamiltonian h, real1_f timeDiff)
 To define a Hamiltonian, give a vector of controlled single bit gates ("HamiltonianOp" instances) that are applied by left-multiplication in low-to-high vector index order on the state vector. More...
 
virtual void CCNOT (bitLenInt control1, bitLenInt control2, bitLenInt target)
 Doubly-controlled NOT gate. More...
 
virtual void AntiCCNOT (bitLenInt control1, bitLenInt control2, bitLenInt target)
 Anti doubly-controlled NOT gate. More...
 
virtual void CNOT (bitLenInt control, bitLenInt target)
 Controlled NOT gate. More...
 
virtual void AntiCNOT (bitLenInt control, bitLenInt target)
 Anti controlled NOT gate. More...
 
virtual void U (bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
 General unitary gate. More...
 
virtual void U2 (bitLenInt target, real1_f phi, real1_f lambda)
 2-parameter unitary gate More...
 
virtual void CU (bitLenInt *controls, bitLenInt controlLen, bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
 Controlled general unitary gate. More...
 
virtual void H (bitLenInt qubitIndex)
 Hadamard gate. More...
 
virtual void SqrtH (bitLenInt qubitIndex)
 Square root of Hadamard gate. More...
 
virtual void SH (bitLenInt qubitIndex)
 Y-basis transformation gate. More...
 
virtual void HIS (bitLenInt qubitIndex)
 Y-basis (inverse) transformation gate. More...
 
virtual bool M (bitLenInt qubitIndex)
 Measurement gate. More...
 
virtual bool MParity (const bitCapInt &mask)
 Measure (and collapse) parity of the masked set of qubits. More...
 
virtual void S (bitLenInt qubitIndex)
 S gate. More...
 
virtual void IS (bitLenInt qubitIndex)
 Inverse S gate. More...
 
virtual void T (bitLenInt qubitIndex)
 T gate. More...
 
virtual void IT (bitLenInt qubitIndex)
 Inverse T gate. More...
 
virtual void PhaseRootN (bitLenInt n, bitLenInt qubitIndex)
 "PhaseRootN" gate More...
 
virtual void IPhaseRootN (bitLenInt n, bitLenInt qubitIndex)
 Inverse "PhaseRootN" gate. More...
 
virtual void Y (bitLenInt qubitIndex)
 Y gate. More...
 
virtual void SqrtX (bitLenInt qubitIndex)
 Square root of X gate. More...
 
virtual void ISqrtX (bitLenInt qubitIndex)
 Inverse square root of X gate. More...
 
virtual void SqrtXConjT (bitLenInt qubitIndex)
 Phased square root of X gate. More...
 
virtual void ISqrtXConjT (bitLenInt qubitIndex)
 Inverse phased square root of X gate. More...
 
virtual void SqrtY (bitLenInt qubitIndex)
 Square root of Y gate. More...
 
virtual void ISqrtY (bitLenInt qubitIndex)
 Square root of Y gate. More...
 
virtual void CY (bitLenInt control, bitLenInt target)
 Controlled Y gate. More...
 
virtual void CZ (bitLenInt control, bitLenInt target)
 Controlled Z gate. More...
 
virtual void CCZ (bitLenInt control1, bitLenInt control2, bitLenInt target)
 Doubly-Controlled Z gate. More...
 
virtual void CH (bitLenInt control, bitLenInt target)
 Controlled H gate. More...
 
virtual void CS (bitLenInt control, bitLenInt target)
 Controlled S gate. More...
 
virtual void CIS (bitLenInt control, bitLenInt target)
 Controlled inverse S gate. More...
 
virtual void CT (bitLenInt control, bitLenInt target)
 Controlled T gate. More...
 
virtual void CIT (bitLenInt control, bitLenInt target)
 Controlled inverse T gate. More...
 
virtual void CPhaseRootN (bitLenInt n, bitLenInt control, bitLenInt target)
 Controlled "PhaseRootN" gate. More...
 
virtual void CIPhaseRootN (bitLenInt n, bitLenInt control, bitLenInt target)
 Controlled inverse "PhaseRootN" gate. More...
 
virtual void AND (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
 Quantum analog of classical "AND" gate. More...
 
virtual void OR (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
 Quantum analog of classical "OR" gate. More...
 
virtual void XOR (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
 Quantum analog of classical "XOR" gate. More...
 
virtual void CLAND (bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
 Quantum analog of classical "AND" gate. More...
 
virtual void CLOR (bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
 Quantum analog of classical "OR" gate. More...
 
virtual void CLXOR (bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
 Quantum analog of classical "XOR" gate. More...
 
virtual void NAND (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
 Quantum analog of classical "NAND" gate. More...
 
virtual void NOR (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
 Quantum analog of classical "NOR" gate. More...
 
virtual void XNOR (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
 Quantum analog of classical "XNOR" gate. More...
 
virtual void CLNAND (bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
 Quantum analog of classical "NAND" gate. More...
 
virtual void CLNOR (bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
 Quantum analog of classical "NOR" gate. More...
 
virtual void CLXNOR (bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
 Quantum analog of classical "XNOR" gate. More...
 
virtual void RT (real1_f radians, bitLenInt qubitIndex)
 Phase shift gate. More...
 
virtual void RTDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction phase shift gate. More...
 
virtual void RX (real1_f radians, bitLenInt qubitIndex)
 X axis rotation gate. More...
 
virtual void RXDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction X axis rotation gate. More...
 
virtual void Exp (real1_f radians, bitLenInt qubitIndex)
 (Identity) Exponentiation gate More...
 
virtual void Exp (bitLenInt *controls, bitLenInt controlLen, bitLenInt qubit, complex *matrix2x2, bool antiCtrled=false)
 Imaginary exponentiation of arbitrary 2x2 gate. More...
 
virtual void ExpDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction (identity) exponentiation gate. More...
 
virtual void ExpX (real1_f radians, bitLenInt qubitIndex)
 Pauli X exponentiation gate. More...
 
virtual void ExpXDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction Pauli X exponentiation gate. More...
 
virtual void ExpY (real1_f radians, bitLenInt qubitIndex)
 Pauli Y exponentiation gate. More...
 
virtual void ExpYDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction Pauli Y exponentiation gate. More...
 
virtual void ExpZ (real1_f radians, bitLenInt qubitIndex)
 Pauli Z exponentiation gate. More...
 
virtual void ExpZDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction Pauli Z exponentiation gate. More...
 
virtual void CRX (real1_f radians, bitLenInt control, bitLenInt target)
 Controlled X axis rotation gate. More...
 
virtual void CRXDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target)
 Controlled dyadic fraction X axis rotation gate. More...
 
virtual void RY (real1_f radians, bitLenInt qubitIndex)
 Y axis rotation gate. More...
 
virtual void RYDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction Y axis rotation gate. More...
 
virtual void CRY (real1_f radians, bitLenInt control, bitLenInt target)
 Controlled Y axis rotation gate. More...
 
virtual void CRYDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target)
 Controlled dyadic fraction y axis rotation gate. More...
 
virtual void UniformlyControlledRY (const bitLenInt *controls, const bitLenInt &controlLen, bitLenInt qubitIndex, const real1 *angles)
 Apply a "uniformly controlled" rotation of a bit around the Pauli Y axis. More...
 
virtual void UniformlyControlledRZ (const bitLenInt *controls, const bitLenInt &controlLen, bitLenInt qubitIndex, const real1 *angles)
 Apply a "uniformly controlled" rotation of a bit around the Pauli Z axis. More...
 
virtual void RZ (real1_f radians, bitLenInt qubitIndex)
 Z axis rotation gate. More...
 
virtual void RZDyad (int numerator, int denomPower, bitLenInt qubitIndex)
 Dyadic fraction Z axis rotation gate. More...
 
virtual void CRZ (real1_f radians, bitLenInt control, bitLenInt target)
 Controlled Z axis rotation gate. More...
 
virtual void CRZDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target)
 Controlled dyadic fraction Z axis rotation gate. More...
 
virtual void CRT (real1_f radians, bitLenInt control, bitLenInt target)
 Controlled "phase shift gate". More...
 
virtual void CRTDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target)
 Controlled dyadic fraction "phase shift gate". More...
 
virtual void U (bitLenInt start, bitLenInt length, real1_f theta, real1_f phi, real1_f lambda)
 Bitwise general unitary. More...
 
virtual void U2 (bitLenInt start, bitLenInt length, real1_f phi, real1_f lambda)
 Bitwise 2-parameter unitary. More...
 
virtual void H (bitLenInt start, bitLenInt length)
 Bitwise Hadamard. More...
 
virtual void SH (bitLenInt start, bitLenInt length)
 Bitwise Y-basis transformation gate. More...
 
virtual void HIS (bitLenInt start, bitLenInt length)
 Bitwise inverse Y-basis transformation gate. More...
 
virtual void SqrtH (bitLenInt start, bitLenInt length)
 Bitwise square root of Hadamard. More...
 
virtual void S (bitLenInt start, bitLenInt length)
 Bitwise S operator (1/4 phase rotation) More...
 
virtual void IS (bitLenInt start, bitLenInt length)
 Bitwise inverse S operator (1/4 phase rotation) More...
 
virtual void T (bitLenInt start, bitLenInt length)
 Bitwise T operator (1/8 phase rotation) More...
 
virtual void IT (bitLenInt start, bitLenInt length)
 Bitwise inverse T operator (1/8 phase rotation) More...
 
virtual void PhaseRootN (bitLenInt n, bitLenInt start, bitLenInt length)
 Bitwise "PhaseRootN" operator (1/(2^N) phase rotation) More...
 
virtual void IPhaseRootN (bitLenInt n, bitLenInt start, bitLenInt length)
 Bitwise inverse "PhaseRootN" operator (1/(2^N) phase rotation) More...
 
virtual void X (bitLenInt start, bitLenInt length)
 Bitwise Pauli X (or logical "NOT") operator. More...
 
virtual void Y (bitLenInt start, bitLenInt length)
 Bitwise Pauli Y operator. More...
 
virtual void SqrtX (bitLenInt start, bitLenInt length)
 Bitwise square root of Pauli X operator. More...
 
virtual void ISqrtX (bitLenInt start, bitLenInt length)
 Bitwise inverse square root of Pauli X operator. More...
 
virtual void SqrtXConjT (bitLenInt start, bitLenInt length)
 Bitwise phased square root of Pauli X operator. More...
 
virtual void ISqrtXConjT (bitLenInt start, bitLenInt length)
 Bitwise inverse phased square root of Pauli X operator. More...
 
virtual void SqrtY (bitLenInt start, bitLenInt length)
 Bitwise square root of Pauli Y operator. More...
 
virtual void ISqrtY (bitLenInt start, bitLenInt length)
 Bitwise inverse square root of Pauli Y operator. More...
 
virtual void Z (bitLenInt start, bitLenInt length)
 Bitwise Pauli Z operator. More...
 
virtual void CNOT (bitLenInt inputBits, bitLenInt targetBits, bitLenInt length)
 Bitwise controlled-not. More...
 
virtual void AntiCNOT (bitLenInt inputBits, bitLenInt targetBits, bitLenInt length)
 Bitwise "anti-"controlled-not. More...
 
virtual void CCNOT (bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length)
 Bitwise doubly controlled-not. More...
 
virtual void AntiCCNOT (bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length)
 Bitwise doubly "anti-"controlled-not. More...
 
virtual void AND (bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)
 Bitwise "AND". More...
 
virtual void CLAND (bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)
 Classical bitwise "AND". More...
 
virtual void OR (bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)
 Bitwise "OR". More...
 
virtual void CLOR (bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)
 Classical bitwise "OR". More...
 
virtual void XOR (bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)
 Bitwise "XOR". More...
 
virtual void CLXOR (bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)
 Classical bitwise "XOR". More...
 
virtual void NAND (bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)
 Bitwise "NAND". More...
 
virtual void CLNAND (bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)
 Classical bitwise "NAND". More...
 
virtual void NOR (bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)
 Bitwise "NOR". More...
 
virtual void CLNOR (bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)
 Classical bitwise "NOR". More...
 
virtual void XNOR (bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)
 Bitwise "XNOR". More...
 
virtual void CLXNOR (bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)
 Classical bitwise "XNOR". More...
 
virtual void RT (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise phase shift gate. More...
 
virtual void RTDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise dyadic fraction phase shift gate. More...
 
virtual void RX (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise X axis rotation gate. More...
 
virtual void RXDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise dyadic fraction X axis rotation gate. More...
 
virtual void CRX (real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled X axis rotation gate. More...
 
virtual void CRXDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled dyadic fraction X axis rotation gate. More...
 
virtual void RY (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise Y axis rotation gate. More...
 
virtual void RYDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise dyadic fraction Y axis rotation gate. More...
 
virtual void CRY (real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled Y axis rotation gate. More...
 
virtual void CRYDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled dyadic fraction y axis rotation gate. More...
 
virtual void RZ (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise Z axis rotation gate. More...
 
virtual void RZDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise dyadic fraction Z axis rotation gate. More...
 
virtual void CRZ (real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled Z axis rotation gate. More...
 
virtual void CRZDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled dyadic fraction Z axis rotation gate. More...
 
virtual void CRT (real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled "phase shift gate". More...
 
virtual void CRTDyad (int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled dyadic fraction "phase shift gate". More...
 
virtual void Exp (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise (identity) exponentiation gate. More...
 
virtual void ExpDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise Dyadic fraction (identity) exponentiation gate. More...
 
virtual void ExpX (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise Pauli X exponentiation gate. More...
 
virtual void ExpXDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise Dyadic fraction Pauli X exponentiation gate. More...
 
virtual void ExpY (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise Pauli Y exponentiation gate. More...
 
virtual void ExpYDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise Dyadic fraction Pauli Y exponentiation gate. More...
 
virtual void ExpZ (real1_f radians, bitLenInt start, bitLenInt length)
 Bitwise Pauli Z exponentiation gate. More...
 
virtual void ExpZDyad (int numerator, int denomPower, bitLenInt start, bitLenInt length)
 Bitwise Dyadic fraction Pauli Z exponentiation gate. More...
 
virtual void CY (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled Y gate. More...
 
virtual void CZ (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled Z gate. More...
 
virtual void CCZ (bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length)
 Bitwise doubly-controlled Z gate. More...
 
virtual void CH (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled H gate. More...
 
virtual void CS (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled S gate. More...
 
virtual void CIS (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled inverse S gate. More...
 
virtual void CT (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled T gate. More...
 
virtual void CIT (bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled inverse T gate. More...
 
virtual void CPhaseRootN (bitLenInt n, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled "PhaseRootN" gate. More...
 
virtual void CIPhaseRootN (bitLenInt n, bitLenInt control, bitLenInt target, bitLenInt length)
 Bitwise controlled inverse "PhaseRootN" gate. More...
 
virtual void ASL (bitLenInt shift, bitLenInt start, bitLenInt length)
 Arithmetic shift left, with last 2 bits as sign and carry. More...
 
virtual void ASR (bitLenInt shift, bitLenInt start, bitLenInt length)
 Arithmetic shift right, with last 2 bits as sign and carry. More...
 
virtual void LSL (bitLenInt shift, bitLenInt start, bitLenInt length)
 Logical shift left, filling the extra bits with |0> More...
 
virtual void LSR (bitLenInt shift, bitLenInt start, bitLenInt length)
 Logical shift right, filling the extra bits with |0> More...
 
virtual void ROR (bitLenInt shift, bitLenInt start, bitLenInt length)
 Circular shift right - shift bits right, and carry first bits. More...
 
virtual void DEC (bitCapInt toSub, bitLenInt start, bitLenInt length)
 Subtract classical integer (without sign) More...
 
virtual void CDEC (bitCapInt toSub, bitLenInt inOutStart, bitLenInt length, bitLenInt *controls, bitLenInt controlLen)
 Subtract classical integer (without sign, with controls) More...
 
virtual void DECS (bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
 Subtract a classical integer from the register, with sign and without carry. More...
 
virtual void CFullAdd (bitLenInt *controls, bitLenInt controlLen, bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
 Controlled quantum analog of classical "Full Adder" gate. More...
 
virtual void CIFullAdd (bitLenInt *controls, bitLenInt controlLen, bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
 Inverse of CFullAdd. More...
 
virtual void ADC (bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
 Add a quantum integer to a quantum integer, with carry. More...
 
virtual void IADC (bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
 Inverse of ADC. More...
 
virtual void CADC (bitLenInt *controls, bitLenInt controlLen, bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
 Add a quantum integer to a quantum integer, with carry and with controls. More...
 
virtual void CIADC (bitLenInt *controls, bitLenInt controlLen, bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
 Inverse of CADC. More...
 
virtual void QFT (bitLenInt start, bitLenInt length, bool trySeparate=false)
 Quantum Fourier Transform - Apply the quantum Fourier transform to the register. More...
 
virtual void IQFT (bitLenInt start, bitLenInt length, bool trySeparate=false)
 Inverse Quantum Fourier Transform - Apply the inverse quantum Fourier transform to the register. More...
 
virtual void ZeroPhaseFlip (bitLenInt start, bitLenInt length)
 Reverse the phase of the state where the register equals zero. More...
 
virtual void PhaseFlip ()
 Phase flip always - equivalent to Z X Z X on any bit in the QInterface. More...
 
virtual void SetReg (bitLenInt start, bitLenInt length, bitCapInt value)
 Set register bits to given permutation. More...
 
virtual bitCapInt MReg (bitLenInt start, bitLenInt length)
 Measure permutation state of a register. More...
 
virtual bitCapInt MAll ()
 Measure permutation state of all coherent bits. More...
 
virtual bitCapInt M (const bitLenInt *bits, const bitLenInt &length)
 Measure bits with indices in array, and return a mask of the results. More...
 
virtual void Swap (bitLenInt start1, bitLenInt start2, bitLenInt length)
 Bitwise swap. More...
 
virtual void ISwap (bitLenInt start1, bitLenInt start2, bitLenInt length)
 Bitwise swap. More...
 
virtual void SqrtSwap (bitLenInt start1, bitLenInt start2, bitLenInt length)
 Bitwise square root of swap. More...
 
virtual void ISqrtSwap (bitLenInt start1, bitLenInt start2, bitLenInt length)
 Bitwise inverse square root of swap. More...
 
virtual void FSim (real1_f theta, real1_f phi, bitLenInt start1, bitLenInt start2, bitLenInt length)
 Bitwise "fSim". More...
 
virtual void Reverse (bitLenInt first, bitLenInt last)
 Reverse all of the bits in a sequence. More...
 
virtual std::map< bitCapInt, int > MultiShotMeasureMask (const bitCapInt *qPowers, const bitLenInt qPowerCount, const unsigned int shots)
 Statistical measure of masked permutation probability. More...
 
virtual void SetBit (bitLenInt qubitIndex1, bool value)
 Set individual bit to pure |0> (false) or |1> (true) state. More...
 
virtual bool ApproxCompare (QInterfacePtr toCompare, real1_f error_tol=REAL1_EPSILON)
 Compare state vectors approximately, component by component, to determine whether this state vector is the same as the target. More...
 
virtual bool TryDecompose (bitLenInt start, QInterfacePtr dest, real1_f error_tol=REAL1_EPSILON)
 
virtual bool isClifford ()
 Returns "true" if current state is identifiably within the Clifford set, or "false" if it is not or cannot be determined. More...
 
virtual bool TrySeparate (bitLenInt start, bitLenInt length=1, real1_f error_tol=REAL1_EPSILON)
 Qrack::QUnit types maintain explicit separation of representations of qubits, which reduces memory usage and increases gate speed. More...
 
bitCapIntOcl GetMaxSize ()
 Get maximum number of amplitudes that can be allocated on current device. More...
 

Static Public Attributes

static const bitCapIntOcl OclMemDenom = 3U
 1 / OclMemDenom is the maximum fraction of total OCL device RAM that a single state vector should occupy, by design of the QEngine. More...
 

Protected Member Functions

virtual real1_f GetExpectation (bitLenInt valueStart, bitLenInt valueLength)
 
virtual complexAllocStateVec (bitCapInt elemCount, bool doForceAlloc=false)
 
virtual void ResetStateVec (complex *sv)
 
virtual void ResetStateBuffer (BufferPtr nStateBuffer)
 
virtual BufferPtr MakeStateVecBuffer (complex *nStateVec)
 
virtual void ReinitBuffer ()
 
virtual void Compose (OCLAPI apiCall, bitCapIntOcl *bciArgs, QEngineOCLPtr toCopy)
 
virtual void INCDECC (bitCapInt toMod, const bitLenInt &inOutStart, const bitLenInt &length, const bitLenInt &carryIndex)
 Common driver method behing INCC and DECC. More...
 
virtual void INCDECSC (bitCapInt toMod, const bitLenInt &inOutStart, const bitLenInt &length, const bitLenInt &carryIndex)
 Increment integer (with sign, with carry) More...
 
virtual void INCDECSC (bitCapInt toMod, const bitLenInt &inOutStart, const bitLenInt &length, const bitLenInt &overflowIndex, const bitLenInt &carryIndex)
 Increment integer (with sign, with carry) More...
 
void InitOCL (int devID)
 
PoolItemPtr GetFreePoolItem ()
 
real1_f ParSum (real1 *toSum, bitCapIntOcl maxI)
 
void LockSync (cl_int flags=(CL_MAP_READ|CL_MAP_WRITE))
 Locks synchronization between the state vector buffer and general RAM, so the state vector can be directly read and/or written to. More...
 
void UnlockSync ()
 Unlocks synchronization between the state vector buffer and general RAM, so the state vector can be operated on with OpenCL kernels and operations. More...
 
virtual void clFinish (bool doHard=false)
 Finishes the asynchronous wait event list or queue of OpenCL events. More...
 
virtual void clDump ()
 Dumps the remaining asynchronous wait event list or queue of OpenCL events, for the current queue. More...
 
size_t FixWorkItemCount (size_t maxI, size_t wic)
 
size_t FixGroupSize (size_t wic, size_t gs)
 
void DecomposeDispose (bitLenInt start, bitLenInt length, QEngineOCLPtr dest)
 
void ArithmeticCall (OCLAPI api_call, bitCapIntOcl(&bciArgs)[BCI_ARG_LEN], unsigned char *values=NULL, bitCapIntOcl valuesLength=0)
 
void CArithmeticCall (OCLAPI api_call, bitCapIntOcl(&bciArgs)[BCI_ARG_LEN], bitCapIntOcl *controlPowers, const bitLenInt controlLen, unsigned char *values=NULL, bitCapIntOcl valuesLength=0)
 
virtual void Apply2x2 (bitCapInt offset1, bitCapInt offset2, const complex *mtrx, const bitLenInt bitCount, const bitCapInt *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)
 
virtual void Apply2x2 (bitCapInt offset1, bitCapInt offset2, const complex *mtrx, const bitLenInt bitCount, const bitCapInt *qPowersSorted, bool doCalcNorm, SPECIAL_2X2 special, real1_f norm_thresh=REAL1_DEFAULT_ARG)
 
virtual void ApplyM (bitCapInt mask, bool result, complex nrm)
 
virtual void ApplyM (bitCapInt mask, bitCapInt result, complex nrm)
 
void WaitCall (OCLAPI api_call, size_t workItemCount, size_t localGroupSize, std::vector< BufferPtr > args, size_t localBuffSize=0)
 
EventVecPtr ResetWaitEvents (bool waitQueue=true)
 
void ApplyMx (OCLAPI api_call, bitCapIntOcl *bciArgs, complex nrm)
 
real1_f Probx (OCLAPI api_call, bitCapIntOcl *bciArgs)
 
void ROx (OCLAPI api_call, bitLenInt shift, bitLenInt start, bitLenInt length)
 
void INT (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt length)
 Add or Subtract integer (without sign or carry) More...
 
void CINT (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt start, const bitLenInt length, const bitLenInt *controls, const bitLenInt controlLen)
 Add or Subtract integer (without sign or carry, with controls) More...
 
void INTC (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt length, const bitLenInt carryIndex)
 Add or Subtract integer (without sign, with carry) More...
 
void INTS (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt length, const bitLenInt overflowIndex)
 Add or Subtract integer (with overflow, without carry) More...
 
void INTSC (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt length, const bitLenInt carryIndex)
 Add or Subtract integer (with sign, with carry) More...
 
void INTSC (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt length, const bitLenInt overflowIndex, const bitLenInt carryIndex)
 Add or Subtract integer (with sign, with carry) More...
 
void xMULx (OCLAPI api_call, bitCapIntOcl *bciArgs, BufferPtr controlBuffer)
 
void MULx (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt carryStart, const bitLenInt length)
 
void MULModx (OCLAPI api_call, bitCapIntOcl toMod, bitCapIntOcl modN, const bitLenInt inOutStart, const bitLenInt carryStart, const bitLenInt length)
 
void CMULx (OCLAPI api_call, bitCapIntOcl toMod, const bitLenInt inOutStart, const bitLenInt carryStart, const bitLenInt length, const bitLenInt *controls, const bitLenInt controlLen)
 
void CMULModx (OCLAPI api_call, bitCapIntOcl toMod, bitCapIntOcl modN, const bitLenInt inOutStart, const bitLenInt carryStart, const bitLenInt length, const bitLenInt *controls, const bitLenInt controlLen)
 
void FullAdx (bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut, OCLAPI api_call)
 
void PhaseFlipX (OCLAPI api_call, bitCapIntOcl *bciArgs)
 
bitCapIntOcl OpIndexed (OCLAPI api_call, bitCapIntOcl carryIn, bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, unsigned char *values)
 Add or Subtract based on an indexed load from classical memory. More...
 
void ClearBuffer (BufferPtr buff, bitCapIntOcl offset, bitCapIntOcl size)
 
- Protected Member Functions inherited from Qrack::QInterface
template<typename GateFunc >
void ControlledLoopFixture (bitLenInt length, GateFunc gate)
 
void FreeAligned (void *toFree)
 
bool IsIdentity (const complex *mtrx, const bool isControlled)
 
complex GetNonunitaryPhase ()
 

Protected Attributes

bitCapIntOcl maxQPowerOcl
 
complexstateVec
 
int deviceID
 
DeviceContextPtr device_context
 
std::vector< EventVecPtrwait_refs
 
std::list< QueueItemwait_queue_items
 
std::mutex queue_mutex
 
cl::CommandQueue queue
 
cl::Context context
 
BufferPtr stateBuffer
 
BufferPtr nrmBuffer
 
BufferPtr powersBuffer
 
std::vector< PoolItemPtrpoolItems
 
real1nrmArray
 
size_t nrmGroupCount
 
size_t nrmGroupSize
 
size_t maxWorkItems
 
size_t maxMem
 
size_t maxAlloc
 
unsigned int procElemCount
 
bool unlockHostMem
 
cl_int lockSyncFlags
 
bool usingHostRam
 
complex permutationAmp
 
- Protected Attributes inherited from Qrack::QEngine
bool useHostRam
 
real1 runningNorm
 The value stored in runningNorm should always be the total probability implied by the norm of all amplitudes, summed, at each update. More...
 
- Protected Attributes inherited from Qrack::QInterface
bitLenInt qubitCount
 
bitCapInt maxQPower
 
uint32_t randomSeed
 
qrack_rand_gen_ptr rand_generator
 
std::uniform_real_distribution< real1_frand_distribution
 
std::shared_ptr< RdRandomhardware_rand_generator
 
bool doNormalize
 
bool randGlobalPhase
 
real1 amplitudeFloor
 

Additional Inherited Members

- Static Protected Member Functions inherited from Qrack::QInterface
static real1_f normHelper (complex c)
 
static real1_f clampProb (real1_f toClamp)
 

Detailed Description

OpenCL enhanced QEngineCPU implementation.

QEngineOCL exposes asynchronous void-return public methods, wherever possible. While QEngine public methods run on a secondary accelerator, such as a GPU, other code can be executed on the CPU at the same time. If only one (CPU) OpenCL device is available, this engine type is still compatible with most CPUs, and this implementation will still usually give a very significant performance boost over the non-OpenCL QEngineCPU implementation.

Each QEngineOCL queues an independent event list of chained asynchronous methods. Multiple QEngineOCL instances may share a single device. Any one QEngineOCL instance (or QEngineCPU instance) is NOT safe to access from multiple threads, but different QEngineOCL instances may be accessed in respective threads. When a public method with a non-void return type is called, (such as Prob() or M() variants,) the engine wait list of OpenCL events will first be finished, then the return value will be calculated based on all public method calls dispatched up to that point. Asynchronous method dispatch is "transparent," in the sense that no explicit consideration for synchronization should be necessary. The programmer benefits from knowing that void-return methods attempt asynchronous execution, but asynchronous methods are always joined, in order of dispatch, before any and all non-void-return methods give their results.

Constructor & Destructor Documentation

◆ QEngineOCL()

Qrack::QEngineOCL::QEngineOCL ( bitLenInt  qBitCount,
bitCapInt  initState,
qrack_rand_gen_ptr  rgp = nullptr,
complex  phaseFac = CMPLX_DEFAULT_ARG,
bool  doNorm = false,
bool  randomGlobalPhase = true,
bool  useHostMem = false,
int  devID = -1,
bool  useHardwareRNG = true,
bool  ignored = false,
real1_f  norm_thresh = REAL1_EPSILON,
std::vector< int >  ignored2 = {},
bitLenInt  ignored3 = 0 
)

Initialize a Qrack::QEngineOCL object.

Specify the number of qubits and an initial permutation state. Additionally, optionally specify a pointer to a random generator engine object, a device ID from the list of devices in the OCLEngine singleton, and a boolean that is set to "true" to initialize the state vector of the object to zero norm.

"devID" is the index of an OpenCL device in the OCLEngine singleton, to select the device to run this engine on. If "useHostMem" is set false, as by default, the QEngineOCL will attempt to allocate the state vector object only on device memory. If "useHostMem" is set true, general host RAM will be used for the state vector buffers. If the state vector is too large to allocate only on device memory, the QEngineOCL will attempt to fall back to allocating it in general host RAM.

Warning
"useHostMem" is not conscious of allocation by other QEngineOCL instances on the same device. Attempting to allocate too much device memory across too many QEngineOCL instances, for which each instance would have sufficient device resources on its own, will probably cause the program to crash (and may lead to general system instability). For safety, "useHostMem" can be turned on.

◆ ~QEngineOCL()

virtual Qrack::QEngineOCL::~QEngineOCL ( )
inlinevirtual

Member Function Documentation

◆ AddQueueItem()

virtual void Qrack::QEngineOCL::AddQueueItem ( const QueueItem item)
inlinevirtual

◆ AllocStateVec()

complex * Qrack::QEngineOCL::AllocStateVec ( bitCapInt  elemCount,
bool  doForceAlloc = false 
)
protectedvirtual

◆ Apply2x2() [1/2]

virtual void Qrack::QEngineOCL::Apply2x2 ( bitCapInt  offset1,
bitCapInt  offset2,
const complex mtrx,
const bitLenInt  bitCount,
const bitCapInt qPowersSorted,
bool  doCalcNorm,
real1_f  norm_thresh = REAL1_DEFAULT_ARG 
)
inlineprotectedvirtual

Implements Qrack::QEngine.

◆ Apply2x2() [2/2]

void Qrack::QEngineOCL::Apply2x2 ( bitCapInt  offset1,
bitCapInt  offset2,
const complex mtrx,
const bitLenInt  bitCount,
const bitCapInt qPowersSorted,
bool  doCalcNorm,
SPECIAL_2X2  special,
real1_f  norm_thresh = REAL1_DEFAULT_ARG 
)
protectedvirtual

◆ ApplyM() [1/2]

void Qrack::QEngineOCL::ApplyM ( bitCapInt  mask,
bool  result,
complex  nrm 
)
protectedvirtual

Reimplemented from Qrack::QEngine.

◆ ApplyM() [2/2]

void Qrack::QEngineOCL::ApplyM ( bitCapInt  mask,
bitCapInt  result,
complex  nrm 
)
protectedvirtual

Implements Qrack::QEngine.

◆ ApplyMx()

void Qrack::QEngineOCL::ApplyMx ( OCLAPI  api_call,
bitCapIntOcl bciArgs,
complex  nrm 
)
protected

◆ ApplySingleInvert()

void Qrack::QEngineOCL::ApplySingleInvert ( const complex  topRight,
const complex  bottomLeft,
bitLenInt  qubitIndex 
)
virtual

Apply a single bit transformation that reverses bit probability and might effect phase.

Reimplemented from Qrack::QInterface.

◆ ApplySinglePhase()

void Qrack::QEngineOCL::ApplySinglePhase ( const complex  topLeft,
const complex  bottomRight,
bitLenInt  qubitIndex 
)
virtual

Apply a single bit transformation that only effects phase.

Reimplemented from Qrack::QInterface.

◆ ArithmeticCall()

void Qrack::QEngineOCL::ArithmeticCall ( OCLAPI  api_call,
bitCapIntOcl(&)  bciArgs[BCI_ARG_LEN],
unsigned char *  values = NULL,
bitCapIntOcl  valuesLength = 0 
)
protected

◆ CArithmeticCall()

void Qrack::QEngineOCL::CArithmeticCall ( OCLAPI  api_call,
bitCapIntOcl(&)  bciArgs[BCI_ARG_LEN],
bitCapIntOcl controlPowers,
const bitLenInt  controlLen,
unsigned char *  values = NULL,
bitCapIntOcl  valuesLength = 0 
)
protected

◆ CDIV()

void Qrack::QEngineOCL::CDIV ( bitCapInt  toDiv,
bitLenInt  inOutStart,
bitLenInt  carryStart,
bitLenInt  length,
bitLenInt controls,
bitLenInt  controlLen 
)
virtual

Controlled division by integer.

Implements Qrack::QInterface.

◆ CIMULModNOut()

void Qrack::QEngineOCL::CIMULModNOut ( bitCapInt  toMul,
bitCapInt  modN,
bitLenInt  inStart,
bitLenInt  outStart,
bitLenInt  length,
bitLenInt controls,
bitLenInt  controlLen 
)
virtual

Inverse: controlled multiplication modulo N by integer, (out of place)

Implements Qrack::QInterface.

◆ CINC()

void Qrack::QEngineOCL::CINC ( bitCapInt  toAdd,
bitLenInt  inOutStart,
bitLenInt  length,
bitLenInt controls,
bitLenInt  controlLen 
)
virtual

Add integer (without sign, with controls)

Implements Qrack::QInterface.

◆ CINT()

void Qrack::QEngineOCL::CINT ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  start,
const bitLenInt  length,
const bitLenInt controls,
const bitLenInt  controlLen 
)
protected

Add or Subtract integer (without sign or carry, with controls)

◆ clDump()

void Qrack::QEngineOCL::clDump ( )
protectedvirtual

Dumps the remaining asynchronous wait event list or queue of OpenCL events, for the current queue.

◆ ClearBuffer()

void Qrack::QEngineOCL::ClearBuffer ( BufferPtr  buff,
bitCapIntOcl  offset,
bitCapIntOcl  size 
)
protected

◆ clFinish()

void Qrack::QEngineOCL::clFinish ( bool  doHard = false)
protectedvirtual

Finishes the asynchronous wait event list or queue of OpenCL events.

By default (doHard = false) only the wait event list of this engine is finished. If doHard = true, the entire device queue is finished, (which might be shared by other QEngineOCL instances).

◆ Clone()

QInterfacePtr Qrack::QEngineOCL::Clone ( )
virtual

Clone this QInterface.

Implements Qrack::QInterface.

◆ CMUL()

void Qrack::QEngineOCL::CMUL ( bitCapInt  toMul,
bitLenInt  inOutStart,
bitLenInt  carryStart,
bitLenInt  length,
bitLenInt controls,
bitLenInt  controlLen 
)
virtual

Controlled multiplication by integer.

Implements Qrack::QInterface.

◆ CMULModNOut()

void Qrack::QEngineOCL::CMULModNOut ( bitCapInt  toMul,
bitCapInt  modN,
bitLenInt  inStart,
bitLenInt  outStart,
bitLenInt  length,
bitLenInt controls,
bitLenInt  controlLen 
)
virtual

Controlled multiplication modulo N by integer, (out of place)

Implements Qrack::QInterface.

◆ CMULModx()

void Qrack::QEngineOCL::CMULModx ( OCLAPI  api_call,
bitCapIntOcl  toMod,
bitCapIntOcl  modN,
const bitLenInt  inOutStart,
const bitLenInt  carryStart,
const bitLenInt  length,
const bitLenInt controls,
const bitLenInt  controlLen 
)
protected

◆ CMULx()

void Qrack::QEngineOCL::CMULx ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  carryStart,
const bitLenInt  length,
const bitLenInt controls,
const bitLenInt  controlLen 
)
protected

◆ Compose() [1/5]

bitLenInt Qrack::QEngineOCL::Compose ( QEngineOCLPtr  toCopy)
virtual

◆ Compose() [2/5]

virtual bitLenInt Qrack::QEngineOCL::Compose ( QInterfacePtr  toCopy)
inlinevirtual

Combine another QInterface with this one, after the last bit index of this one.

"Compose" combines the quantum description of state of two independent QInterface objects into one object, containing the full permutation basis of the full object. The "inputState" bits are added after the last qubit index of the QInterface to which we "Compose." Informally, "Compose" is equivalent to "just setting another group of qubits down next to the first" without interacting them. Schroedinger's equation can form a description of state for two independent subsystems at once or "separable quantum subsystems" without interacting them. Once the description of state of the independent systems is combined, we can interact them, and we can describe their entanglements to each other, in which case they are no longer independent. A full entangled description of quantum state is not possible for two independent quantum subsystems until we "Compose" them.

"Compose" multiplies the probabilities of the indepedent permutation states of the two subsystems to find the probabilites of the entire set of combined permutations, by simple combinatorial reasoning. If the probablity of the "left-hand" subsystem being in |00> is 1/4, and the probablity of the "right-hand" subsystem being in |101> is 1/8, than the probability of the combined |00101> permutation state is 1/32, and so on for all permutations of the new combined state.

If the programmer doesn't want to "cheat" quantum mechanically, then the original copy of the state which is duplicated into the larger QInterface should be "thrown away" to satisfy "no clone theorem." This is not semantically enforced in Qrack, because optimization of an emulator might be acheived by "cloning" "under-the-hood" while only exposing a quantum mechanically consistent API or instruction set.

Returns the quantum bit offset that the QInterface was appended at, such that bit 5 in toCopy is equal to offset+5 in this object.

Reimplemented from Qrack::QInterface.

◆ Compose() [3/5]

bitLenInt Qrack::QEngineOCL::Compose ( QEngineOCLPtr  toCopy,
bitLenInt  start 
)
virtual

◆ Compose() [4/5]

virtual bitLenInt Qrack::QEngineOCL::Compose ( QInterfacePtr  toCopy,
bitLenInt  start 
)
inlinevirtual

Implements Qrack::QInterface.

◆ Compose() [5/5]

void Qrack::QEngineOCL::Compose ( OCLAPI  apiCall,
bitCapIntOcl bciArgs,
QEngineOCLPtr  toCopy 
)
protectedvirtual

◆ CopyStateVec()

virtual void Qrack::QEngineOCL::CopyStateVec ( QEnginePtr  src)
inlinevirtual

Implements Qrack::QEngine.

◆ CPhaseFlipIfLess()

void Qrack::QEngineOCL::CPhaseFlipIfLess ( bitCapInt  greaterPerm,
bitLenInt  start,
bitLenInt  length,
bitLenInt  flagIndex 
)
virtual

The 6502 uses its carry flag also as a greater-than/less-than flag, for the CMP operation.

Implements Qrack::QInterface.

◆ CPOWModNOut()

void Qrack::QEngineOCL::CPOWModNOut ( bitCapInt  base,
bitCapInt  modN,
bitLenInt  inStart,
bitLenInt  outStart,
bitLenInt  length,
bitLenInt controls,
bitLenInt  controlLen 
)
virtual

Controlled multiplication modulo N by integer, (out of place)

Implements Qrack::QInterface.

◆ CUniformParityRZ()

void Qrack::QEngineOCL::CUniformParityRZ ( const bitLenInt controls,
const bitLenInt controlLen,
const bitCapInt mask,
const real1_f angle 
)
virtual

If the controls are set and the target qubit set parity is odd, this applies a phase factor of e^{i angle}.

If the controls are set and the target qubit set parity is even, this applies the conjugate, e^{-i angle}. Otherwise, do nothing if any control is not set.

Implements Qrack::QInterface.

◆ Decompose()

void Qrack::QEngineOCL::Decompose ( bitLenInt  start,
QInterfacePtr  dest 
)
virtual

Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".

Minimally decompose a set of contigious bits from the separably composed unit. The length of this separable unit is reduced by the length of bits decomposed, and the bits removed are output in the destination QInterface pointer. The destination object must be initialized to the correct number of bits, in 0 permutation state. For quantum mechanical accuracy, the bit set removed and the bit set left behind should be quantum mechanically "separable."

Like how "Compose" is like "just setting another group of qubits down next to the first," if two sets of qubits are not entangled, then "Decompose" is like "just moving a few qubits away from the rest." Schroedinger's equation does not require bits to be explicitly interacted in order to describe their permutation basis, and the descriptions of state of separable subsystems, those which are not entangled with other subsystems, are just as easily removed from the description of state. (This is equivalent to a "Schmidt decomposition.")

If we have for example 5 qubits, and we wish to separate into "left" and "right" subsystems of 3 and 2 qubits, we sum probabilities of one permutation of the "left" three over ALL permutations of the "right" two, for all permutations, and vice versa, like so:

\( P(|1000>|xy>) = P(|1000 00>) + P(|1000 10>) + P(|1000 01>) + P(|1000 11>). \)

If the subsystems are not "separable," i.e. if they are entangled, this operation is not well-motivated, and its output is not necessarily defined. (The summing of probabilities over permutations of subsytems will be performed as described above, but this is not quantum mechanically meaningful.) To ensure that the subsystem is "separable," i.e. that it has no entanglements to other subsystems in the QInterface, it can be measured with M(), or else all qubits other than the subsystem can be measured.

Implements Qrack::QInterface.

◆ DecomposeDispose()

void Qrack::QEngineOCL::DecomposeDispose ( bitLenInt  start,
bitLenInt  length,
QEngineOCLPtr  dest 
)
protected

◆ DispatchQueue()

void Qrack::QEngineOCL::DispatchQueue ( cl_event  event,
cl_int  type 
)

◆ Dispose() [1/2]

void Qrack::QEngineOCL::Dispose ( bitLenInt  start,
bitLenInt  length 
)
virtual

Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separable bits from index "start" for "length.".

Minimally decompose a set of contigious bits from the separably composed unit. The length of this separable unit is reduced by the length of bits decomposed, and the bits removed are output in the destination QInterface pointer. The destination object must be initialized to the correct number of bits, in 0 permutation state. For quantum mechanical accuracy, the bit set removed and the bit set left behind should be quantum mechanically "separable."

Like how "Compose" is like "just setting another group of qubits down next to the first," if two sets of qubits are not entangled, then "Decompose" is like "just moving a few qubits away from the rest." Schroedinger's equation does not require bits to be explicitly interacted in order to describe their permutation basis, and the descriptions of state of separable subsystems, those which are not entangled with other subsystems, are just as easily removed from the description of state. (This is equivalent to a "Schmidt decomposition.")

If we have for example 5 qubits, and we wish to separate into "left" and "right" subsystems of 3 and 2 qubits, we sum probabilities of one permutation of the "left" three over ALL permutations of the "right" two, for all permutations, and vice versa, like so:

\( P(|1000>|xy>) = P(|1000 00>) + P(|1000 10>) + P(|1000 01>) + P(|1000 11>). \)

If the subsystems are not "separable," i.e. if they are entangled, this operation is not well-motivated, and its output is not necessarily defined. (The summing of probabilities over permutations of subsytems will be performed as described above, but this is not quantum mechanically meaningful.) To ensure that the subsystem is "separable," i.e. that it has no entanglements to other subsystems in the QInterface, it can be measured with M(), or else all qubits other than the subsystem can be measured.

Implements Qrack::QInterface.

◆ Dispose() [2/2]

void Qrack::QEngineOCL::Dispose ( bitLenInt  start,
bitLenInt  length,
bitCapInt  disposedPerm 
)
virtual

Dispose a a contiguous set of qubits that are already in a permutation eigenstate.

Implements Qrack::QInterface.

◆ DIV()

void Qrack::QEngineOCL::DIV ( bitCapInt  toDiv,
bitLenInt  inOutStart,
bitLenInt  carryStart,
bitLenInt  length 
)
virtual

Divide by integer.

Implements Qrack::QInterface.

◆ Finish()

virtual void Qrack::QEngineOCL::Finish ( )
inlinevirtual

If asynchronous work is still running, block until it finishes.

Note that this is never necessary to get correct, timely return values. QEngines and other layers will always internally "Finish" when necessary for correct return values. This is primarily for debugging and benchmarking.

Reimplemented from Qrack::QInterface.

◆ FixGroupSize()

size_t Qrack::QEngineOCL::FixGroupSize ( size_t  wic,
size_t  gs 
)
protected

◆ FixWorkItemCount()

size_t Qrack::QEngineOCL::FixWorkItemCount ( size_t  maxI,
size_t  wic 
)
protected

◆ ForceMParity()

bool Qrack::QEngineOCL::ForceMParity ( const bitCapInt mask,
bool  result,
bool  doForce = true 
)
virtual

Act as if is a measurement of parity of the masked set of qubits was applied, except force the (usually random) result.

Warning
PSEUDO-QUANTUM

Implements Qrack::QInterface.

◆ FreeStateVec()

virtual void Qrack::QEngineOCL::FreeStateVec ( complex sv = NULL)
inlinevirtual

Implements Qrack::QEngine.

◆ FullAdd()

void Qrack::QEngineOCL::FullAdd ( bitLenInt  inputBit1,
bitLenInt  inputBit2,
bitLenInt  carryInSumOut,
bitLenInt  carryOut 
)
virtual

Quantum analog of classical "Full Adder" gate.

Reimplemented from Qrack::QInterface.

◆ FullAdx()

void Qrack::QEngineOCL::FullAdx ( bitLenInt  inputBit1,
bitLenInt  inputBit2,
bitLenInt  carryInSumOut,
bitLenInt  carryOut,
OCLAPI  api_call 
)
protected

◆ GetAmplitude()

complex Qrack::QEngineOCL::GetAmplitude ( bitCapInt  perm)
virtual

Get the representational amplitude of a full permutation.

Warning
PSEUDO-QUANTUM

Implements Qrack::QInterface.

◆ GetAmplitudePage()

void Qrack::QEngineOCL::GetAmplitudePage ( complex pagePtr,
const bitCapInt  offset,
const bitCapInt  length 
)
virtual

Implements Qrack::QEngine.

◆ GetDeviceID()

virtual int Qrack::QEngineOCL::GetDeviceID ( )
inlinevirtual

Get the device index.

("-1" is default).

Reimplemented from Qrack::QInterface.

◆ GetExpectation()

real1_f Qrack::QEngineOCL::GetExpectation ( bitLenInt  valueStart,
bitLenInt  valueLength 
)
protectedvirtual

Implements Qrack::QEngine.

◆ GetFreePoolItem()

PoolItemPtr Qrack::QEngineOCL::GetFreePoolItem ( )
protected

◆ GetMaxSize()

bitCapIntOcl Qrack::QEngineOCL::GetMaxSize ( )
inline

◆ GetProbs()

void Qrack::QEngineOCL::GetProbs ( real1 outputProbs)
virtual

Get all probabilities, in unsigned int permutation basis.

Implements Qrack::QInterface.

◆ GetQuantumState()

void Qrack::QEngineOCL::GetQuantumState ( complex outputState)
virtual

Get pure quantum state, in unsigned int permutation basis.

Implements Qrack::QInterface.

◆ Hash()

void Qrack::QEngineOCL::Hash ( bitLenInt  start,
bitLenInt  length,
unsigned char *  values 
)
virtual

Set 8 bit register bits based on read from classical memory.

Implements Qrack::QInterface.

◆ IFullAdd()

void Qrack::QEngineOCL::IFullAdd ( bitLenInt  inputBit1,
bitLenInt  inputBit2,
bitLenInt  carryInSumOut,
bitLenInt  carryOut 
)
virtual

Inverse of FullAdd.

Reimplemented from Qrack::QInterface.

◆ IMULModNOut()

void Qrack::QEngineOCL::IMULModNOut ( bitCapInt  toMul,
bitCapInt  modN,
bitLenInt  inStart,
bitLenInt  outStart,
bitLenInt  length 
)
virtual

Inverse: multiplication modulo N by integer, (out of place)

Implements Qrack::QInterface.

◆ INC()

void Qrack::QEngineOCL::INC ( bitCapInt  toAdd,
bitLenInt  start,
bitLenInt  length 
)
virtual

Increment integer (without sign, with carry)

Implements Qrack::QInterface.

◆ INCDECC()

void Qrack::QEngineOCL::INCDECC ( bitCapInt  toMod,
const bitLenInt inOutStart,
const bitLenInt length,
const bitLenInt carryIndex 
)
protectedvirtual

Common driver method behing INCC and DECC.

Implements Qrack::QEngine.

◆ INCDECSC() [1/2]

void Qrack::QEngineOCL::INCDECSC ( bitCapInt  toMod,
const bitLenInt inOutStart,
const bitLenInt length,
const bitLenInt carryIndex 
)
protectedvirtual

Increment integer (with sign, with carry)

Implements Qrack::QEngine.

◆ INCDECSC() [2/2]

void Qrack::QEngineOCL::INCDECSC ( bitCapInt  toMod,
const bitLenInt inOutStart,
const bitLenInt length,
const bitLenInt overflowIndex,
const bitLenInt carryIndex 
)
protectedvirtual

Increment integer (with sign, with carry)

Implements Qrack::QEngine.

◆ INCS()

void Qrack::QEngineOCL::INCS ( bitCapInt  toAdd,
bitLenInt  start,
bitLenInt  length,
bitLenInt  carryIndex 
)
virtual

Increment integer (without sign, with carry)

Implements Qrack::QInterface.

◆ IndexedADC()

bitCapInt Qrack::QEngineOCL::IndexedADC ( bitLenInt  indexStart,
bitLenInt  indexLength,
bitLenInt  valueStart,
bitLenInt  valueLength,
bitLenInt  carryIndex,
unsigned char *  values 
)
virtual

Add based on an indexed load from classical memory.

Implements Qrack::QInterface.

◆ IndexedLDA()

bitCapInt Qrack::QEngineOCL::IndexedLDA ( bitLenInt  indexStart,
bitLenInt  indexLength,
bitLenInt  valueStart,
bitLenInt  valueLength,
unsigned char *  values,
bool  resetValue = true 
)
virtual

Set 8 bit register bits based on read from classical memory.

Implements Qrack::QInterface.

◆ IndexedSBC()

bitCapInt Qrack::QEngineOCL::IndexedSBC ( bitLenInt  indexStart,
bitLenInt  indexLength,
bitLenInt  valueStart,
bitLenInt  valueLength,
bitLenInt  carryIndex,
unsigned char *  values 
)
virtual

Subtract based on an indexed load from classical memory.

Implements Qrack::QInterface.

◆ InitOCL()

void Qrack::QEngineOCL::InitOCL ( int  devID)
protected

◆ INT()

void Qrack::QEngineOCL::INT ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  length 
)
protected

Add or Subtract integer (without sign or carry)

◆ INTC()

void Qrack::QEngineOCL::INTC ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  length,
const bitLenInt  carryIndex 
)
protected

Add or Subtract integer (without sign, with carry)

◆ INTS()

void Qrack::QEngineOCL::INTS ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  length,
const bitLenInt  overflowIndex 
)
protected

Add or Subtract integer (with overflow, without carry)

◆ INTSC() [1/2]

void Qrack::QEngineOCL::INTSC ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  length,
const bitLenInt  carryIndex 
)
protected

Add or Subtract integer (with sign, with carry)

◆ INTSC() [2/2]

void Qrack::QEngineOCL::INTSC ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  length,
const bitLenInt  overflowIndex,
const bitLenInt  carryIndex 
)
protected

Add or Subtract integer (with sign, with carry)

◆ isFinished()

virtual bool Qrack::QEngineOCL::isFinished ( )
inlinevirtual

Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynchronous work is done.

Reimplemented from Qrack::QInterface.

◆ IsZeroAmplitude()

virtual bool Qrack::QEngineOCL::IsZeroAmplitude ( )
inlinevirtual

Implements Qrack::QEngine.

◆ LockSync()

void Qrack::QEngineOCL::LockSync ( cl_int  flags = (CL_MAP_READ | CL_MAP_WRITE))
protected

Locks synchronization between the state vector buffer and general RAM, so the state vector can be directly read and/or written to.

OpenCL buffers, even when allocated on "host" general RAM, are not safe to read from or write to unless "mapped." When mapped, a buffer cannot be used by OpenCL kernels. If the state vector needs to be directly manipulated, it needs to be temporarily mapped, and this can be accomplished with LockSync(). When direct reading from or writing to the state vector is done, before performing other OpenCL operations on it, it must be unmapped with UnlockSync().

◆ MakeStateVecBuffer()

BufferPtr Qrack::QEngineOCL::MakeStateVecBuffer ( complex nStateVec)
protectedvirtual

◆ MUL()

void Qrack::QEngineOCL::MUL ( bitCapInt  toMul,
bitLenInt  inOutStart,
bitLenInt  carryStart,
bitLenInt  length 
)
virtual

Multiply by integer.

Implements Qrack::QInterface.

◆ MULModNOut()

void Qrack::QEngineOCL::MULModNOut ( bitCapInt  toMul,
bitCapInt  modN,
bitLenInt  inStart,
bitLenInt  outStart,
bitLenInt  length 
)
virtual

Multiplication modulo N by integer, (out of place)

Implements Qrack::QInterface.

◆ MULModx()

void Qrack::QEngineOCL::MULModx ( OCLAPI  api_call,
bitCapIntOcl  toMod,
bitCapIntOcl  modN,
const bitLenInt  inOutStart,
const bitLenInt  carryStart,
const bitLenInt  length 
)
protected

◆ MULx()

void Qrack::QEngineOCL::MULx ( OCLAPI  api_call,
bitCapIntOcl  toMod,
const bitLenInt  inOutStart,
const bitLenInt  carryStart,
const bitLenInt  length 
)
protected

◆ NormalizeState()

void Qrack::QEngineOCL::NormalizeState ( real1_f  nrm = REAL1_DEFAULT_ARG,
real1_f  norm_thresh = REAL1_DEFAULT_ARG 
)
virtual

Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate.

(On an actual quantum computer, the state should never require manual normalization.)

Warning
PSEUDO-QUANTUM

Implements Qrack::QEngine.

◆ OpIndexed()

bitCapIntOcl Qrack::QEngineOCL::OpIndexed ( OCLAPI  api_call,
bitCapIntOcl  carryIn,
bitLenInt  indexStart,
bitLenInt  indexLength,
bitLenInt  valueStart,
bitLenInt  valueLength,
bitLenInt  carryIndex,
unsigned char *  values 
)
protected

Add or Subtract based on an indexed load from classical memory.

◆ ParSum()

real1_f Qrack::QEngineOCL::ParSum ( real1 toSum,
bitCapIntOcl  maxI 
)
protected

◆ PhaseFlipIfLess()

void Qrack::QEngineOCL::PhaseFlipIfLess ( bitCapInt  greaterPerm,
bitLenInt  start,
bitLenInt  length 
)
virtual

This is an expedient for an adaptive Grover's search for a function's global minimum.

Implements Qrack::QInterface.

◆ PhaseFlipX()

void Qrack::QEngineOCL::PhaseFlipX ( OCLAPI  api_call,
bitCapIntOcl bciArgs 
)
protected

◆ PopQueue()

void Qrack::QEngineOCL::PopQueue ( cl_event  event,
cl_int  type 
)

◆ POWModNOut()

void Qrack::QEngineOCL::POWModNOut ( bitCapInt  base,
bitCapInt  modN,
bitLenInt  inStart,
bitLenInt  outStart,
bitLenInt  length 
)
virtual

Raise a classical base to a quantum power, modulo N, (out of place)

Implements Qrack::QInterface.

◆ Prob()

real1_f Qrack::QEngineOCL::Prob ( bitLenInt  qubit)
virtual

PSEUDO-QUANTUM Direct measure of bit probability to be in |1> state.

Implements Qrack::QInterface.

◆ ProbAll()

real1_f Qrack::QEngineOCL::ProbAll ( bitCapInt  fullRegister)
virtual

Direct measure of full permutation probability.

Warning
PSEUDO-QUANTUM

Implements Qrack::QInterface.

◆ ProbMask()

real1_f Qrack::QEngineOCL::ProbMask ( const bitCapInt mask,
const bitCapInt permutation 
)
virtual

Direct measure of masked permutation probability.

Returns probability of permutation of the mask.

"mask" masks the bits to check the probability of. "permutation" sets the 0 or 1 value for each bit in the mask. Bits which are set in the mask can be set to 0 or 1 in the permutation, while reset bits in the mask should be 0 in the permutation.

Warning
PSEUDO-QUANTUM

Implements Qrack::QEngine.

◆ ProbMaskAll()

void Qrack::QEngineOCL::ProbMaskAll ( const bitCapInt mask,
real1 probsArray 
)
virtual

Direct measure of masked permutation probability.

"mask" masks the bits to check the probability of. The probabilities of all permutations of the masked bits, from left/low to right/high are returned in the "probsArray" argument.

Warning
PSEUDO-QUANTUM

Reimplemented from Qrack::QInterface.

◆ ProbParity()

real1_f Qrack::QEngineOCL::ProbParity ( const bitCapInt mask)
virtual

Overall probability of any odd permutation of the masked set of bits.

Implements Qrack::QInterface.

◆ ProbReg()

real1_f Qrack::QEngineOCL::ProbReg ( const bitLenInt start,
const bitLenInt length,
const bitCapInt permutation 
)
virtual

Direct measure of register permutation probability.

Returns probability of permutation of the register.

Warning
PSEUDO-QUANTUM

Implements Qrack::QEngine.

◆ ProbRegAll()

void Qrack::QEngineOCL::ProbRegAll ( const bitLenInt start,
const bitLenInt length,
real1 probsArray 
)
virtual

Reimplemented from Qrack::QEngine.

◆ Probx()

real1_f Qrack::QEngineOCL::Probx ( OCLAPI  api_call,
bitCapIntOcl bciArgs 
)
protected

◆ QueueCall()

virtual void Qrack::QEngineOCL::QueueCall ( OCLAPI  api_call,
size_t  workItemCount,
size_t  localGroupSize,
std::vector< BufferPtr args,
size_t  localBuffSize = 0 
)
inlinevirtual

◆ QueueSetDoNormalize()

virtual void Qrack::QEngineOCL::QueueSetDoNormalize ( const bool &  doNorm)
inlinevirtual

Implements Qrack::QEngine.

◆ QueueSetRunningNorm()

virtual void Qrack::QEngineOCL::QueueSetRunningNorm ( const real1_f runningNrm)
inlinevirtual

Implements Qrack::QEngine.

◆ ReinitBuffer()

void Qrack::QEngineOCL::ReinitBuffer ( )
protectedvirtual

◆ ResetStateBuffer()

void Qrack::QEngineOCL::ResetStateBuffer ( BufferPtr  nStateBuffer)
protectedvirtual

◆ ResetStateVec()

void Qrack::QEngineOCL::ResetStateVec ( complex sv)
protectedvirtual

◆ ResetWaitEvents()

EventVecPtr Qrack::QEngineOCL::ResetWaitEvents ( bool  waitQueue = true)
protected

◆ ROL()

void Qrack::QEngineOCL::ROL ( bitLenInt  shift,
bitLenInt  start,
bitLenInt  length 
)
virtual

"Circular shift left" - shift bits left, and carry last bits.

Reimplemented from Qrack::QInterface.

◆ ROx()

void Qrack::QEngineOCL::ROx ( OCLAPI  api_call,
bitLenInt  shift,
bitLenInt  start,
bitLenInt  length 
)
protected

◆ SetAmplitude()

void Qrack::QEngineOCL::SetAmplitude ( bitCapInt  perm,
complex  amp 
)
virtual

Sets the representational amplitude of a full permutation.

Warning
PSEUDO-QUANTUM

Implements Qrack::QInterface.

◆ SetAmplitudePage() [1/2]

void Qrack::QEngineOCL::SetAmplitudePage ( const complex pagePtr,
const bitCapInt  offset,
const bitCapInt  length 
)
virtual

Implements Qrack::QEngine.

◆ SetAmplitudePage() [2/2]

void Qrack::QEngineOCL::SetAmplitudePage ( QEnginePtr  pageEnginePtr,
const bitCapInt  srcOffset,
const bitCapInt  dstOffset,
const bitCapInt  length 
)
virtual

Implements Qrack::QEngine.

◆ SetDevice()

void Qrack::QEngineOCL::SetDevice ( const int &  dID,
const bool &  forceReInit = false 
)
virtual

Set the device index, if more than one device is available.

Reimplemented from Qrack::QInterface.

◆ SetPermutation()

void Qrack::QEngineOCL::SetPermutation ( bitCapInt  perm,
complex  phaseFac = CMPLX_DEFAULT_ARG 
)
virtual

Set to a specific permutation.

Implements Qrack::QInterface.

◆ SetQuantumState()

void Qrack::QEngineOCL::SetQuantumState ( const complex inputState)
virtual

Set arbitrary pure quantum state, in unsigned int permutation basis.

Implements Qrack::QInterface.

◆ SetQubitCount()

virtual void Qrack::QEngineOCL::SetQubitCount ( bitLenInt  qb)
inlinevirtual

Reimplemented from Qrack::QInterface.

◆ ShuffleBuffers()

void Qrack::QEngineOCL::ShuffleBuffers ( QEnginePtr  engine)
virtual

Swap the high half of this engine with the low half of another.

This is necessary for gates which cross sub-engine boundaries.

Implements Qrack::QEngine.

◆ SumSqrDiff() [1/2]

virtual real1_f Qrack::QEngineOCL::SumSqrDiff ( QInterfacePtr  toCompare)
inlinevirtual

Implements Qrack::QInterface.

◆ SumSqrDiff() [2/2]

real1_f Qrack::QEngineOCL::SumSqrDiff ( QEngineOCLPtr  toCompare)
virtual

◆ UniformlyControlledSingleBit()

void Qrack::QEngineOCL::UniformlyControlledSingleBit ( const bitLenInt controls,
const bitLenInt controlLen,
bitLenInt  qubitIndex,
const complex mtrxs,
const bitCapInt mtrxSkipPowers,
const bitLenInt  mtrxSkipLen,
const bitCapInt mtrxSkipValueMask 
)
virtual

Reimplemented from Qrack::QInterface.

◆ UniformParityRZ()

void Qrack::QEngineOCL::UniformParityRZ ( const bitCapInt mask,
const real1_f angle 
)
virtual

If the target qubit set parity is odd, this applies a phase factor of e^{i angle}.

If the target qubit set parity is even, this applies the conjugate, e^{-i angle}.

Reimplemented from Qrack::QInterface.

◆ UnlockSync()

void Qrack::QEngineOCL::UnlockSync ( )
protected

Unlocks synchronization between the state vector buffer and general RAM, so the state vector can be operated on with OpenCL kernels and operations.

OpenCL buffers, even when allocated on "host" general RAM, are not safe to read from or write to unless "mapped." When mapped, a buffer cannot be used by OpenCL kernels. If the state vector needs to be directly manipulated, it needs to be temporarily mapped, and this can be accomplished with LockSync(). When direct reading from or writing to the state vector is done, before performing other OpenCL operations on it, it must be unmapped with UnlockSync().

◆ UpdateRunningNorm()

void Qrack::QEngineOCL::UpdateRunningNorm ( real1_f  norm_thresh = REAL1_DEFAULT_ARG)
virtual

Force a calculation of the norm of the state vector, in order to make it unit length before the next probability or measurement operation.

(On an actual quantum computer, the state should never require manual normalization.)

Warning
PSEUDO-QUANTUM

Implements Qrack::QInterface.

◆ WaitCall()

void Qrack::QEngineOCL::WaitCall ( OCLAPI  api_call,
size_t  workItemCount,
size_t  localGroupSize,
std::vector< BufferPtr args,
size_t  localBuffSize = 0 
)
protected

◆ X()

void Qrack::QEngineOCL::X ( bitLenInt  target)
virtual

NOT gate, which is also Pauli x matrix.

Reimplemented from Qrack::QInterface.

◆ xMULx()

void Qrack::QEngineOCL::xMULx ( OCLAPI  api_call,
bitCapIntOcl bciArgs,
BufferPtr  controlBuffer 
)
protected

◆ Z()

void Qrack::QEngineOCL::Z ( bitLenInt  target)
virtual

Apply Pauli Z matrix to bit.

Reimplemented from Qrack::QInterface.

◆ ZeroAmplitudes()

virtual void Qrack::QEngineOCL::ZeroAmplitudes ( )
inlinevirtual

Implements Qrack::QEngine.

Member Data Documentation

◆ context

cl::Context Qrack::QEngineOCL::context
protected

◆ device_context

DeviceContextPtr Qrack::QEngineOCL::device_context
protected

◆ deviceID

int Qrack::QEngineOCL::deviceID
protected

◆ lockSyncFlags

cl_int Qrack::QEngineOCL::lockSyncFlags
protected

◆ maxAlloc

size_t Qrack::QEngineOCL::maxAlloc
protected

◆ maxMem

size_t Qrack::QEngineOCL::maxMem
protected

◆ maxQPowerOcl

bitCapIntOcl Qrack::QEngineOCL::maxQPowerOcl
protected

◆ maxWorkItems

size_t Qrack::QEngineOCL::maxWorkItems
protected

◆ nrmArray

real1* Qrack::QEngineOCL::nrmArray
protected

◆ nrmBuffer

BufferPtr Qrack::QEngineOCL::nrmBuffer
protected

◆ nrmGroupCount

size_t Qrack::QEngineOCL::nrmGroupCount
protected

◆ nrmGroupSize

size_t Qrack::QEngineOCL::nrmGroupSize
protected

◆ OclMemDenom

const bitCapIntOcl Qrack::QEngineOCL::OclMemDenom = 3U
static

1 / OclMemDenom is the maximum fraction of total OCL device RAM that a single state vector should occupy, by design of the QEngine.

◆ permutationAmp

complex Qrack::QEngineOCL::permutationAmp
protected

◆ poolItems

std::vector<PoolItemPtr> Qrack::QEngineOCL::poolItems
protected

◆ powersBuffer

BufferPtr Qrack::QEngineOCL::powersBuffer
protected

◆ procElemCount

unsigned int Qrack::QEngineOCL::procElemCount
protected

◆ queue

cl::CommandQueue Qrack::QEngineOCL::queue
protected

◆ queue_mutex

std::mutex Qrack::QEngineOCL::queue_mutex
protected

◆ stateBuffer

BufferPtr Qrack::QEngineOCL::stateBuffer
protected

◆ stateVec

complex* Qrack::QEngineOCL::stateVec
protected

◆ unlockHostMem

bool Qrack::QEngineOCL::unlockHostMem
protected

◆ usingHostRam

bool Qrack::QEngineOCL::usingHostRam
protected

◆ wait_queue_items

std::list<QueueItem> Qrack::QEngineOCL::wait_queue_items
protected

◆ wait_refs

std::vector<EventVecPtr> Qrack::QEngineOCL::wait_refs
protected

The documentation for this class was generated from the following files: