103 return (
double)
clampProb((N + P0 + P1) / 2) * 2;
113 throw std::runtime_error(
"QUnit fidelity estimate is effectively 0! (This DOES NOT mean your fidelity is "
114 "necessarily close to 0! Please read the Qrack README, and then, afterward, "
115 "consider setting environment variable QRACK_DISABLE_QUNIT_FIDELITY_GUARD=1.)");
123 const bool ptHi = pth > pc;
124 const real1_f pHi = ptHi ? pth : pc;
125 const real1_f pLo = ptHi ? pc : pth;
151 bool randomGlobalPhase =
true,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
157 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool ignored =
false,
161 useHostMem, deviceId, useHardwareRNG, ignored, norm_thresh, devIDs, qubitThreshold, separation_thresh)
172 std::vector<int64_t> unused4) {
173 unit->SetConcurrency((uint32_t)threadsPerEngine);
184 std::vector<int64_t> unused4) {
185 unit->SetTInjection((
bool)useGadget);
196 std::vector<int64_t> unused4) {
197 unit->SetUseExactNearClifford((
bool)useExact);
208 std::vector<int64_t> unused4) {
209 unit->SetSparseProbabilityFloor(p);
226 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::ProbRdm!");
234 return shard.
unit->ProbRdm(qubit);
246 CNOT(control, target);
248 CNOT(control, target);
253 virtual bool AreFactorized(std::vector<bitLenInt> a, std::vector<bitLenInt> b,
bool flushCache =
false)
255 std::set<QInterfacePtr> aUnits;
266 std::set<QInterfacePtr> bUnits;
279 auto it1 = aUnits.begin();
280 auto it2 = bUnits.begin();
282 while (it1 != aUnits.end() && it2 != bUnits.end()) {
285 }
else if (*it2 < *it1) {
307 throw std::domain_error(
"QUnit::SetAmplitude called for 0 qubits!");
311 throw std::invalid_argument(
"QUnit::SetAmplitude argument out-of-bounds!");
315 shards[0
U].unit->SetAmplitude(perm, amp);
324 throw std::invalid_argument(
"QUnit::Compose start index is out-of-bounds!");
330 QUnitPtr clone = std::dynamic_pointer_cast<QUnit>(toCopy->Clone());
332 clone->ToPermBasisAll();
343 return Compose(std::dynamic_pointer_cast<QUnit>(toCopy), start);
347 Decompose(start, std::dynamic_pointer_cast<QUnit>(dest));
363 Detach(start, length,
nullptr);
367 return TryDecompose(start, std::dynamic_pointer_cast<QUnit>(dest), error_tol);
371 return Detach(start, dest->GetQubitCount(), dest,
true, error_tol);
398 UCPhase(controls, topLeft, bottomRight, target, m);
405 UCInvert(controls, topRight, bottomLeft, target, m);
417 virtual void UCPhase(
const std::vector<bitLenInt>& controls,
const complex& topLeft,
const complex& bottomRight,
419 virtual void UCInvert(
const std::vector<bitLenInt>& controls,
const complex& topRight,
const complex& bottomLeft,
426 UCMtrx(controls, mtrx, target, m);
436 const complex* mtrxs,
const std::vector<bitCapInt>& mtrxSkipPowers,
const bitCapInt& mtrxSkipValueMask);
445 virtual bool ForceM(
bitLenInt qubitIndex,
bool result,
bool doForce =
true,
bool doApply =
true);
451 virtual std::map<bitCapInt, int>
MultiShotMeasureMask(
const std::vector<bitCapInt>& qPowers,
unsigned shots);
453 const std::vector<bitCapInt>& qPowers,
unsigned shots,
unsigned long long* shotsArray);
502 bitLenInt length,
const std::vector<bitLenInt>& controls)
507 bitLenInt length,
const std::vector<bitLenInt>& controls)
529 const std::vector<bitLenInt>& controls);
531 const std::vector<bitLenInt>& controls);
533 bitLenInt length,
const std::vector<bitLenInt>& controls);
535 bitLenInt valueLength,
const unsigned char* values,
bool resetValue =
true);
557 throw std::invalid_argument(
"QUnit::Swap qubit index parameter must be within allocated qubit bounds!");
561 throw std::invalid_argument(
"QUnit::Swap qubit index parameter must be within allocated qubit bounds!");
564 if (qubit1 == qubit2) {
587 throw std::invalid_argument(
"QUnit::Prob target parameter must be within allocated qubit bounds!");
597 throw std::domain_error(
"QUnit::ProbAllRdm called for 0 qubits!");
602 return shards[0
U].unit->ProbAllRdm(roundRz, perm);
607 clone->OrderContiguous(unit);
609 return unit->ProbAllRdm(roundRz, perm);
615 return SumSqrDiff(std::dynamic_pointer_cast<QUnit>(toCompare));
619 const std::vector<bitLenInt>& bits,
const std::vector<bitCapInt>& perms,
const bitCapInt& offset =
ZERO_BCI)
621 return ExpVarFactorized(
true,
false,
false, bits, perms, std::vector<real1_f>(), offset,
false);
626 return ExpVarFactorized(
true,
true,
false, bits, perms, std::vector<real1_f>(), offset, roundRz);
629 const std::vector<bitLenInt>& bits,
const std::vector<bitCapInt>& perms,
const bitCapInt& offset =
ZERO_BCI)
631 return ExpVarFactorized(
false,
false,
false, bits, perms, std::vector<real1_f>(), offset,
false);
636 return ExpVarFactorized(
false,
true,
false, bits, perms, std::vector<real1_f>(), offset, roundRz);
649 shard.unit =
nullptr;
656 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::isClifford!");
659 return shards[qubit].isClifford();
667 for (
size_t i = 0
U; i < qubits.size(); ++i) {
680 for (
bitLenInt i = qubits.size(); i > 0
U; --i) {
698 std::vector<int64_t> unused4) {
718 throw std::invalid_argument(
"QUnit::XBase qubit index parameter must be within allocated qubit bounds!");
733 throw std::invalid_argument(
"QUnit::YBase qubit index parameter must be within allocated qubit bounds!");
750 throw std::invalid_argument(
"QUnit::ZBase qubit index parameter must be within allocated qubit bounds!");
774 std::vector<bitLenInt> controlVec = std::vector<bitLenInt>());
781 bitLenInt length, std::vector<bitLenInt>* controlsMapped);
785 std::vector<bitLenInt> controlVec);
787 bitLenInt length, std::vector<bitLenInt> controlVec);
793 bitLenInt valueLength,
const unsigned char* values);
798 const std::vector<bitCapInt>& perms,
const std::vector<real1_f>& weights,
const bitCapInt& offset,
bool roundRz)
801 throw std::domain_error(
"QUnit::ProbAllRdm called for 0 qubits!");
804 if ((isFloat && (weights.size() < bits.size())) || (!isFloat && (perms.size() < bits.size()))) {
805 throw std::invalid_argument(
"QUnit::ExpectationFactorized() must supply at least as many weights as bits!");
809 "QUnit::ExpectationFactorized parameter qubits vector values must be within allocated qubit bounds!");
813 return isExp ? isFloat
814 ? (isRdm ?
shards[0
U].unit->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
815 :
shards[0
U].unit->ExpectationFloatsFactorized(bits, weights))
816 : (isRdm ?
shards[0
U].unit->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
817 :
shards[0
U].unit->ExpectationBitsFactorized(bits, perms, offset))
818 : isFloat ? (isRdm ?
shards[0
U].unit->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
819 :
shards[0
U].unit->VarianceFloatsFactorized(bits, weights))
820 : (isRdm ?
shards[0
U].unit->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset)
821 :
shards[0
U].unit->VarianceBitsFactorized(bits, perms, offset));
826 clone->OrderContiguous(unit);
828 return isExp ? isFloat ? (isRdm ? unit->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
829 : unit->ExpectationFloatsFactorized(bits, weights))
830 : (isRdm ? unit->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
831 : unit->ExpectationBitsFactorized(bits, perms, offset))
832 : isFloat ? (isRdm ? unit->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
833 : unit->VarianceFloatsFactorized(bits, weights))
834 : (isRdm ? unit->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset)
835 : unit->VarianceBitsFactorized(bits, perms, offset));
859 std::vector<bitLenInt*>::iterator first, std::vector<bitLenInt*>::iterator last);
862 std::vector<int64_t> param5);
864 real1_f param3 =
ZERO_R1_F, int64_t param4 = 0, std::vector<int64_t> param5 = {});
881 bool TrimControls(
const std::vector<bitLenInt>& controls, std::vector<bitLenInt>& controlVec,
bitCapInt* perm);
883 template <
typename CF>
884 void ApplyEitherControlled(std::vector<bitLenInt> controlVec,
const std::vector<bitLenInt> targets, CF cfn,
885 bool isPhase,
const bitCapInt& controlPerm,
const double payloadInfidelity);
890 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::ClampShard!");
911 mtrxOut[0
U] =
HALF_R1 * (mtrxIn[0
U] + mtrxIn[1U] + mtrxIn[2U] + mtrxIn[3U]);
912 mtrxOut[1U] =
HALF_R1 * (mtrxIn[0
U] - mtrxIn[1U] + mtrxIn[2U] - mtrxIn[3U]);
913 mtrxOut[2U] =
HALF_R1 * (mtrxIn[0
U] + mtrxIn[1U] - mtrxIn[2U] - mtrxIn[3U]);
914 mtrxOut[3U] =
HALF_R1 * (mtrxIn[0
U] - mtrxIn[1U] - mtrxIn[2U] + mtrxIn[3U]);
919 mtrxOut[0
U] =
HALF_R1 * (topRight + bottomLeft);
920 mtrxOut[1U] =
HALF_R1 * (-topRight + bottomLeft);
921 mtrxOut[2U] = -mtrxOut[1U];
922 mtrxOut[3U] = -mtrxOut[0
U];
927 mtrxOut[0
U] =
HALF_R1 * (mtrxIn[0
U] +
I_CMPLX * (mtrxIn[1U] - mtrxIn[2U]) + mtrxIn[3U]);
928 mtrxOut[1U] =
HALF_R1 * (mtrxIn[0
U] -
I_CMPLX * (mtrxIn[1U] + mtrxIn[2U]) - mtrxIn[3U]);
929 mtrxOut[2U] =
HALF_R1 * (mtrxIn[0
U] +
I_CMPLX * (mtrxIn[1U] + mtrxIn[2U]) - mtrxIn[3U]);
930 mtrxOut[3U] =
HALF_R1 * (mtrxIn[0
U] -
I_CMPLX * (mtrxIn[1U] - mtrxIn[2U]) + mtrxIn[3U]);
937 mtrxOut[2U] = -mtrxOut[1U];
938 mtrxOut[3U] = -mtrxOut[0
U];
943 mtrxOut[0
U] =
HALF_R1 * (topLeft + bottomRight);
944 mtrxOut[1U] =
HALF_R1 * (topLeft - bottomRight);
945 mtrxOut[2U] = mtrxOut[1U];
946 mtrxOut[3U] = mtrxOut[0
U];
952 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisX!");
968 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisY!");
996 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
997 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1004 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasis1Qb!");
1019 throw std::invalid_argument(
1020 "Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisToX1Qb!");
1034 throw std::invalid_argument(
1035 "Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisToY1Qb!");
1049 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertZToX!");
1068 shard.
amp1 = tempAmp1;
1074 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertXToY!");
1096 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1097 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1103 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertYToZ!");
1124 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1125 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1131 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertZToY!");
1152 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1153 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1159 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::ShardAI!");
1168 complex mtrx[4U]{ cosineI, -expNegA * sineI, expA * sineI, cosineI };
1174 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1175 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1185 bool isAnti,
const std::set<bitLenInt>& exceptPartners,
bool dumpSkipped);
1188 const std::set<bitLenInt>& exceptControlling = {},
const std::set<bitLenInt>& exceptTargetedBy = {},
1189 bool dumpSkipped =
false,
bool skipOptimized =
false);
1194 throw std::invalid_argument(
1195 "Qubit index " + std::to_string(i) +
" out of range in QUnit::Flush0Eigenstate!");
1208 throw std::invalid_argument(
1209 "Qubit index " + std::to_string(i) +
" out of range in QUnit::Flush1Eigenstate!");
1255 shards[qubit].DumpMultiBit();
1263 throw std::invalid_argument(
1264 "Qubit index " + std::to_string(start + length) +
" out of range in QUnit::DirtyShardRange!");
1268 shards[start + i].MakeDirty();
1275 throw std::invalid_argument(
1276 "Qubit index " + std::to_string(start + length) +
" out of range in QUnit::DirtyShardRangePhase!");
1280 shards[start + i].isPhaseDirty =
true;
1286 for (
const bitLenInt& bitIndex : bitIndices) {
1288 throw std::invalid_argument(
1289 "Qubit index " + std::to_string(bitIndex) +
" out of range in QUnit::DirtyShardRangePhase!");
1292 shards[bitIndex].MakeDirty();
1299 throw std::invalid_argument(
1300 "Qubit index " + std::to_string(target) +
" out of range in QUnit::EndEmulation!");
1315 shard.
unit->SetQuantumState(bitState);
1321 shard->
found =
true;
1324 shard->
found =
false;
1328 shard->
found =
false;
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:238
int bi_compare(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:126
Definition: qengineshard.hpp:316
std::vector< QEngineShard > shards
Definition: qengineshard.hpp:318
bitLenInt size()
Definition: qengineshard.hpp:352
void swap(bitLenInt qubit1, bitLenInt qubit2)
Definition: qengineshard.hpp:388
void insert(bitLenInt start, QEngineShardMap &toInsert)
Definition: qengineshard.hpp:360
Associates a QInterface object with a set of bits.
Definition: qengineshard.hpp:50
void DumpControlOf()
Definition: qengineshard.hpp:163
complex amp0
Definition: qengineshard.hpp:63
bool ClampAmps()
Definition: qengineshard.cpp:26
bitLenInt mapped
Definition: qengineshard.hpp:60
bool isProbDirty
Definition: qengineshard.hpp:61
void DumpAntiControlOf()
Definition: qengineshard.hpp:164
QInterfacePtr unit
Definition: qengineshard.hpp:59
Pauli pauliBasis
Definition: qengineshard.hpp:65
complex amp1
Definition: qengineshard.hpp:64
void DumpSamePhaseAntiControlOf()
Definition: qengineshard.hpp:172
bool found
Definition: qengineshard.hpp:75
void DumpSamePhaseControlOf()
Definition: qengineshard.hpp:168
bool isPhaseDirty
Definition: qengineshard.hpp:62
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
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:275
real1 amplitudeFloor
Definition: qinterface.hpp:148
bool useRDRAND
Definition: qinterface.hpp:145
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:488
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:382
qrack_rand_gen_ptr rand_generator
Definition: qinterface.hpp:150
bool randGlobalPhase
Definition: qinterface.hpp:144
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:268
static real1_f clampProb(real1_f toClamp)
Definition: qinterface.hpp:158
bitLenInt qubitCount
Definition: qinterface.hpp:146
bool doNormalize
Definition: qinterface.hpp:143
Definition: qparity.hpp:22
void ConvertYToZ(bitLenInt i)
Definition: qunit.hpp:1100
void ToPermBasisAll()
Definition: qunit.hpp:1247
bool useExactNC
Definition: qunit.hpp:37
virtual void SetReactiveSeparate(bool isAggSep)
Set reactive separation option (on by default if available)
Definition: qunit.hpp:215
std::vector< int64_t > deviceIDs
Definition: qunit.hpp:53
void CMULx(CMULFn fn, const bitCapInt &toMod, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > controlVec)
Definition: qunit.cpp:3385
void OptimizePairBuffers(bitLenInt control, bitLenInt target, bool anti)
Definition: qunit.cpp:4288
virtual void YBase(bitLenInt target)
Definition: qunit.hpp:730
void ApplyEitherControlled(std::vector< bitLenInt > controlVec, const std::vector< bitLenInt > targets, CF cfn, bool isPhase, const bitCapInt &controlPerm, const double payloadInfidelity)
Definition: qunit.cpp:2666
void OrderContiguous(QInterfacePtr unit)
Definition: qunit.cpp:857
virtual complex GetAmplitudeOrProb(const bitCapInt &perm, bool isProb)
Definition: qunit.cpp:257
double PhaseInfidelity(const complex &p)
Definition: qunit.hpp:79
real1_f ExpVarFactorized(bool isExp, bool isRdm, bool isFloat, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const std::vector< real1_f > &weights, const bitCapInt &offset, bool roundRz)
Definition: qunit.hpp:797
void INTS(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex, bool hasCarry)
Definition: qunit.cpp:3148
bool ParallelUnitApply(ParallelUnitFn fn, real1_f param1=ZERO_R1_F, real1_f param2=ZERO_R1_F, real1_f param3=ZERO_R1_F, int64_t param4=0, std::vector< int64_t > param5={})
Definition: qunit.cpp:3739
void(QAlu::* INCxFn)(const bitCapInt &, bitLenInt, bitLenInt, bitLenInt)
Definition: qunit.hpp:768
void Flush1Eigenstate(bitLenInt i)
Definition: qunit.hpp:1205
QInterfacePtr MakeEngine(bitLenInt length, const bitCapInt &perm)
Definition: qunit.cpp:140
void SortUnit(QInterfacePtr unit, std::vector< QSortEntry > &bits, bitLenInt low, bitLenInt high)
Sort a container of bits, calling Swap() on each.
Definition: qunit.cpp:883
void ToPermBasisProb(bitLenInt qubit)
Definition: qunit.hpp:1233
virtual QInterfacePtr EntangleInCurrentBasis(std::vector< bitLenInt * >::iterator first, std::vector< bitLenInt * >::iterator last)
Definition: qunit.cpp:431
double PayloadInfidelityFactor3(const complex m[4U])
Definition: qunit.hpp:85
virtual bool CheckBitsPermutation(bitLenInt start, bitLenInt length=1)
Check if all qubits in the range have cached probabilities indicating that they are in permutation ba...
Definition: qunit.cpp:924
bool useTGadget
Definition: qunit.hpp:36
virtual void X(bitLenInt q)
Definition: qunit.hpp:461
virtual QInterfacePtr Entangle(std::vector< bitLenInt > bits)
Definition: qunit.cpp:545
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:488
virtual void EitherISwap(bitLenInt qubit1, bitLenInt qubit2, bool isInverse)
Definition: qunit.cpp:1793
void RevertBasis1Qb(bitLenInt i)
Definition: qunit.hpp:1001
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qunit.hpp:350
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:1052
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:1045
virtual real1_f CProbRdm(bitLenInt control, bitLenInt target)
Definition: qunit.hpp:236
real1_f separabilityThreshold
Definition: qunit.hpp:46
void ToPermBasisProb()
Definition: qunit.hpp:1248
virtual real1_f ProbBase(bitLenInt qubit)
Definition: qunit.cpp:976
virtual void GetQuantumState(complex *outputState)
Get the pure quantum state representation.
Definition: qunit.hpp:300
virtual void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubit, const complex *mtrxs)
Apply a "uniformly controlled" arbitrary single bit unitary transformation.
Definition: qinterface.hpp:645
virtual bitCapInt ForceMReg(bitLenInt start, bitLenInt length, const bitCapInt &result, bool doForce=true, bool doApply=true)
Act as if is a measurement was applied, except force the (usually random) result.
Definition: qinterface.cpp:215
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:382
virtual bool ForceM(bitLenInt qubit, bool result, bool doForce=true, bool doApply=true)=0
Act as if is a measurement was applied, except force the (usually random) result.
real1_f roundingThreshold
Definition: qunit.hpp:47
virtual bool CheckBitsPlus(bitLenInt qubitIndex, bitLenInt length)
Definition: qunit.cpp:963
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qunit.hpp:320
void ToPermBasisAllMeasure()
Definition: qunit.cpp:2820
complex phaseFactor
Definition: qunit.hpp:51
void CheckFidelity()
Definition: qunit.hpp:106
void INT(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex, bool hasCarry, std::vector< bitLenInt > controlVec=std::vector< bitLenInt >())
Definition: qunit.cpp:2939
virtual void H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:931
virtual bool SeparateBit(bool value, bitLenInt qubit)
Definition: qunit.cpp:1350
bool isReactiveSeparate
Definition: qunit.hpp:35
real1_f sparse_thresh
Definition: qunit.hpp:48
void(QAlu::* CMULModFn)(const bitCapInt &, const bitCapInt &, bitLenInt, bitLenInt, bitLenInt, const std::vector< bitLenInt > &)
Definition: qunit.hpp:771
virtual void SetTInjection(bool useGadget)
Set the option to use T-injection gadgets (off by default)
Definition: qunit.hpp:179
virtual QInterfacePtr EntangleRange(bitLenInt start, bitLenInt length, bool isForProb=false)
Definition: qunit.cpp:565
virtual bool TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Attempt to Decompose() a bit range.
Definition: qunit.hpp:365
virtual void LossySaveStateVector(std::string f, int p=6, int b=4)
Write the quantum state to disk with lossy compression.
Definition: qunit_turboquant.cpp:105
virtual bool Detach(bitLenInt start, bitLenInt length, QUnitPtr dest, bool isTry=false, real1_f tol=TRYDECOMPOSE_EPSILON)
Definition: qunit.cpp:300
void ShardAI(bitLenInt qubit, real1_f azimuth, real1_f inclination)
Definition: qunit.hpp:1156
virtual void GetProbs(real1 *outputProbs)
Get the pure quantum state representation.
Definition: qunit.hpp:301
void ClampShard(bitLenInt qubit)
Definition: qunit.hpp:887
virtual void Decompose(bitLenInt start, QInterfacePtr dest)
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
Definition: qunit.hpp:345
bool isAce
Definition: qunit.hpp:42
virtual bool M(bitLenInt q)
Definition: qunit.hpp:459
void TransformPhase(const complex &topLeft, const complex &bottomRight, complex *mtrxOut)
Definition: qunit.hpp:941
virtual void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qunit.cpp:3793
bitLenInt thresholdQubits
Definition: qunit.hpp:45
void DirtyShardIndexVector(std::vector< bitLenInt > bitIndices)
Definition: qunit.hpp:1284
bool INTSOptimize(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt overflowIndex)
Check if overflow arithmetic can be optimized.
Definition: qunit.cpp:2881
void ConvertZToY(bitLenInt i)
Definition: qunit.hpp:1128
std::vector< QInterfaceEngine > engines
Definition: qunit.hpp:54
void RevertBasisY(bitLenInt i)
Definition: qunit.hpp:965
virtual bool GetReactiveSeparate()
Get reactive separation option.
Definition: qunit.hpp:216
bool TrimControls(const std::vector< bitLenInt > &controls, std::vector< bitLenInt > &controlVec, bitCapInt *perm)
Definition: qunit.cpp:2549
virtual void SetDeviceList(std::vector< int64_t > dIDs)
Set the device index list, if more than one device is available.
Definition: qunit.cpp:3805
virtual ~QUnit()
Definition: qunit.hpp:165
double logFidelity
Definition: qunit.hpp:49
QUnit(bitLenInt qBitCount, const bitCapInt &initState=ZERO_BCI, qrack_rand_gen_ptr rgp=nullptr, const complex &phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t deviceId=-1, bool useHardwareRNG=true, bool ignored=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > devIDs={}, bitLenInt qubitThreshold=0U, real1_f separation_thresh=_qrack_qunit_sep_thresh)
Definition: qunit.hpp:155
void ToPermBasis(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1224
RevertAnti
Definition: qunit.hpp:1181
@ ONLY_ANTI
Definition: qunit.hpp:1181
@ CTRL_AND_ANTI
Definition: qunit.hpp:1181
@ ONLY_CTRL
Definition: qunit.hpp:1181
void RevertBasisToX1Qb(bitLenInt i)
Definition: qunit.hpp:1016
void CMULModx(CMULModFn fn, const bitCapInt &toMod, const bitCapInt &modN, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > controlVec)
Definition: qunit.cpp:3398
virtual void SetAmplitude(const bitCapInt &perm, const complex &)
Sets the representational amplitude of a full permutation.
Definition: qunit.hpp:304
void ApplyBuffer(PhaseShardPtr phaseShard, bitLenInt control, bitLenInt target, bool isAnti)
Definition: qunit.cpp:3940
virtual void Dispose(bitLenInt start, bitLenInt length)
Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separa...
Definition: qunit.hpp:360
int64_t devID
Definition: qunit.hpp:50
void RevertBasis2Qb(bitLenInt i, RevertExclusivity exclusivity=INVERT_AND_PHASE, RevertControl controlExclusivity=CONTROLS_AND_TARGETS, RevertAnti antiExclusivity=CTRL_AND_ANTI, const std::set< bitLenInt > &exceptControlling={}, const std::set< bitLenInt > &exceptTargetedBy={}, bool dumpSkipped=false, bool skipOptimized=false)
Definition: qunit.cpp:4129
virtual void SetUseExactNearClifford(bool useExact)
Set the option to use exact-method near-Clifford simulation (on by default)
Definition: qunit.hpp:191
virtual bool TrySeparateClifford(bitLenInt qubit)
Definition: qunit.cpp:663
bool isCpu
Definition: qunit.hpp:39
bool freezeBasis2Qb
Definition: qunit.hpp:33
bool isSinglePage
Definition: qunit.hpp:40
virtual bitCapInt GetCachedPermutation(bitLenInt start, bitLenInt length)
Assuming all bits in the range are in cached |0>/|1> eigenstates, read the unsigned integer value of ...
Definition: qunit.cpp:941
bool(* ParallelUnitFn)(QInterfacePtr unit, real1_f param1, real1_f param2, real1_f param3, int64_t param4, std::vector< int64_t > param5)
Definition: qunit.hpp:861
virtual QInterfacePtr CloneBody(QUnitPtr copyPtr, bool isCopy)
Definition: qunit.cpp:3907
virtual int64_t GetDevice()
Get the device index.
Definition: qunit.hpp:220
void RevertBasisToY1Qb(bitLenInt i)
Definition: qunit.hpp:1031
void DirtyShardRange(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1260
QInterfacePtr CMULEntangle(std::vector< bitLenInt > controlVec, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > *controlsMapped)
Definition: qunit.cpp:3349
virtual void XBase(bitLenInt target)
Definition: qunit.hpp:715
bitLenInt aceQubits
Definition: qunit.hpp:44
void ElideCz(const bool &isAnti, const bitLenInt &control, const bitLenInt &target, const real1_f &pth, const real1_f &pc)
Definition: qunit.hpp:119
void ToPermBasisProb(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1238
void TransformX2x2(const complex mtrxIn[4U], complex mtrxOut[4U])
Definition: qunit.hpp:909
virtual bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Compose() a QInterface peer, inserting its qubit into index order at start index.
Definition: qunit.hpp:341
void ToPermBasis(bitLenInt i)
Definition: qunit.hpp:1219
virtual bool TryDecompose(bitLenInt start, QUnitPtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Definition: qunit.hpp:369
virtual complex GetAmplitude(const bitCapInt &perm)
Get the representational amplitude of a full permutation.
Definition: qunit.cpp:255
virtual void SetSparseProbabilityFloor(real1_f p)
Set the sparse-simulation amplitude probability floor, before truncation.
Definition: qunit.hpp:203
virtual real1_f ACProbRdm(bitLenInt control, bitLenInt target)
Definition: qunit.hpp:244
virtual void SetPermutation(const bitCapInt &perm, const complex &phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qunit.cpp:153
virtual bool AreFactorized(std::vector< bitLenInt > a, std::vector< bitLenInt > b, bool flushCache=false)
Check if two vectors of qubit indices are factorized, in internal representation.
Definition: qunit.hpp:253
bitLenInt FindShardIndex(QEngineShardPtr shard)
Definition: qunit.hpp:1319
RevertControl
Definition: qunit.hpp:1180
@ ONLY_TARGETS
Definition: qunit.hpp:1180
@ CONTROLS_AND_TARGETS
Definition: qunit.hpp:1180
@ ONLY_CONTROLS
Definition: qunit.hpp:1180
virtual QInterfacePtr EntangleAll(bool isForProb=false)
Definition: qunit.hpp:844
void ToPermBasisMeasure(bitLenInt qubit)
Definition: qunit.hpp:1249
bitCapInt GetIndexedEigenstate(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, const unsigned char *values)
Definition: qunit.cpp:3495
virtual void Copy(QInterfacePtr orig)
Definition: qunit.hpp:58
bool INTCOptimize(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt carryIndex)
Check if carry arithmetic can be optimized.
Definition: qunit.cpp:2887
std::vector< bitLenInt > CMULEntangle(std::vector< bitLenInt > controlVec, bitLenInt start, const bitCapInt &carryStart, bitLenInt length)
virtual void GetQuantumStateOrProbs(complex *outputState, real1 *outputProbs)
Definition: qunit.cpp:215
virtual bitLenInt Compose(QUnitPtr toCopy)
Definition: qunit.hpp:319
virtual std::vector< int64_t > GetDeviceList()
Get the device index.
Definition: qunit.hpp:221
virtual void Decompose(bitLenInt start, QUnitPtr dest)
Definition: qunit.hpp:349
void TransformXInvert(const complex &topRight, const complex &bottomLeft, complex mtrxOut[4U])
Definition: qunit.hpp:917
void INCxx(INCxxFn fn, const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt flag1Index, bitLenInt flag2Index)
Definition: qunit.cpp:2852
void INCx(INCxFn fn, const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
Definition: qunit.cpp:2833
QUnit(std::vector< QInterfaceEngine > eng, bitLenInt qBitCount, const bitCapInt &initState=ZERO_BCI, qrack_rand_gen_ptr rgp=nullptr, const complex &phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t deviceId=-1, bool useHardwareRNG=true, bool ignored=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > devIDs={}, bitLenInt qubitThreshold=0U, real1_f separation_thresh=_qrack_qunit_sep_thresh)
Definition: qunit.cpp:73
virtual void Copy(QUnitPtr orig)
Definition: qunit.hpp:59
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qunit.hpp:167
void ConvertZToX(bitLenInt i)
Definition: qunit.hpp:1046
bool isSparse
Definition: qunit.hpp:41
void CommuteH(bitLenInt bitIndex)
Definition: qunit.cpp:4185
virtual bool TrySeparate(const std::vector< bitLenInt > &qubits, real1_f error_tol)
Qrack::QUnit types maintain explicit separation of representations of qubits, which reduces memory us...
Definition: qinterface.hpp:2925
void ApplyBufferMap(bitLenInt bitIndex, ShardToPhaseMap bufferMap, RevertExclusivity exclusivity, bool isControl, bool isAnti, const std::set< bitLenInt > &exceptPartners, bool dumpSkipped)
Definition: qunit.cpp:4062
void(QAlu::* INCxxFn)(const bitCapInt &, bitLenInt, bitLenInt, bitLenInt, bitLenInt)
Definition: qunit.hpp:769
virtual void Dispose(bitLenInt start, bitLenInt length, const bitCapInt &disposedPerm)
Dispose a a contiguous set of qubits that are already in a permutation eigenstate.
Definition: qunit.hpp:361
void ConvertXToY(bitLenInt i)
Definition: qunit.hpp:1071
RevertExclusivity
Definition: qunit.hpp:1179
@ ONLY_INVERT
Definition: qunit.hpp:1179
@ ONLY_PHASE
Definition: qunit.hpp:1179
@ INVERT_AND_PHASE
Definition: qunit.hpp:1179
virtual bitLenInt Compose(QUnitPtr toCopy, bitLenInt start)
Definition: qunit.hpp:321
virtual real1_f ProbRdm(bitLenInt qubit)
Direct measure of bit probability to be in |1> state, treating all ancillary qubits as post-selected ...
Definition: qunit.hpp:223
void DirtyShardRangePhase(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1272
void Flush0Eigenstate(bitLenInt i)
Definition: qunit.hpp:1191
bool isBdt
Definition: qunit.hpp:38
virtual void LossyLoadStateVector(std::string f)
Read the quantum state from disk with lossy compression.
Definition: qunit_turboquant.cpp:227
QEngineShardMap shards
Definition: qunit.hpp:52
size_t aceMb
Definition: qunit.hpp:43
bool INTSCOptimize(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt carryIndex, bitLenInt overflowIndex)
Check if arithmetic with both carry and overflow can be optimized.
Definition: qunit.cpp:2893
void TransformY2x2(const complex mtrxIn[4U], complex mtrxOut[4U])
Definition: qunit.hpp:925
bool useHostRam
Definition: qunit.hpp:34
void EndEmulation(bitLenInt target)
Definition: qunit.hpp:1296
void(QAlu::* CMULFn)(const bitCapInt &, bitLenInt, bitLenInt, bitLenInt, const std::vector< bitLenInt > &)
Definition: qunit.hpp:770
virtual void SetQuantumState(const complex *inputState)
Set an arbitrary pure quantum state representation.
Definition: qunit.cpp:166
void TransformYInvert(const complex &topRight, const complex &bottomLeft, complex mtrxOut[4U])
Definition: qunit.hpp:933
void RevertBasisX(bitLenInt i)
Definition: qunit.hpp:949
virtual void ZBase(bitLenInt target)
Definition: qunit.hpp:747
Half-precision floating-point type.
Definition: half.hpp:2206
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 bitCapInt IndexedLDA(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, const unsigned char *values, bool resetValue=true)
Set 8 bit register bits by a superposed index-offset-based read from classical memory.
Definition: qunit.cpp:3520
virtual void POWModNOut(const bitCapInt &base, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Raise a classical base to a quantum power, modulo N, (out of place)
Definition: qunit.cpp:3318
virtual void CMUL(const bitCapInt &toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication by integer.
Definition: qunit.cpp:3410
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:2225
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: qunit.hpp:473
virtual bitCapInt IndexedADC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)
Add to entangled 8 bit register state with a superposed index-offset-based read from classical memory...
Definition: qunit.cpp:3556
virtual void INCDECBCDC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (without overflow flag)
Definition: qunit.cpp:3241
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 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: qunit.hpp:501
virtual void CPhaseFlipIfLess(const 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.
Definition: qunit.cpp:3698
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 INCBCD(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add classical BCD integer (without sign)
Definition: qunit.cpp:3219
virtual void Hash(bitLenInt start, bitLenInt length, const unsigned char *values)
Transform a length of qubit register via lookup through a hash table.
Definition: qunit.cpp:3658
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qunit.cpp:3119
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2166
virtual void CDIV(const bitCapInt &toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled division by power of integer.
Definition: qunit.cpp:3439
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qunit.cpp:3125
virtual void DECBCD(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Subtract classical BCD integer (without sign)
Definition: qunit.cpp:3230
virtual void MULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: qunit.hpp:491
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract integer (without sign, with carry)
Definition: qunit.cpp:3136
virtual void CPOWModNOut(const bitCapInt &base, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled, raise a classical base to a quantum power, modulo N, (out of place)
Definition: qunit.cpp:3468
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qunit.hpp:469
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qunit.hpp:477
virtual bitCapInt IndexedSBC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)
Subtract from an entangled 8 bit register state with a superposed index-offset-based read from classi...
Definition: qunit.cpp:3607
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: qunit.cpp:3202
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 MUL(const bitCapInt &toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Multiply by integer.
Definition: qunit.cpp:3248
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:2206
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: qunit.hpp:506
virtual void PhaseFlipIfLess(const bitCapInt &greaterPerm, bitLenInt start, bitLenInt length)
This is an expedient for an adaptive Grover's search for a function's global minimum.
Definition: qunit.cpp:3678
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 IMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: qunit.hpp:496
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC (without sign, with carry)
Definition: qunit.hpp:487
virtual void INCDECSC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (with overflow flag)
Definition: qunit.cpp:3207
virtual void DIV(const bitCapInt &toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Divide by integer.
Definition: qunit.cpp:3282
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract integer (without sign, with controls)
Definition: qunit.hpp:482
virtual void MCMtrx(const std::vector< bitLenInt > &controls, const complex mtrx[4U], bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
Definition: qunit.hpp:422
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qunit.cpp:2519
virtual void MACPhase(const std::vector< bitLenInt > &controls, const complex &topLeft, const complex &bottomRight, bitLenInt target)
Apply a single bit transformation that only effects phase, with arbitrary (anti-)control bits.
Definition: qunit.hpp:407
virtual void CNOT(bitLenInt control, bitLenInt target)
Controlled NOT gate.
Definition: qinterface.hpp:727
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:1052
virtual void MACInvert(const std::vector< bitLenInt > &controls, const complex &topRight, const complex &bottomLeft, bitLenInt target)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qunit.hpp:412
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:1045
virtual void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubit, const complex *mtrxs)
Apply a "uniformly controlled" arbitrary single bit unitary transformation.
Definition: qinterface.hpp:645
virtual bool ForceM(bitLenInt qubit, bool result, bool doForce=true, bool doApply=true)=0
Act as if is a measurement was applied, except force the (usually random) result.
virtual void UCMtrx(const std::vector< bitLenInt > &controls, const complex mtrx[4U], bitLenInt target, const bitCapInt &controlPerm)
Definition: qunit.cpp:2488
virtual void H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:931
virtual void MCPhase(const std::vector< bitLenInt > &controls, const complex &topLeft, const complex &bottomRight, bitLenInt target)
Apply a single bit transformation that only effects phase, with arbitrary control bits.
Definition: qunit.hpp:393
virtual bitCapInt HighestProbAll()
Get highest probability permutation.
Definition: qunit.cpp:1501
virtual void MACMtrx(const std::vector< bitLenInt > &controls, const complex mtrx[4U], bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary (anti-)control bits.
Definition: qunit.hpp:428
virtual void AntiCSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary (anti) control bits.
Definition: qunit.cpp:2534
virtual void Mtrx(const complex mtrx[4U], bitLenInt qubit)
Apply an arbitrary single bit unitary transformation.
Definition: qunit.cpp:2433
virtual void CSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary control bits.
Definition: qunit.cpp:2529
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1116
virtual void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: qunit.hpp:388
virtual void AntiCNOT(bitLenInt control, bitLenInt target)
Anti controlled NOT gate.
Definition: qinterface.hpp:738
virtual void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qunit.cpp:2524
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: qunit.cpp:2544
virtual void UCInvert(const std::vector< bitLenInt > &controls, const complex &topRight, const complex &bottomLeft, bitLenInt target, const bitCapInt &controlPerm)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qunit.cpp:2371
virtual void CUniformParityRZ(const std::vector< bitLenInt > &controls, const bitCapInt &mask, real1_f angle)
If the controls are set and the target qubit set parity is odd, this applies a phase factor of .
Definition: qunit.cpp:1242
virtual void PhaseParity(real1_f radians, const bitCapInt &mask)
Parity phase gate.
Definition: qunit.cpp:1043
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual void MCInvert(const std::vector< bitLenInt > &controls, const complex &topRight, const complex &bottomLeft, bitLenInt target)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qunit.hpp:400
virtual void Phase(const complex &topLeft, const complex &bottomRight, bitLenInt qubitIndex)
Apply a single bit transformation that only effects phase.
Definition: qunit.cpp:2191
virtual void Invert(const complex &topRight, const complex &bottomLeft, bitLenInt qubitIndex)
Apply a single bit transformation that reverses bit probability and might effect phase.
Definition: qunit.cpp:2251
virtual bool M(bitLenInt qubit)
Measurement gate.
Definition: qinterface.hpp:1031
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qunit.cpp:1583
virtual bitCapInt MAll()
Measure permutation state of all coherent bits.
Definition: qunit.cpp:1534
virtual void UCPhase(const std::vector< bitLenInt > &controls, const complex &topLeft, const complex &bottomRight, bitLenInt target, const bitCapInt &controlPerm)
Apply a single bit transformation that only effects phase, with arbitrary control bits,...
Definition: qunit.cpp:2303
virtual void CISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary control bits.
Definition: qunit.cpp:2539
virtual void SetNcrp(real1_f ncrp)
Set the "Near-clifford rounding parameter" value, (between 0 and 1)
Definition: qunit.hpp:693
virtual real1_f VarianceBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qunit.hpp:628
virtual real1_f ExpectationBitsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get (reduced density matrix) expectation value of bits, given an array of qubit weights.
Definition: qunit.hpp:623
virtual bool TrySeparate(const std::vector< bitLenInt > &qubits, real1_f error_tol)
Qrack::QUnit types maintain explicit separation of representations of qubits, which reduces memory us...
Definition: qunit.hpp:665
virtual bool isClifford()
Returns "true" if current state is identifiably within the Clifford set, or "false" if it is not or c...
Definition: qinterface.hpp:2899
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 ...
Definition: qunit.cpp:3756
virtual real1_f ProbParity(const bitCapInt &mask)
Overall probability of any odd permutation of the masked set of bits.
Definition: qunit.cpp:1119
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qunit.cpp:3898
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qinterface.hpp:3058
virtual real1_f SumSqrDiff(QInterfacePtr toCompare)
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
Definition: qunit.hpp:613
virtual bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qunit.cpp:3787
virtual void SetSparseAceMaxMb(size_t mb)
Set the (sparse-simulation) "automatic circuit elision" (ACE) maximum memory megabytes.
Definition: qunit.hpp:705
virtual real1_f ExpectationBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qunit.hpp:618
virtual bool isClifford(bitLenInt qubit)
Returns "true" if current qubit state is identifiably within the Clifford set, or "false" if it is no...
Definition: qunit.hpp:653
virtual QInterfacePtr Clone()
Clone this QInterface.
Definition: qunit.cpp:3890
virtual real1_f ProbAllRdm(bool roundRz, const bitCapInt &perm)
Direct measure of full permutation probability, treating all ancillary qubits as post-selected T gate...
Definition: qunit.hpp:594
virtual void NormalizeState(real1_f nrm=REAL1_DEFAULT_ARG, real1_f norm_thresh=REAL1_DEFAULT_ARG, real1_f phaseArg=ZERO_R1_F)
Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate.
Definition: qunit.cpp:3767
virtual real1_f VarianceBitsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get (reduced density matrix) expectation value of bits, given an array of qubit weights.
Definition: qunit.hpp:633
virtual double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qunit.cpp:3724
virtual void SetSdrp(real1_f sdrp)
Set the "Schmidt decomposition rounding parameter" value, (between 0 and 1)
Definition: qunit.hpp:688
virtual real1_f ProbAll(const bitCapInt &perm)
Direct measure of full permutation probability.
Definition: qunit.hpp:593
virtual real1_f Prob(bitLenInt qubit)
Direct measure of bit probability to be in |1> state.
Definition: qunit.hpp:584
virtual void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qunit.hpp:687
virtual void SetAceMaxQubits(bitLenInt qb)
Set the "automatic circuit elision" (ACE) maximum entangled subsystem qubit count.
Definition: qunit.hpp:704
virtual void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qunit.hpp:643
virtual bool TrySeparate(const std::vector< bitLenInt > &qubits, real1_f error_tol)
Qrack::QUnit types maintain explicit separation of representations of qubits, which reduces memory us...
Definition: qinterface.hpp:2925
virtual void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qunit.cpp:3778
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 (usual...
Definition: qunit.cpp:1177
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
void ThrowIfQbIdArrayIsBad(const std::vector< bitLenInt > &controls, const bitLenInt &qubitCount, std::string message)
Definition: qrack_functions.hpp:198
QRACK_CONST real1_f FP_NORM_EPSILON_F
Definition: qrack_types.hpp:264
QRACK_CONST real1 SQRT1_2_R1
Definition: qrack_types.hpp:182
@ QINTERFACE_STABILIZER_HYBRID
Create a QStabilizerHybrid, switching between a QStabilizer and a QHybrid as efficient.
Definition: qinterface.hpp:77
std::shared_ptr< QUnit > QUnitPtr
Definition: qunit.hpp:24
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:258
QRACK_CONST real1_f TRYDECOMPOSE_EPSILON
Definition: qrack_types.hpp:265
QRACK_CONST real1 HALF_R1
Definition: qrack_types.hpp:187
std::shared_ptr< PhaseShard > PhaseShardPtr
Definition: qengineshard.hpp:46
half_float::half real1
Definition: qrack_types.hpp:106
std::complex< real1 > complex
Definition: qrack_types.hpp:140
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:263
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:156
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:122
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:203
QRACK_CONST complex ONE_CMPLX
Definition: qrack_types.hpp:257
QRACK_CONST real1 ONE_R1
Definition: qrack_types.hpp:188
QRACK_CONST real1 ZERO_R1
Definition: qrack_types.hpp:186
float real1_f
Definition: qrack_types.hpp:107
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:262
QRACK_CONST complex I_CMPLX
Definition: qrack_types.hpp:259
std::map< QEngineShardPtr, PhaseShardPtr > ShardToPhaseMap
Definition: qengineshard.hpp:47
@ PauliX
Pauli X operator. Corresponds to Q# constant "PauliX.".
Definition: pauli.hpp:23
@ PauliY
Pauli Y operator. Corresponds to Q# constant "PauliY.".
Definition: pauli.hpp:25
@ PauliZ
Pauli Z operator. Corresponds to Q# constant "PauliZ.".
Definition: pauli.hpp:27
const double FIDELITY_MIN
Definition: qrack_types.hpp:266
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:180
const bitCapInt ONE_BCI
Definition: qrack_types.hpp:141
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:142
HALF_CONSTEXPR half abs(half arg)
Absolute value.
Definition: half.hpp:2958
half sin(half arg)
Sine function.
Definition: half.hpp:3868
half log(half arg)
Natural logarithm.
Definition: half.hpp:3301
half cos(half arg)
Cosine function.
Definition: half.hpp:3905
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:179
#define QRACK_CONST
Definition: qrack_types.hpp:176
#define bitLenInt
Definition: qrack_types.hpp:41
#define ZERO_R1_F
Definition: qrack_types.hpp:162
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:158
#define bitCapInt
Definition: qrack_types.hpp:65
#define ONE_R1_F
Definition: qrack_types.hpp:165
#define IS_NORM_0(c)
Definition: qrack_types.hpp:28
Definition: qunit.hpp:873
bool operator<(const QSortEntry &rhs)
Definition: qunit.hpp:876
bitLenInt mapped
Definition: qunit.hpp:875
bool operator>(const QSortEntry &rhs)
Definition: qunit.hpp:877
bitLenInt bit
Definition: qunit.hpp:874