83 :
QInterface(qBitCount, rgp, doNorm, useHardwareRNG, randomGlobalPhase, norm_thresh)
90 throw std::invalid_argument(
91 "Cannot instantiate a register with greater capacity than native types on emulating system.");
162 virtual bool ForceM(
bitLenInt qubitIndex,
bool result,
bool doForce =
true,
bool doApply =
true);
163 virtual bitCapInt ForceM(
const std::vector<bitLenInt>& bits,
const std::vector<bool>& values,
bool doApply =
true);
170 ApplyM(qPower, powerTest, nrm);
246 bitLenInt length,
const std::vector<bitLenInt>& controls)
251 bitLenInt length,
const std::vector<bitLenInt>& controls)
296 dest->SetQubitCount(length);
301 virtual std::map<bitCapInt, int>
MultiShotMeasureMask(
const std::vector<bitCapInt>& qPowers,
unsigned shots);
303 const std::vector<bitCapInt>& qPowers,
unsigned shots,
unsigned long long* shotsArray);
Abstract QEngine implementation, for all "Schroedinger method" engines.
Definition: qengine.hpp:31
virtual void SetQubitCount(bitLenInt qb)
Definition: qengine.hpp:111
virtual void CIMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Inverse of controlled multiplication modulo N by integer, (out of place)
Definition: qengine.hpp:250
double fidelity
Definition: qengine.hpp:41
virtual void ApplyAntiControlled2x2(const std::vector< bitLenInt > &controls, bitLenInt target, const complex *mtrx)
Definition: qengine.cpp:388
virtual void Copy(QInterfacePtr orig)
Definition: qengine.hpp:71
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qengine.cpp:212
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qengine.cpp:543
virtual void ApplyControlled2x2(const std::vector< bitLenInt > &controls, bitLenInt target, const complex *mtrx)
Definition: qengine.cpp:372
virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt &permutation)=0
Direct measure of register permutation probability.
virtual void SwitchHostPtr(bool useHostMem)
Switch to/from host/device state vector bufffer.
Definition: qengine.hpp:125
virtual ~QEngine()
Definition: qengine.hpp:104
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC (without sign, with carry)
Definition: qengine.hpp:231
virtual void CISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary control bits.
Definition: qengine.cpp:318
virtual void ApplyM(const bitCapInt ®Mask, const bitCapInt &result, const complex &nrm)=0
virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse square root of Swap gate.
Definition: gates.cpp:224
void EitherMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target, bool isAnti)
Definition: qengine.cpp:29
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qengine.hpp:205
virtual void SetDevice(int64_t dID)
Set GPU device ID.
Definition: qengine.hpp:129
virtual void Mtrx(const complex *mtrx, bitLenInt qubit)
Apply an arbitrary single bit unitary transformation.
Definition: qengine.cpp:19
virtual void CSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary control bits.
Definition: qengine.cpp:265
virtual void ApplyM(const bitCapInt &qPower, bool result, const complex &nrm)
Definition: qengine.hpp:167
virtual void UCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target, const bitCapInt &controlPerm)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits,...
Definition: qengine.cpp:50
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 real1_f CProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |1>.
Definition: qengine.hpp:279
bool IsInvert(const complex *mtrx)
Definition: qengine.hpp:44
virtual void SetAmplitudePage(const complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from pagePtr into this QEngine's internal state.
virtual real1_f ACProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |0>.
Definition: qengine.hpp:280
virtual void AntiCISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary (anti) control bits.
Definition: qengine.cpp:346
bitCapIntOcl maxQPowerOcl
Definition: qengine.hpp:40
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual real1_f ProbMask(const bitCapInt &mask, const bitCapInt &permutation)=0
Direct measure of masked permutation probability.
virtual void IISwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse ISwap - Swap values of two bits in register, and apply phase factor of -i if bits are differe...
Definition: gates.cpp:189
virtual void ResetHostPtr()
Reset host/device state vector bufffer usage to default.
Definition: qengine.hpp:127
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.
Definition: qengine.cpp:78
virtual void MULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: qengine.hpp:235
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qengine.hpp:201
virtual void IMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: qengine.hpp:240
virtual void ISwap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register, and apply phase factor of i if bits are different.
Definition: gates.cpp:177
virtual void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: qengine.hpp:160
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qengine.hpp:209
bool useHostRam
Definition: qengine.hpp:36
virtual void CopyStateVec(QEnginePtr src)=0
Exactly copy the state vector of a different QEngine instance.
virtual void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qengine.cpp:240
virtual int64_t GetDevice()
Get GPU device ID.
Definition: qengine.hpp:131
virtual bool IsZeroAmplitude()=0
Returns "true" only if amplitudes are all totally 0.
virtual void Apply2x2(bitCapIntOcl offset1, bitCapIntOcl offset2, const complex *mtrx, bitLenInt bitCount, bitCapIntOcl const *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)=0
virtual void Copy(QEnginePtr orig)
Definition: qengine.hpp:72
bool IsIdentity(const complex *mtrx, bool isControlled)
Definition: qengine.hpp:46
virtual QEnginePtr CloneEmpty()=0
Clone this QEngine's settings, with a zeroed state vector.
virtual void ZeroAmplitudes()=0
Set all amplitudes to 0, and optionally temporarily deallocate state vector RAM.
virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Square root of Swap gate.
Definition: gates.cpp:201
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qengine.hpp:293
virtual void QueueSetDoNormalize(bool doNorm)=0
Add an operation to the (OpenCL) queue, to set the value of doNormalize, which controls whether to au...
virtual bool M(bitLenInt q)
Definition: qengine.hpp:194
virtual real1_f GetRunningNorm()
Get in-flight renormalization factor.
Definition: qengine.hpp:118
virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
Definition: qinterface.hpp:2389
virtual void SetAmplitudePage(QEnginePtr pageEnginePtr, bitCapIntOcl srcOffset, bitCapIntOcl dstOffset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from another QEngine, pointed to by pageEnginePtr, into this QEngine's in...
virtual void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qengine.hpp:217
virtual void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qengine.hpp:213
virtual real1_f CtrlOrAntiProb(bool controlState, bitLenInt control, bitLenInt target)
Definition: qengine.cpp:463
virtual void MACMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary (anti-)control bits.
Definition: qengine.hpp:179
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qengine.hpp:221
virtual void ProbRegAll(bitLenInt start, bitLenInt length, real1 *probsArray)
Definition: qengine.cpp:479
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)
Definition: qengine.hpp:81
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:166
virtual void GetAmplitudePage(complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from this QEngine's internal state, into pagePtr.
virtual bitCapInt ForceMReg(bitLenInt start, bitLenInt length, const bitCapInt &result, bool doForce=true, bool doApply=true)
Measure permutation state of a register.
Definition: qengine.cpp:490
virtual void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
Definition: qengine.hpp:175
virtual void QueueSetRunningNorm(real1_f runningNrm)=0
Add an operation to the (OpenCL) queue, to set the value of runningNorm, which is the normalization c...
bool IsPhase(const complex *mtrx)
Definition: qengine.hpp:43
virtual void ShuffleBuffers(QEnginePtr engine)=0
Swap the high half of this engine with the low half of another.
virtual void X(bitLenInt q)
Definition: qengine.hpp:196
virtual void CMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication modulo N by integer, (out of place)
Definition: qengine.hpp:245
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qengine.hpp:197
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract integer (without sign, with controls)
Definition: qengine.hpp:226
virtual real1_f GetExpectation(bitLenInt valueStart, bitLenInt valueLength)=0
QEngine()
Default constructor, primarily for protected internal use.
Definition: qengine.hpp:96
virtual real1_f ProbAll(const bitCapInt &fullRegister)
Direct measure of full permutation probability.
Definition: qengine.hpp:270
virtual void AntiCSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary (anti) control bits.
Definition: qengine.cpp:293
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:141
bitCapInt maxQPower
Definition: qinterface.hpp:149
bool randGlobalPhase
Definition: qinterface.hpp:144
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:268
static real1_f clampProb(real1_f toClamp)
Definition: qinterface.hpp:158
bool doNormalize
Definition: qinterface.hpp:143
virtual complex GetAmplitude(const bitCapInt &perm)=0
Get the representational amplitude of a full permutation.
Definition: qparity.hpp:22
Half-precision floating-point type.
Definition: half.hpp:2222
virtual void MULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:127
virtual void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Subtract a classical integer from the register, with sign and without carry.
Definition: qinterface.hpp:2200
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC.
Definition: arithmetic.cpp:53
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: arithmetic.cpp:79
virtual void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qinterface.hpp:2189
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qinterface.hpp:2163
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2141
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: arithmetic.cpp:20
virtual void IMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:165
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract classical integer (without sign, with controls)
Definition: qinterface.hpp:2181
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qinterface.hpp:2151
virtual void CMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:201
virtual void CIMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Inverse of controlled multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:240
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1091
virtual void PhaseParity(real1_f radians, const bitCapInt &mask)
Parity phase gate.
Definition: gates.cpp:399
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual bool M(bitLenInt qubit)
Measurement gate.
Definition: qinterface.hpp:1020
virtual void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qinterface.hpp:2850
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qinterface.hpp:2992
virtual void NormalizeState(real1_f nrm=REAL1_DEFAULT_ARG, real1_f norm_thresh=REAL1_DEFAULT_ARG, real1_f phaseArg=ZERO_R1_F)=0
Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate.
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
std::shared_ptr< QEngine > QEnginePtr
Definition: qrack_types.hpp:159
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
std::complex< real1 > complex
Definition: qrack_types.hpp:136
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:122
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:208
QRACK_CONST complex ONE_CMPLX
Definition: qrack_types.hpp:262
QRACK_CONST real1 ONE_R1
Definition: qrack_types.hpp:193
float real1_f
Definition: qrack_types.hpp:103
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:186
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:138
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:144
#define IS_SAME(c1, c2)
Definition: qrack_types.hpp:30
#define bitsInByte
Definition: qrack_types.hpp:162
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:185
#define bitLenInt
Definition: qrack_types.hpp:42
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:164
#define bitCapInt
Definition: qrack_types.hpp:66
#define bitCapIntOcl
Definition: qrack_types.hpp:54
#define IS_NORM_0(c)
Definition: qrack_types.hpp:29