21 #define bitLenInt uint8_t 22 #define bitCapInt uint64_t 29 #define complex std::complex<float> 32 #define polar(A, B) std::polar(A, B) 35 #define complex Complex16Simd 37 #define min_norm 1e-15 121 const bitCapInt* qPowersSorted,
bool doCalcNorm) = 0;
133 : doNormalize(doNorm)
134 , rand_distribution(0.0, 1.0)
139 rand_generator = std::make_shared<std::default_random_engine>();
140 randomSeed = std::time(0);
143 rand_generator = rgp;
199 virtual std::map<QInterfacePtr, bitLenInt>
Cohere(std::vector<QInterfacePtr> toCopy);
496 virtual void RTDyad(
int numerator,
int denomPower,
bitLenInt qubitIndex);
510 virtual void RXDyad(
int numerator,
int denomPower,
bitLenInt qubitIndex);
596 virtual void RYDyad(
int numerator,
int denomPower,
bitLenInt qubitIndex);
627 virtual void RZDyad(
int numerator,
int denomPower,
bitLenInt qubitIndex);
1001 bitLenInt length,
bool clearCarry =
false) = 0;
1092 bitLenInt valueLength,
unsigned char* values) = 0;
1163 while ((first < last) && (first < (last - 1))) {
1183 virtual void CopyState(QInterfacePtr orig) = 0;
1219 virtual bool ForceM(
bitLenInt qubitIndex,
bool result,
bool doForce =
true,
real1 nrmlzr = 1.0);
Create a QEngineOCL, derived from QEngineCPU, leveraging OpenCL hardware to increase the speed of cer...
Definition: qinterface.hpp:64
virtual void INC(bitCapInt toAdd, bitLenInt start, bitLenInt length)=0
Add integer (without sign)
virtual void SetQuantumState(complex *inputState)=0
Set an arbitrary pure quantum state.
virtual void ApplyControlled2x2(bitLenInt control, bitLenInt target, const complex *mtrx, bool doCalcNorm)
Definition: protected.cpp:46
virtual void CRTDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction "phase shift gate".
Definition: qinterface.cpp:534
QInterface(bitLenInt n, std::shared_ptr< std::default_random_engine > rgp=nullptr, bool doNorm=true)
Definition: qinterface.hpp:132
virtual void OR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "OR" gate.
Definition: operators.cpp:97
virtual void ExpYDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction Pauli Y exponentiation gate.
Definition: qinterface.cpp:358
virtual void INCS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)=0
Add a classical integer to the register, with sign and without carry.
virtual void CRY(real1 radians, bitLenInt control, bitLenInt target)
Controlled Y axis rotation gate.
Definition: rotational.cpp:111
virtual void RXDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction X axis rotation gate.
Definition: qinterface.cpp:432
virtual void CDIV(bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt controlBit, bitLenInt length)=0
Controlled division by power of integer.
virtual void LSL(bitLenInt shift, bitLenInt start, bitLenInt length)
Logical shift left, filling the extra bits with |0>
Definition: qinterface.cpp:171
virtual void RY(real1 radians, bitLenInt qubitIndex)
Y axis rotation gate.
Definition: rotational.cpp:36
virtual void ROL(bitLenInt shift, bitLenInt start, bitLenInt length)
Circular shift left - shift bits left, and carry last bits.
Definition: qinterface.cpp:659
virtual void DIV(bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)=0
Divide by integer.
virtual void CMUL(bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt controlBit, bitLenInt length, bool clearCarry=false)=0
Controlled multiplication by integer.
virtual void CRT(real1 radians, bitLenInt control, bitLenInt target)
Controlled "phase shift gate".
Definition: rotational.cpp:87
virtual void ASL(bitLenInt shift, bitLenInt start, bitLenInt length)
Arithmetic shift left, with last 2 bits as sign and carry.
Definition: qinterface.cpp:139
virtual void X(bitLenInt qubitIndex)
X gate.
Definition: gates.cpp:147
virtual void ApplyAntiControlled2x2(bitLenInt control, bitLenInt target, const complex *mtrx, bool doCalcNorm)
Definition: protected.cpp:57
virtual void H(bitLenInt qubitIndex)
Hadamard gate.
Definition: gates.cpp:137
virtual void CRX(real1 radians, bitLenInt control, bitLenInt target)
Controlled X axis rotation gate.
Definition: rotational.cpp:100
virtual void DECS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)=0
Subtract a classical integer from the register, with sign and without carry.
virtual void CCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target)
Doubly-controlled NOT gate.
Definition: gates.cpp:78
virtual void ApplySingleBit(const complex *mtrx, bool doCalcNorm, bitLenInt qubitIndex)
Apply an arbitrary single bit unitary transformation.
Definition: protected.cpp:39
real1 runningNorm
Definition: qinterface.hpp:103
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:110
virtual void INCBCDC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Add classical BCD integer (without sign, with carry)
virtual void CLAND(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "AND" gate.
Definition: operators.cpp:134
virtual void RZDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction Z axis rotation gate.
Definition: qinterface.cpp:503
bitCapInt maxQPower
Definition: qinterface.hpp:102
Definition: qinterface.hpp:86
virtual void CLXOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "XOR" gate.
Definition: operators.cpp:152
#define real1
Definition: qinterface.hpp:36
virtual void Decohere(bitLenInt start, bitLenInt length, QInterfacePtr dest)=0
Minimally decohere a set of contiguous bits from the full coherent unit, into "destination.".
virtual void Z(bitLenInt qubitIndex)
Z gate.
Definition: gates.cpp:165
virtual void CRZDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction Z axis rotation gate.
Definition: qinterface.cpp:632
virtual void RT(real1 radians, bitLenInt qubitIndex)
Phase shift gate.
Definition: rotational.cpp:18
uint32_t randomSeed
Definition: qinterface.hpp:106
virtual void DECC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Subtract classical integer (without sign, with carry)
virtual void ExpX(real1 radians, bitLenInt qubitIndex)
Pauli X exponentiation gate.
Definition: rotational.cpp:62
virtual void XOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "XOR" gate.
Definition: operators.cpp:116
virtual void NormalizeState(real1 nrm=-999.0)=0
virtual void RTDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction phase shift gate.
Definition: qinterface.cpp:245
virtual void ExpXDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction Pauli X exponentiation gate.
Definition: qinterface.cpp:320
virtual void ExpDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction (identity) exponentiation gate.
Definition: qinterface.cpp:282
#define complex
Definition: qinterface.hpp:35
virtual void RYDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction Y axis rotation gate.
Definition: qinterface.cpp:468
virtual void SetPermutation(bitCapInt perm)=0
Set to a specific permutation.
virtual bool M(bitLenInt qubitIndex)
Measurement gate.
Definition: gates.cpp:50
virtual void ApplyDoublyAntiControlled2x2(bitLenInt control1, bitLenInt control2, bitLenInt target, const complex *mtrx, bool doCalcNorm)
Definition: protected.cpp:82
virtual real1 Rand()
Generate a random real1 from 0 to 1.
Definition: qinterface.hpp:117
virtual void ROR(bitLenInt shift, bitLenInt start, bitLenInt length)
Circular shift right - shift bits right, and carry first bits.
Definition: qinterface.cpp:671
virtual bitLenInt Cohere(QInterfacePtr toCopy)=0
Combine another QInterface with this one, after the last bit index of this one.
virtual void DECSC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)=0
Subtract a classical integer from the register, with sign and with carry.
QInterfaceEngine
Enumerated list of supported engines.
Definition: qinterface.hpp:54
virtual void MUL(bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, bool clearCary=false)=0
Multiply by integer.
virtual void CRXDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction X axis rotation gate.
Definition: qinterface.cpp:568
#define bitCapInt
Definition: qinterface.hpp:22
virtual void ApplyDoublyControlled2x2(bitLenInt control1, bitLenInt control2, bitLenInt target, const complex *mtrx, bool doCalcNorm)
Definition: protected.cpp:68
std::shared_ptr< std::default_random_engine > rand_generator
Definition: qinterface.hpp:107
Definition: qinterface.hpp:89
virtual void SetRandomSeed(uint32_t seed)
Definition: qinterface.hpp:118
virtual void ExpY(real1 radians, bitLenInt qubitIndex)
Pauli Y exponentiation gate.
Definition: rotational.cpp:70
#define bitLenInt
Definition: qinterface.hpp:21
virtual ~QInterface()
Destructor of QInterface.
Definition: qinterface.hpp:148
virtual void DEC(bitCapInt toSub, bitLenInt start, bitLenInt length)=0
Subtract classical integer (without sign)
Definition: qinterface.hpp:82
virtual void ASR(bitLenInt shift, bitLenInt start, bitLenInt length)
Arithmetic shift right, with last 2 bits as sign and carry.
Definition: qinterface.cpp:155
int GetMaxQPower()
Get the maximum number of basis states, namely for qubits.
Definition: qinterface.hpp:154
virtual real1 Prob(bitLenInt qubitIndex)=0
Direct measure of bit probability to be in |1> state.
virtual void CopyState(QInterfacePtr orig)=0
Direct copy of raw state vector to produce a clone.
virtual void DECBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length)=0
Subtract BCD integer (without sign)
virtual void CNOT(bitLenInt control, bitLenInt target)
Controlled NOT gate.
Definition: gates.cpp:111
virtual void AND(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "AND" gate.
Definition: operators.cpp:78
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:99
virtual void SetBit(bitLenInt qubitIndex1, bool value)
Set individual bit to pure |0> (false) or |1> (true) state.
Definition: gates.cpp:53
bool doNormalize
Definition: qinterface.hpp:104
bitLenInt qubitCount
Definition: qinterface.hpp:101
Create a QUnit, which utilizes other QInterface classes to minimize the amount of work that's needed ...
Definition: qinterface.hpp:80
virtual void CRZ(real1 radians, bitLenInt control, bitLenInt target)
Controlled Z axis rotation gate.
Definition: rotational.cpp:122
virtual void Apply2x2(bitCapInt offset1, bitCapInt offset2, const complex *mtrx, const bitLenInt bitCount, const bitCapInt *qPowersSorted, bool doCalcNorm)=0
virtual void RZ(real1 radians, bitLenInt qubitIndex)
Z axis rotation gate.
Definition: rotational.cpp:45
virtual void CY(bitLenInt control, bitLenInt target)
Controlled Y gate.
Definition: gates.cpp:174
virtual void ApplyM(bitCapInt qPower, bool result, complex nrm)=0
virtual void DECBCDC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Subtract BCD integer (without sign, with carry)
virtual void INCC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Add integer (without sign, with carry)
virtual real1 ProbAll(bitCapInt fullRegister)=0
Direct measure of full register probability to be in permutation state.
std::uniform_real_distribution< real1 > rand_distribution
Definition: qinterface.hpp:108
virtual void AntiCNOT(bitLenInt control, bitLenInt target)
Anti controlled NOT gate.
Definition: gates.cpp:124
virtual void CRYDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction y axis rotation gate.
Definition: qinterface.cpp:601
virtual void RX(real1 radians, bitLenInt qubitIndex)
X axis rotation gate.
Definition: rotational.cpp:27
virtual void Y(bitLenInt qubitIndex)
Y gate.
Definition: gates.cpp:156
virtual bool ForceM(bitLenInt qubitIndex, bool result, bool doForce=true, real1 nrmlzr=1.0)
Act as though a measurement was applied, except force the result of the measurement.
Definition: gates.cpp:22
virtual void ExpZDyad(int numerator, int denomPower, bitLenInt qubitIndex)
Dyadic fraction Pauli Z exponentiation gate.
Definition: qinterface.cpp:386
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:46
virtual void CZ(bitLenInt control, bitLenInt target)
Controlled Z gate.
Definition: gates.cpp:185
virtual void Dispose(bitLenInt start, bitLenInt length)=0
Minimally decohere a set of contigious bits from the full coherent unit, throwing these qubits away...
Definition: complex16simd.hpp:21
virtual void ExpZ(real1 radians, bitLenInt qubitIndex)
Pauli Z exponentiation gate.
Definition: rotational.cpp:79
virtual void INCBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length)=0
Add classical BCD integer (without sign)
virtual void LSR(bitLenInt shift, bitLenInt start, bitLenInt length)
Logical shift right, filling the extra bits with |0>
Definition: qinterface.cpp:184
Create a QEngineOCLMUlti, composed from multiple QEngineOCLs, using OpenCL in parallel across 2^N dev...
Definition: qinterface.hpp:70
int GetQubitCount()
Get the count of bits in this register.
Definition: qinterface.hpp:151
virtual void AntiCCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target)
Anti doubly-controlled NOT gate.
Definition: gates.cpp:95
virtual void CLOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "OR" gate.
Definition: operators.cpp:142
virtual void Exp(real1 radians, bitLenInt qubitIndex)
(Identity) Exponentiation gate
Definition: rotational.cpp:54
virtual void INCSC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)=0
Add a classical integer to the register, with sign and with carry.
Create a QEngineCPU leveraging only local CPU and memory resources.
Definition: qinterface.hpp:59