98 return (
double)
clampProb((N + P0 + P1) / 2) * 2;
108 throw std::runtime_error(
"QUnit fidelity estimate is effectively 0! (This DOES NOT mean your fidelity is "
109 "necessarily close to 0! Please read the Qrack README, and then, afterward, "
110 "consider setting environment variable QRACK_DISABLE_QUNIT_FIDELITY_GUARD=1.)");
118 const bool ptHi = pth > pc;
119 const real1_f pHi = ptHi ? pth : pc;
120 const real1_f pLo = ptHi ? pc : pth;
146 bool randomGlobalPhase =
true,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
152 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool ignored =
false,
156 useHostMem, deviceId, useHardwareRNG, ignored, norm_thresh, devIDs, qubitThreshold, separation_thresh)
167 std::vector<int64_t> unused4) {
168 unit->SetConcurrency((uint32_t)threadsPerEngine);
179 std::vector<int64_t> unused4) {
180 unit->SetTInjection((
bool)useGadget);
197 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::ProbRdm!");
205 return shard.
unit->ProbRdm(qubit);
217 CNOT(control, target);
219 CNOT(control, target);
232 throw std::domain_error(
"QUnit::SetAmplitude called for 0 qubits!");
236 throw std::invalid_argument(
"QUnit::SetAmplitude argument out-of-bounds!");
240 shards[0
U].unit->SetAmplitude(perm, amp);
249 throw std::invalid_argument(
"QUnit::Compose start index is out-of-bounds!");
255 QUnitPtr clone = std::dynamic_pointer_cast<QUnit>(toCopy->Clone());
257 clone->ToPermBasisAll();
268 return Compose(std::dynamic_pointer_cast<QUnit>(toCopy), start);
272 Decompose(start, std::dynamic_pointer_cast<QUnit>(dest));
288 Detach(start, length,
nullptr);
292 return TryDecompose(start, std::dynamic_pointer_cast<QUnit>(dest), error_tol);
296 return Detach(start, dest->GetQubitCount(), dest,
true, error_tol);
323 UCPhase(controls, topLeft, bottomRight, target, m);
330 UCInvert(controls, topRight, bottomLeft, target, m);
342 virtual void UCPhase(
const std::vector<bitLenInt>& controls,
const complex& topLeft,
const complex& bottomRight,
344 virtual void UCInvert(
const std::vector<bitLenInt>& controls,
const complex& topRight,
const complex& bottomLeft,
351 UCMtrx(controls, mtrx, target, m);
361 const complex* mtrxs,
const std::vector<bitCapInt>& mtrxSkipPowers,
const bitCapInt& mtrxSkipValueMask);
370 virtual bool ForceM(
bitLenInt qubitIndex,
bool result,
bool doForce =
true,
bool doApply =
true);
376 virtual std::map<bitCapInt, int>
MultiShotMeasureMask(
const std::vector<bitCapInt>& qPowers,
unsigned shots);
378 const std::vector<bitCapInt>& qPowers,
unsigned shots,
unsigned long long* shotsArray);
427 bitLenInt length,
const std::vector<bitLenInt>& controls)
432 bitLenInt length,
const std::vector<bitLenInt>& controls)
454 const std::vector<bitLenInt>& controls);
456 const std::vector<bitLenInt>& controls);
458 bitLenInt length,
const std::vector<bitLenInt>& controls);
460 bitLenInt valueLength,
const unsigned char* values,
bool resetValue =
true);
482 throw std::invalid_argument(
"QUnit::Swap qubit index parameter must be within allocated qubit bounds!");
486 throw std::invalid_argument(
"QUnit::Swap qubit index parameter must be within allocated qubit bounds!");
489 if (qubit1 == qubit2) {
512 throw std::invalid_argument(
"QUnit::Prob target parameter must be within allocated qubit bounds!");
522 throw std::domain_error(
"QUnit::ProbAllRdm called for 0 qubits!");
527 return shards[0
U].unit->ProbAllRdm(roundRz, perm);
532 clone->OrderContiguous(unit);
534 return unit->ProbAllRdm(roundRz, perm);
540 return SumSqrDiff(std::dynamic_pointer_cast<QUnit>(toCompare));
544 const std::vector<bitLenInt>& bits,
const std::vector<bitCapInt>& perms,
const bitCapInt& offset =
ZERO_BCI)
546 return ExpVarFactorized(
true,
false,
false, bits, perms, std::vector<real1_f>(), offset,
false);
551 return ExpVarFactorized(
true,
true,
false, bits, perms, std::vector<real1_f>(), offset, roundRz);
554 const std::vector<bitLenInt>& bits,
const std::vector<bitCapInt>& perms,
const bitCapInt& offset =
ZERO_BCI)
556 return ExpVarFactorized(
false,
false,
false, bits, perms, std::vector<real1_f>(), offset,
false);
561 return ExpVarFactorized(
false,
true,
false, bits, perms, std::vector<real1_f>(), offset, roundRz);
574 shard.unit =
nullptr;
581 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::isClifford!");
584 return shards[qubit].isClifford();
592 for (
size_t i = 0
U; i < qubits.size(); ++i) {
605 for (
bitLenInt i = qubits.size(); i > 0
U; --i) {
623 std::vector<int64_t> unused4) {
643 throw std::invalid_argument(
"QUnit::XBase qubit index parameter must be within allocated qubit bounds!");
658 throw std::invalid_argument(
"QUnit::YBase qubit index parameter must be within allocated qubit bounds!");
675 throw std::invalid_argument(
"QUnit::ZBase qubit index parameter must be within allocated qubit bounds!");
699 std::vector<bitLenInt> controlVec = std::vector<bitLenInt>());
706 bitLenInt length, std::vector<bitLenInt>* controlsMapped);
710 std::vector<bitLenInt> controlVec);
712 bitLenInt length, std::vector<bitLenInt> controlVec);
718 bitLenInt valueLength,
const unsigned char* values);
723 const std::vector<bitCapInt>& perms,
const std::vector<real1_f>& weights,
const bitCapInt& offset,
bool roundRz)
726 throw std::domain_error(
"QUnit::ProbAllRdm called for 0 qubits!");
729 if ((isFloat && (weights.size() < bits.size())) || (!isFloat && (perms.size() < bits.size()))) {
730 throw std::invalid_argument(
"QUnit::ExpectationFactorized() must supply at least as many weights as bits!");
734 "QUnit::ExpectationFactorized parameter qubits vector values must be within allocated qubit bounds!");
738 return isExp ? isFloat
739 ? (isRdm ?
shards[0
U].unit->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
740 :
shards[0
U].unit->ExpectationFloatsFactorized(bits, weights))
741 : (isRdm ?
shards[0
U].unit->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
742 :
shards[0
U].unit->ExpectationBitsFactorized(bits, perms, offset))
743 : isFloat ? (isRdm ?
shards[0
U].unit->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
744 :
shards[0
U].unit->VarianceFloatsFactorized(bits, weights))
745 : (isRdm ?
shards[0
U].unit->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset)
746 :
shards[0
U].unit->VarianceBitsFactorized(bits, perms, offset));
751 clone->OrderContiguous(unit);
753 return isExp ? isFloat ? (isRdm ? unit->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
754 : unit->ExpectationFloatsFactorized(bits, weights))
755 : (isRdm ? unit->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
756 : unit->ExpectationBitsFactorized(bits, perms, offset))
757 : isFloat ? (isRdm ? unit->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
758 : unit->VarianceFloatsFactorized(bits, weights))
759 : (isRdm ? unit->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset)
760 : unit->VarianceBitsFactorized(bits, perms, offset));
784 std::vector<bitLenInt*>::iterator first, std::vector<bitLenInt*>::iterator last);
787 std::vector<int64_t> param5);
789 real1_f param3 =
ZERO_R1_F, int64_t param4 = 0, std::vector<int64_t> param5 = {});
806 bool TrimControls(
const std::vector<bitLenInt>& controls, std::vector<bitLenInt>& controlVec,
bitCapInt* perm);
808 template <
typename CF>
809 void ApplyEitherControlled(std::vector<bitLenInt> controlVec,
const std::vector<bitLenInt> targets, CF cfn,
810 bool isPhase,
const bitCapInt& controlPerm,
const double payloadInfidelity);
815 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::ClampShard!");
836 mtrxOut[0
U] =
HALF_R1 * (mtrxIn[0
U] + mtrxIn[1U] + mtrxIn[2U] + mtrxIn[3U]);
837 mtrxOut[1U] =
HALF_R1 * (mtrxIn[0
U] - mtrxIn[1U] + mtrxIn[2U] - mtrxIn[3U]);
838 mtrxOut[2U] =
HALF_R1 * (mtrxIn[0
U] + mtrxIn[1U] - mtrxIn[2U] - mtrxIn[3U]);
839 mtrxOut[3U] =
HALF_R1 * (mtrxIn[0
U] - mtrxIn[1U] - mtrxIn[2U] + mtrxIn[3U]);
844 mtrxOut[0
U] =
HALF_R1 * (topRight + bottomLeft);
845 mtrxOut[1U] =
HALF_R1 * (-topRight + bottomLeft);
846 mtrxOut[2U] = -mtrxOut[1U];
847 mtrxOut[3U] = -mtrxOut[0
U];
852 mtrxOut[0
U] =
HALF_R1 * (mtrxIn[0
U] +
I_CMPLX * (mtrxIn[1U] - mtrxIn[2U]) + mtrxIn[3U]);
853 mtrxOut[1U] =
HALF_R1 * (mtrxIn[0
U] -
I_CMPLX * (mtrxIn[1U] + mtrxIn[2U]) - mtrxIn[3U]);
854 mtrxOut[2U] =
HALF_R1 * (mtrxIn[0
U] +
I_CMPLX * (mtrxIn[1U] + mtrxIn[2U]) - mtrxIn[3U]);
855 mtrxOut[3U] =
HALF_R1 * (mtrxIn[0
U] -
I_CMPLX * (mtrxIn[1U] - mtrxIn[2U]) + mtrxIn[3U]);
862 mtrxOut[2U] = -mtrxOut[1U];
863 mtrxOut[3U] = -mtrxOut[0
U];
868 mtrxOut[0
U] =
HALF_R1 * (topLeft + bottomRight);
869 mtrxOut[1U] =
HALF_R1 * (topLeft - bottomRight);
870 mtrxOut[2U] = mtrxOut[1U];
871 mtrxOut[3U] = mtrxOut[0
U];
877 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisX!");
893 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisY!");
921 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
922 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
929 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasis1Qb!");
944 throw std::invalid_argument(
945 "Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisToX1Qb!");
959 throw std::invalid_argument(
960 "Qubit index " + std::to_string(i) +
" out of range in QUnit::RevertBasisToY1Qb!");
974 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertZToX!");
993 shard.
amp1 = tempAmp1;
999 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertXToY!");
1021 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1022 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1028 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertYToZ!");
1049 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1050 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1056 throw std::invalid_argument(
"Qubit index " + std::to_string(i) +
" out of range in QUnit::ConvertZToY!");
1077 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1078 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1084 throw std::invalid_argument(
"Qubit index " + std::to_string(qubit) +
" out of range in QUnit::ShardAI!");
1093 complex mtrx[4U]{ cosineI, -expNegA * sineI, expA * sineI, cosineI };
1099 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * Y1);
1100 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * Y1);
1110 bool isAnti,
const std::set<bitLenInt>& exceptPartners,
bool dumpSkipped);
1113 const std::set<bitLenInt>& exceptControlling = {},
const std::set<bitLenInt>& exceptTargetedBy = {},
1114 bool dumpSkipped =
false,
bool skipOptimized =
false);
1119 throw std::invalid_argument(
1120 "Qubit index " + std::to_string(i) +
" out of range in QUnit::Flush0Eigenstate!");
1133 throw std::invalid_argument(
1134 "Qubit index " + std::to_string(i) +
" out of range in QUnit::Flush1Eigenstate!");
1180 shards[qubit].DumpMultiBit();
1188 throw std::invalid_argument(
1189 "Qubit index " + std::to_string(start + length) +
" out of range in QUnit::DirtyShardRange!");
1193 shards[start + i].MakeDirty();
1200 throw std::invalid_argument(
1201 "Qubit index " + std::to_string(start + length) +
" out of range in QUnit::DirtyShardRangePhase!");
1205 shards[start + i].isPhaseDirty =
true;
1211 for (
const bitLenInt& bitIndex : bitIndices) {
1213 throw std::invalid_argument(
1214 "Qubit index " + std::to_string(bitIndex) +
" out of range in QUnit::DirtyShardRangePhase!");
1217 shards[bitIndex].MakeDirty();
1224 throw std::invalid_argument(
1225 "Qubit index " + std::to_string(target) +
" out of range in QUnit::EndEmulation!");
1240 shard.
unit->SetQuantumState(bitState);
1246 shard->
found =
true;
1249 shard->
found =
false;
1253 shard->
found =
false;
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:237
int bi_compare(const BigInteger &left, const BigInteger &right)
Definition: big_integer.hpp:125
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:477
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:371
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:1025
void ToPermBasisAll()
Definition: qunit.hpp:1172
virtual void SetReactiveSeparate(bool isAggSep)
Set reactive separation option (on by default if available)
Definition: qunit.hpp:186
std::vector< int64_t > deviceIDs
Definition: qunit.hpp:50
void CMULx(CMULFn fn, const bitCapInt &toMod, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > controlVec)
Definition: qunit.cpp:3360
void OptimizePairBuffers(bitLenInt control, bitLenInt target, bool anti)
Definition: qunit.cpp:4251
virtual void YBase(bitLenInt target)
Definition: qunit.hpp:655
void ApplyEitherControlled(std::vector< bitLenInt > controlVec, const std::vector< bitLenInt > targets, CF cfn, bool isPhase, const bitCapInt &controlPerm, const double payloadInfidelity)
Definition: qunit.cpp:2647
void OrderContiguous(QInterfacePtr unit)
Definition: qunit.cpp:844
virtual complex GetAmplitudeOrProb(const bitCapInt &perm, bool isProb)
Definition: qunit.cpp:246
double PhaseInfidelity(const complex &p)
Definition: qunit.hpp:74
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:722
void INTS(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex, bool hasCarry)
Definition: qunit.cpp:3123
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:3714
void(QAlu::* INCxFn)(const bitCapInt &, bitLenInt, bitLenInt, bitLenInt)
Definition: qunit.hpp:693
void Flush1Eigenstate(bitLenInt i)
Definition: qunit.hpp:1130
QInterfacePtr MakeEngine(bitLenInt length, const bitCapInt &perm)
Definition: qunit.cpp:132
void SortUnit(QInterfacePtr unit, std::vector< QSortEntry > &bits, bitLenInt low, bitLenInt high)
Sort a container of bits, calling Swap() on each.
Definition: qunit.cpp:870
void ToPermBasisProb(bitLenInt qubit)
Definition: qunit.hpp:1158
virtual QInterfacePtr EntangleInCurrentBasis(std::vector< bitLenInt * >::iterator first, std::vector< bitLenInt * >::iterator last)
Definition: qunit.cpp:420
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:911
bool useTGadget
Definition: qunit.hpp:36
virtual void X(bitLenInt q)
Definition: qunit.hpp:386
virtual QInterfacePtr Entangle(std::vector< bitLenInt > bits)
Definition: qunit.cpp:532
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:477
virtual void EitherISwap(bitLenInt qubit1, bitLenInt qubit2, bool isInverse)
Definition: qunit.cpp:1780
void RevertBasis1Qb(bitLenInt i)
Definition: qunit.hpp:926
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qunit.hpp:275
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:1041
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:1034
virtual real1_f CProbRdm(bitLenInt control, bitLenInt target)
Definition: qunit.hpp:207
real1_f separabilityThreshold
Definition: qunit.hpp:44
void ToPermBasisProb()
Definition: qunit.hpp:1173
void TransformYInvert(const complex &topRight, const complex &bottomLeft, complex *mtrxOut)
Definition: qunit.hpp:858
virtual real1_f ProbBase(bitLenInt qubit)
Definition: qunit.cpp:963
virtual void GetQuantumState(complex *outputState)
Get the pure quantum state representation.
Definition: qunit.hpp:225
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:634
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:213
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:371
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:45
virtual bool CheckBitsPlus(bitLenInt qubitIndex, bitLenInt length)
Definition: qunit.cpp:950
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qunit.hpp:245
void ToPermBasisAllMeasure()
Definition: qunit.cpp:2795
complex phaseFactor
Definition: qunit.hpp:48
void CheckFidelity()
Definition: qunit.hpp:101
void INT(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex, bool hasCarry, std::vector< bitLenInt > controlVec=std::vector< bitLenInt >())
Definition: qunit.cpp:2914
virtual void H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:920
virtual bool SeparateBit(bool value, bitLenInt qubit)
Definition: qunit.cpp:1337
bool isReactiveSeparate
Definition: qunit.hpp:35
void(QAlu::* CMULModFn)(const bitCapInt &, const bitCapInt &, bitLenInt, bitLenInt, bitLenInt, const std::vector< bitLenInt > &)
Definition: qunit.hpp:696
virtual void SetTInjection(bool useGadget)
Set the option to use T-injection gadgets (off by default)
Definition: qunit.hpp:174
void TransformXInvert(const complex &topRight, const complex &bottomLeft, complex *mtrxOut)
Definition: qunit.hpp:842
virtual QInterfacePtr EntangleRange(bitLenInt start, bitLenInt length, bool isForProb=false)
Definition: qunit.cpp:552
virtual bool TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Attempt to Decompose() a bit range.
Definition: qunit.hpp:290
virtual bool Detach(bitLenInt start, bitLenInt length, QUnitPtr dest, bool isTry=false, real1_f tol=TRYDECOMPOSE_EPSILON)
Definition: qunit.cpp:289
void ShardAI(bitLenInt qubit, real1_f azimuth, real1_f inclination)
Definition: qunit.hpp:1081
virtual void GetProbs(real1 *outputProbs)
Get the pure quantum state representation.
Definition: qunit.hpp:226
void ClampShard(bitLenInt qubit)
Definition: qunit.hpp:812
virtual void Decompose(bitLenInt start, QInterfacePtr dest)
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
Definition: qunit.hpp:270
virtual bool M(bitLenInt q)
Definition: qunit.hpp:384
void TransformPhase(const complex &topLeft, const complex &bottomRight, complex *mtrxOut)
Definition: qunit.hpp:866
virtual void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qunit.cpp:3768
bitLenInt thresholdQubits
Definition: qunit.hpp:43
void DirtyShardIndexVector(std::vector< bitLenInt > bitIndices)
Definition: qunit.hpp:1209
bool INTSOptimize(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt overflowIndex)
Check if overflow arithmetic can be optimized.
Definition: qunit.cpp:2856
void ConvertZToY(bitLenInt i)
Definition: qunit.hpp:1053
std::vector< QInterfaceEngine > engines
Definition: qunit.hpp:51
void RevertBasisY(bitLenInt i)
Definition: qunit.hpp:890
virtual bool GetReactiveSeparate()
Get reactive separation option.
Definition: qunit.hpp:187
bool TrimControls(const std::vector< bitLenInt > &controls, std::vector< bitLenInt > &controlVec, bitCapInt *perm)
Definition: qunit.cpp:2530
virtual void SetDeviceList(std::vector< int64_t > dIDs)
Set the device index list, if more than one device is available.
Definition: qunit.cpp:3780
virtual ~QUnit()
Definition: qunit.hpp:160
double logFidelity
Definition: qunit.hpp:46
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:150
void ToPermBasis(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1149
RevertAnti
Definition: qunit.hpp:1106
@ ONLY_ANTI
Definition: qunit.hpp:1106
@ CTRL_AND_ANTI
Definition: qunit.hpp:1106
@ ONLY_CTRL
Definition: qunit.hpp:1106
void RevertBasisToX1Qb(bitLenInt i)
Definition: qunit.hpp:941
void CMULModx(CMULModFn fn, const bitCapInt &toMod, const bitCapInt &modN, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > controlVec)
Definition: qunit.cpp:3373
virtual void SetAmplitude(const bitCapInt &perm, const complex &)
Sets the representational amplitude of a full permutation.
Definition: qunit.hpp:229
void ApplyBuffer(PhaseShardPtr phaseShard, bitLenInt control, bitLenInt target, bool isAnti)
Definition: qunit.cpp:3913
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:285
int64_t devID
Definition: qunit.hpp:47
double PayloadInfidelityFactor3(const complex *m)
Definition: qunit.hpp:80
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:4092
virtual bool TrySeparateClifford(bitLenInt qubit)
Definition: qunit.cpp:650
bool isCpu
Definition: qunit.hpp:38
bool freezeBasis2Qb
Definition: qunit.hpp:33
bool isSinglePage
Definition: qunit.hpp:39
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:928
bool(* ParallelUnitFn)(QInterfacePtr unit, real1_f param1, real1_f param2, real1_f param3, int64_t param4, std::vector< int64_t > param5)
Definition: qunit.hpp:786
virtual QInterfacePtr CloneBody(QUnitPtr copyPtr, bool isCopy)
Definition: qunit.cpp:3882
virtual int64_t GetDevice()
Get the device index.
Definition: qunit.hpp:191
void RevertBasisToY1Qb(bitLenInt i)
Definition: qunit.hpp:956
void DirtyShardRange(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1185
QInterfacePtr CMULEntangle(std::vector< bitLenInt > controlVec, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > *controlsMapped)
Definition: qunit.cpp:3324
virtual void XBase(bitLenInt target)
Definition: qunit.hpp:640
bitLenInt aceQubits
Definition: qunit.hpp:42
void ElideCz(const bool &isAnti, const bitLenInt &control, const bitLenInt &target, const real1_f &pth, const real1_f &pc)
Definition: qunit.hpp:114
void ToPermBasisProb(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1163
virtual bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Compose() a QInterface peer, inserting its qubit into index order at start index.
Definition: qunit.hpp:266
void ToPermBasis(bitLenInt i)
Definition: qunit.hpp:1144
void TransformX2x2(const complex *mtrxIn, complex *mtrxOut)
Definition: qunit.hpp:834
virtual bool TryDecompose(bitLenInt start, QUnitPtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Definition: qunit.hpp:294
virtual complex GetAmplitude(const bitCapInt &perm)
Get the representational amplitude of a full permutation.
Definition: qunit.cpp:244
virtual real1_f ACProbRdm(bitLenInt control, bitLenInt target)
Definition: qunit.hpp:215
virtual void SetPermutation(const bitCapInt &perm, const complex &phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qunit.cpp:142
bitLenInt FindShardIndex(QEngineShardPtr shard)
Definition: qunit.hpp:1244
RevertControl
Definition: qunit.hpp:1105
@ ONLY_TARGETS
Definition: qunit.hpp:1105
@ CONTROLS_AND_TARGETS
Definition: qunit.hpp:1105
@ ONLY_CONTROLS
Definition: qunit.hpp:1105
virtual QInterfacePtr EntangleAll(bool isForProb=false)
Definition: qunit.hpp:769
void ToPermBasisMeasure(bitLenInt qubit)
Definition: qunit.hpp:1174
bitCapInt GetIndexedEigenstate(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, const unsigned char *values)
Definition: qunit.cpp:3470
virtual void Copy(QInterfacePtr orig)
Definition: qunit.hpp:55
bool INTCOptimize(const bitCapInt &toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt carryIndex)
Check if carry arithmetic can be optimized.
Definition: qunit.cpp:2862
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:204
virtual bitLenInt Compose(QUnitPtr toCopy)
Definition: qunit.hpp:244
virtual std::vector< int64_t > GetDeviceList()
Get the device index.
Definition: qunit.hpp:192
virtual void Decompose(bitLenInt start, QUnitPtr dest)
Definition: qunit.hpp:274
void INCxx(INCxxFn fn, const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt flag1Index, bitLenInt flag2Index)
Definition: qunit.cpp:2827
void INCx(INCxFn fn, const bitCapInt &toMod, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
Definition: qunit.cpp:2808
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:56
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qunit.hpp:162
void ConvertZToX(bitLenInt i)
Definition: qunit.hpp:971
bool isSparse
Definition: qunit.hpp:40
void CommuteH(bitLenInt bitIndex)
Definition: qunit.cpp:4148
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:2900
void ApplyBufferMap(bitLenInt bitIndex, ShardToPhaseMap bufferMap, RevertExclusivity exclusivity, bool isControl, bool isAnti, const std::set< bitLenInt > &exceptPartners, bool dumpSkipped)
Definition: qunit.cpp:4025
void(QAlu::* INCxxFn)(const bitCapInt &, bitLenInt, bitLenInt, bitLenInt, bitLenInt)
Definition: qunit.hpp:694
void TransformY2x2(const complex *mtrxIn, complex *mtrxOut)
Definition: qunit.hpp:850
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:286
void ConvertXToY(bitLenInt i)
Definition: qunit.hpp:996
RevertExclusivity
Definition: qunit.hpp:1104
@ ONLY_INVERT
Definition: qunit.hpp:1104
@ ONLY_PHASE
Definition: qunit.hpp:1104
@ INVERT_AND_PHASE
Definition: qunit.hpp:1104
virtual bitLenInt Compose(QUnitPtr toCopy, bitLenInt start)
Definition: qunit.hpp:246
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:194
void DirtyShardRangePhase(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:1197
void Flush0Eigenstate(bitLenInt i)
Definition: qunit.hpp:1116
bool isBdt
Definition: qunit.hpp:37
QEngineShardMap shards
Definition: qunit.hpp:49
size_t aceMb
Definition: qunit.hpp:41
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:2868
bool useHostRam
Definition: qunit.hpp:34
void EndEmulation(bitLenInt target)
Definition: qunit.hpp:1221
void(QAlu::* CMULFn)(const bitCapInt &, bitLenInt, bitLenInt, bitLenInt, const std::vector< bitLenInt > &)
Definition: qunit.hpp:695
virtual void SetQuantumState(const complex *inputState)
Set an arbitrary pure quantum state representation.
Definition: qunit.cpp:155
void RevertBasisX(bitLenInt i)
Definition: qunit.hpp:874
virtual void ZBase(bitLenInt target)
Definition: qunit.hpp:672
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 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:3495
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:3293
virtual void CMUL(const bitCapInt &toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication by integer.
Definition: qunit.cpp:3385
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 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:398
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:3531
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:3216
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:426
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:3673
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:3194
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:3633
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qunit.cpp:3094
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2141
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:3414
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qunit.cpp:3100
virtual void DECBCD(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Subtract classical BCD integer (without sign)
Definition: qunit.cpp:3205
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:416
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract integer (without sign, with carry)
Definition: qunit.cpp:3111
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:3443
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qunit.hpp:394
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qunit.hpp:402
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:3582
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:3177
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:3223
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 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:431
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:3653
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:421
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:412
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:3182
virtual void DIV(const bitCapInt &toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Divide by integer.
Definition: qunit.cpp:3257
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract integer (without sign, with controls)
Definition: qunit.hpp:407
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qunit.cpp:2500
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:332
virtual void CNOT(bitLenInt control, bitLenInt target)
Controlled NOT gate.
Definition: qinterface.hpp:716
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:1041
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: qunit.cpp:2469
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:337
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:1034
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:634
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 H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:920
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:318
virtual bitCapInt HighestProbAll()
Get highest probability permutation.
Definition: qunit.cpp:1488
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:2515
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:2510
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1091
virtual void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: qunit.hpp:313
virtual void AntiCNOT(bitLenInt control, bitLenInt target)
Anti controlled NOT gate.
Definition: qinterface.hpp:727
virtual void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qunit.cpp:2505
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:2525
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:2352
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:1229
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:325
virtual void Phase(const complex &topLeft, const complex &bottomRight, bitLenInt qubitIndex)
Apply a single bit transformation that only effects phase.
Definition: qunit.cpp:2172
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:2232
virtual void Mtrx(const complex *mtrx, bitLenInt qubit)
Apply an arbitrary single bit unitary transformation.
Definition: qunit.cpp:2414
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: qunit.hpp:347
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: qunit.hpp:353
virtual bool M(bitLenInt qubit)
Measurement gate.
Definition: qinterface.hpp:1020
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qunit.cpp:1570
virtual bitCapInt MAll()
Measure permutation state of all coherent bits.
Definition: qunit.cpp:1521
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:2284
virtual void PhaseParity(real1 radians, const bitCapInt &mask)
Definition: qunit.cpp:1030
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:2520
virtual void SetNcrp(real1_f ncrp)
Set the "Near-clifford rounding parameter" value, (between 0 and 1)
Definition: qunit.hpp:618
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:553
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:548
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:590
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:2874
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:3731
virtual real1_f ProbParity(const bitCapInt &mask)
Overall probability of any odd permutation of the masked set of bits.
Definition: qunit.cpp:1106
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qunit.cpp:3873
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qinterface.hpp:2992
virtual real1_f SumSqrDiff(QInterfacePtr toCompare)
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
Definition: qunit.hpp:538
virtual bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qunit.cpp:3762
virtual void SetSparseAceMaxMb(size_t mb)
Set the (sparse-simulation) "automatic circuit elision" (ACE) maximum memory megabytes.
Definition: qunit.hpp:630
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:543
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:578
virtual QInterfacePtr Clone()
Clone this QInterface.
Definition: qunit.cpp:3865
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:519
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:3742
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:558
virtual double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qunit.cpp:3699
virtual void SetSdrp(real1_f sdrp)
Set the "Schmidt decomposition rounding parameter" value, (between 0 and 1)
Definition: qunit.hpp:613
virtual real1_f ProbAll(const bitCapInt &perm)
Direct measure of full permutation probability.
Definition: qunit.hpp:518
virtual real1_f Prob(bitLenInt qubit)
Direct measure of bit probability to be in |1> state.
Definition: qunit.hpp:509
virtual void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qunit.hpp:612
virtual void SetAceMaxQubits(bitLenInt qb)
Set the "automatic circuit elision" (ACE) maximum entangled subsystem qubit count.
Definition: qunit.hpp:629
virtual void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qunit.hpp:568
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:2900
virtual void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qunit.cpp:3753
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:1164
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:185
QRACK_CONST real1_f FP_NORM_EPSILON_F
Definition: qrack_types.hpp:269
QRACK_CONST real1 SQRT1_2_R1
Definition: qrack_types.hpp:188
@ 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:249
QRACK_CONST real1_f TRYDECOMPOSE_EPSILON
Definition: qrack_types.hpp:270
QRACK_CONST real1 HALF_R1
Definition: qrack_types.hpp:192
std::shared_ptr< PhaseShard > PhaseShardPtr
Definition: qengineshard.hpp:46
half_float::half real1
Definition: qrack_types.hpp:102
std::complex< real1 > complex
Definition: qrack_types.hpp:136
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:268
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:143
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
QRACK_CONST real1 ZERO_R1
Definition: qrack_types.hpp:191
float real1_f
Definition: qrack_types.hpp:103
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:267
QRACK_CONST complex I_CMPLX
Definition: qrack_types.hpp:264
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:271
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:186
const bitCapInt ONE_BCI
Definition: qrack_types.hpp:137
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:138
HALF_CONSTEXPR half abs(half arg)
Absolute value.
Definition: half.hpp:2975
half sin(half arg)
Sine function.
Definition: half.hpp:3885
half log(half arg)
Natural logarithm.
Definition: half.hpp:3318
half cos(half arg)
Cosine function.
Definition: half.hpp:3922
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:185
#define QRACK_CONST
Definition: qrack_types.hpp:182
#define bitLenInt
Definition: qrack_types.hpp:42
#define ZERO_R1_F
Definition: qrack_types.hpp:168
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:164
#define bitCapInt
Definition: qrack_types.hpp:66
#define ONE_R1_F
Definition: qrack_types.hpp:171
#define IS_NORM_0(c)
Definition: qrack_types.hpp:29
Definition: qunit.hpp:798
bool operator<(const QSortEntry &rhs)
Definition: qunit.hpp:801
bitLenInt mapped
Definition: qunit.hpp:800
bool operator>(const QSortEntry &rhs)
Definition: qunit.hpp:802
bitLenInt bit
Definition: qunit.hpp:799