52 bool randomGlobalPhase =
true,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
53 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devIDs = {},
58 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
62 useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh, devIDs, qubitThreshold,
74 unit->SetConcurrency((uint32_t)threadsPerEngine);
85 unit->SetTInjection((
bool)useGadget);
104 return shard.
unit->ProbRdm(qubit);
116 CNOT(control, target);
118 CNOT(control, target);
130 throw std::invalid_argument(
"QUnit::SetAmplitude argument out-of-bounds!");
134 shards[0
U].unit->SetAmplitude(perm, amp);
143 throw std::invalid_argument(
"QUnit::Compose start index is out-of-bounds!");
147 QUnitPtr clone = std::dynamic_pointer_cast<QUnit>(toCopy->Clone());
158 return Compose(std::dynamic_pointer_cast<QUnit>(toCopy), start);
162 Decompose(start, std::dynamic_pointer_cast<QUnit>(dest));
199 UCPhase(controls, topLeft, bottomRight, target,
pow2(controls.size()) - 1U);
204 UCInvert(controls, topRight, bottomLeft, target,
pow2(controls.size()) - 1U);
209 UCPhase(controls, topLeft, bottomRight, target, 0
U);
214 UCInvert(controls, topRight, bottomLeft, target, 0
U);
223 UCMtrx(controls, mtrx, target,
pow2(controls.size()) - 1U);
227 UCMtrx(controls, mtrx, target, 0
U);
233 const complex* mtrxs,
const std::vector<bitCapInt>& mtrxSkipPowers,
bitCapInt mtrxSkipValueMask);
242 virtual bool ForceM(
bitLenInt qubitIndex,
bool result,
bool doForce =
true,
bool doApply =
true);
247 virtual std::map<bitCapInt, int>
MultiShotMeasureMask(
const std::vector<bitCapInt>& qPowers,
unsigned shots);
249 const std::vector<bitCapInt>& qPowers,
unsigned shots,
unsigned long long* shotsArray);
287 const std::vector<bitLenInt>& controls)
292 const std::vector<bitLenInt>& controls)
314 const std::vector<bitLenInt>& controls);
316 const std::vector<bitLenInt>& controls);
318 const std::vector<bitLenInt>& controls);
320 bitLenInt valueLength,
const unsigned char* values,
bool resetValue =
true);
342 throw std::invalid_argument(
"QUnit::Swap qubit index parameter must be within allocated qubit bounds!");
346 throw std::invalid_argument(
"QUnit::Swap qubit index parameter must be within allocated qubit bounds!");
349 if (qubit1 == qubit2) {
373 throw std::invalid_argument(
"QUnit::Prob target parameter must be within allocated qubit bounds!");
384 return shards[0
U].unit->ProbAllRdm(roundRz, perm);
389 clone->OrderContiguous(unit);
391 return unit->ProbAllRdm(roundRz, perm);
397 return SumSqrDiff(std::dynamic_pointer_cast<QUnit>(toCompare));
401 const std::vector<bitLenInt>& bits,
const std::vector<bitCapInt>& perms,
bitCapInt offset = 0
U)
406 bool roundRz,
const std::vector<bitLenInt>& bits,
const std::vector<bitCapInt>& perms,
bitCapInt offset = 0
U)
451 const std::vector<bitLenInt>& controls);
453 bitLenInt length,
const std::vector<bitLenInt>& controls);
455 std::vector<bitLenInt> controlVec = std::vector<bitLenInt>());
462 bitLenInt length, std::vector<bitLenInt>* controlsMapped);
466 std::vector<bitLenInt> controlVec);
468 bitLenInt length, std::vector<bitLenInt> controlVec);
474 bitLenInt valueLength,
const unsigned char* values);
479 const std::vector<bitCapInt>& perms,
const std::vector<real1_f>& weights,
bitCapInt offset,
bool roundRz)
481 if ((isFloat && (weights.size() < bits.size())) || (!isFloat && (perms.size() < bits.size()))) {
482 throw std::invalid_argument(
"QUnit::ExpectationFactorized() must supply at least as many weights as bits!");
486 "QUnit::ExpectationFactorized parameter qubits vector values must be within allocated qubit bounds!");
490 return isFloat ? (isRdm ?
shards[0
U].unit->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
491 :
shards[0
U].unit->ExpectationFloatsFactorized(bits, weights))
492 : (isRdm ?
shards[0
U].unit->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
493 :
shards[0
U].unit->ExpectationBitsFactorized(bits, perms, offset));
498 clone->OrderContiguous(unit);
500 return isFloat ? (isRdm ? unit->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
501 : unit->ExpectationFloatsFactorized(bits, weights))
502 : (isRdm ? unit->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
503 : unit->ExpectationBitsFactorized(bits, perms, offset));
527 std::vector<bitLenInt*>::iterator first, std::vector<bitLenInt*>::iterator last);
547 bool TrimControls(
const std::vector<bitLenInt>& controls, std::vector<bitLenInt>& controlVec,
bitCapInt* perm);
549 template <
typename CF>
551 std::vector<bitLenInt> controlVec,
const std::vector<bitLenInt> targets, CF cfn,
bool isPhase);
571 mtrxOut[0
U] = (
real1)(
ONE_R1 / 2) * (
complex)(mtrxIn[0
U] + mtrxIn[1U] + mtrxIn[2U] + mtrxIn[3U]);
572 mtrxOut[1U] = (
real1)(
ONE_R1 / 2) * (
complex)(mtrxIn[0
U] - mtrxIn[1U] + mtrxIn[2U] - mtrxIn[3U]);
573 mtrxOut[2U] = (
real1)(
ONE_R1 / 2) * (
complex)(mtrxIn[0
U] + mtrxIn[1U] - mtrxIn[2U] - mtrxIn[3U]);
574 mtrxOut[3U] = (
real1)(
ONE_R1 / 2) * (
complex)(mtrxIn[0
U] - mtrxIn[1U] - mtrxIn[2U] + mtrxIn[3U]);
581 mtrxOut[2U] = -mtrxOut[1U];
582 mtrxOut[3U] = -mtrxOut[0
U];
597 mtrxOut[2U] = -mtrxOut[1U];
598 mtrxOut[3U] = -mtrxOut[0
U];
605 mtrxOut[2U] = mtrxOut[1U];
606 mtrxOut[3U] = mtrxOut[0
U];
648 shard.
amp0 = (mtrx[0
U] * Y0) + (mtrx[1U] * shard.
amp1);
649 shard.
amp1 = (mtrx[2U] * Y0) + (mtrx[3U] * shard.
amp1);
696 bool isAnti,
const std::set<bitLenInt>& exceptPartners,
bool dumpSkipped);
699 const std::set<bitLenInt>& exceptControlling = {},
const std::set<bitLenInt>& exceptTargetedBy = {},
700 bool dumpSkipped =
false,
bool skipOptimized =
false);
717 shards[start + i].MakeDirty();
724 shards[start + i].isPhaseDirty =
true;
731 shards[bitIndices[i]].MakeDirty();
749 shard.
unit->SetQuantumState(bitState);
758 shard->
found =
false;
762 shard->
found =
false;
Definition: qengineshard.hpp:315
bitLenInt size()
Definition: qengineshard.hpp:343
void swap(bitLenInt qubit1, bitLenInt qubit2)
Definition: qengineshard.hpp:379
void insert(bitLenInt start, QEngineShardMap &toInsert)
Definition: qengineshard.hpp:351
Associates a QInterface object with a set of bits.
Definition: qengineshard.hpp:50
complex amp0
Definition: qengineshard.hpp:62
bool ClampAmps()
Definition: qengineshard.cpp:29
bitLenInt mapped
Definition: qengineshard.hpp:59
bool isProbDirty
Definition: qengineshard.hpp:60
QInterfacePtr unit
Definition: qengineshard.hpp:58
Pauli pauliBasis
Definition: qengineshard.hpp:64
complex amp1
Definition: qengineshard.hpp:63
bool found
Definition: qengineshard.hpp:74
bool isPhaseDirty
Definition: qengineshard.hpp:61
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:146
bitCapInt maxQPower
Definition: qinterface.hpp:154
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:249
real1 amplitudeFloor
Definition: qinterface.hpp:153
bool useRDRAND
Definition: qinterface.hpp:150
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:434
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:338
qrack_rand_gen_ptr rand_generator
Definition: qinterface.hpp:155
bool randGlobalPhase
Definition: qinterface.hpp:149
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:159
static real1_f clampProb(real1_f toClamp)
Definition: qinterface.hpp:169
bitLenInt qubitCount
Definition: qinterface.hpp:151
bool doNormalize
Definition: qinterface.hpp:148
Definition: qparity.hpp:22
void ConvertYToZ(bitLenInt i)
Definition: qunit.cpp:2846
virtual complex GetAmplitude(bitCapInt perm)
Get the representational amplitude of a full permutation.
Definition: qunit.cpp:224
void ToPermBasisAll()
Definition: qunit.hpp:706
bool INTCOptimize(bitCapInt toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt carryIndex)
Check if carry arithmetic can be optimized.
Definition: qunit.cpp:3073
void(QAlu::* INCxxFn)(bitCapInt, bitLenInt, bitLenInt, bitLenInt, bitLenInt)
Definition: qunit.hpp:449
virtual void SetReactiveSeparate(bool isAggSep)
Set reactive separation option (on by default if available)
Definition: qunit.hpp:91
std::vector< int64_t > deviceIDs
Definition: qunit.hpp:44
bool(* ParallelUnitFn)(QInterfacePtr unit, real1_f param1, real1_f param2, real1_f param3, int64_t param4)
Definition: qunit.hpp:529
void OptimizePairBuffers(bitLenInt control, bitLenInt target, bool anti)
Definition: qunit.cpp:4322
void OrderContiguous(QInterfacePtr unit)
Definition: qunit.cpp:857
void INT(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex, bool hasCarry, std::vector< bitLenInt > controlVec=std::vector< bitLenInt >())
Definition: qunit.cpp:3124
void Flush1Eigenstate(bitLenInt i)
Definition: qunit.cpp:2918
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
virtual void SetPermutation(bitCapInt perm, complex phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qunit.cpp:109
virtual QInterfacePtr EntangleInCurrentBasis(std::vector< bitLenInt * >::iterator first, std::vector< bitLenInt * >::iterator last)
Definition: qunit.cpp:384
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:37
virtual void X(bitLenInt q)
Definition: qunit.hpp:257
virtual QInterfacePtr Entangle(std::vector< bitLenInt > bits)
Definition: qunit.cpp:468
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:434
virtual void EitherISwap(bitLenInt qubit1, bitLenInt qubit2, bool isInverse)
Definition: qunit.cpp:1797
void ApplyEitherControlled(std::vector< bitLenInt > controlVec, const std::vector< bitLenInt > targets, CF cfn, bool isPhase)
Definition: qunit.cpp:2735
void RevertBasis1Qb(bitLenInt i)
Definition: qunit.hpp:653
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qunit.hpp:165
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:997
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:990
virtual real1_f CProbRdm(bitLenInt control, bitLenInt target)
Definition: qunit.hpp:106
real1_f separabilityThreshold
Definition: qunit.hpp:39
void ToPermBasisProb()
Definition: qunit.hpp:707
void CMULModx(CMULModFn fn, bitCapInt toMod, bitCapInt modN, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > controlVec)
Definition: qunit.cpp:3584
virtual real1_f ProbBase(bitLenInt qubit)
Definition: qunit.cpp:976
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:338
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 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:139
virtual void GetQuantumState(complex *outputState)
Get the pure quantum state representation.
Definition: qunit.cpp:168
virtual void GetProbs(real1 *outputProbs)
Get the pure quantum state representation.
Definition: qunit.cpp:196
void ToPermBasisAllMeasure()
Definition: qunit.cpp:2982
virtual void XBase(bitLenInt target)
Definition: qunit.cpp:2140
complex phaseFactor
Definition: qunit.hpp:42
virtual bitCapInt ForceMReg(bitLenInt start, bitLenInt length, 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:212
virtual void H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:876
virtual bool SeparateBit(bool value, bitLenInt qubit)
Definition: qunit.cpp:1347
bool isReactiveSeparate
Definition: qunit.hpp:36
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:97
void(QAlu::* CMULFn)(bitCapInt toMod, bitLenInt start, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Definition: qunit.hpp:450
virtual complex GetAmplitudeOrProb(bitCapInt perm, bool isProb)
Definition: qunit.cpp:226
virtual void SetTInjection(bool useGadget)
Set the option to use T-injection gadgets (off by default)
Definition: qunit.hpp:80
virtual QInterfacePtr EntangleRange(bitLenInt start, bitLenInt length, bool isForProb=false)
Definition: qunit.cpp:488
void ShardAI(bitLenInt qubit, real1_f azimuth, real1_f inclination)
Definition: qunit.cpp:2892
void ClampShard(bitLenInt qubit)
Definition: qunit.hpp:553
virtual void Decompose(bitLenInt start, QInterfacePtr dest)
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
Definition: qunit.hpp:160
virtual bool M(bitLenInt q)
Definition: qunit.hpp:255
virtual void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qunit.cpp:3961
bitLenInt thresholdQubits
Definition: qunit.hpp:38
void DirtyShardIndexVector(std::vector< bitLenInt > bitIndices)
Definition: qunit.hpp:728
void ConvertZToY(bitLenInt i)
Definition: qunit.cpp:2869
std::vector< QInterfaceEngine > engines
Definition: qunit.hpp:45
void(QAlu::* INCxFn)(bitCapInt, bitLenInt, bitLenInt, bitLenInt)
Definition: qunit.hpp:448
void RevertBasisY(bitLenInt i)
Definition: qunit.hpp:621
virtual void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubitIndex, const complex *mtrxs)
Apply a "uniformly controlled" arbitrary single bit unitary transformation.
Definition: qinterface.hpp:590
virtual bool GetReactiveSeparate()
Get reactive separation option.
Definition: qunit.hpp:92
bool TrimControls(const std::vector< bitLenInt > &controls, std::vector< bitLenInt > &controlVec, bitCapInt *perm)
Definition: qunit.cpp:2621
virtual ~QUnit()
Definition: qunit.hpp:67
double logFidelity
Definition: qunit.hpp:40
virtual void Detach(bitLenInt start, bitLenInt length, QUnitPtr dest)
Definition: qunit.cpp:268
RevertAnti
Definition: qunit.hpp:692
@ ONLY_ANTI
Definition: qunit.hpp:692
@ CTRL_AND_ANTI
Definition: qunit.hpp:692
@ ONLY_CTRL
Definition: qunit.hpp:692
void RevertBasisToX1Qb(bitLenInt i)
Definition: qunit.hpp:664
virtual void YBase(bitLenInt target)
Definition: qunit.cpp:2155
virtual void ZBase(bitLenInt target)
Definition: qunit.cpp:2172
void INCx(INCxFn fn, bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
Definition: qunit.cpp:3019
void TransformYInvert(complex topRight, complex bottomLeft, complex *mtrxOut)
Definition: qunit.hpp:593
void(QAlu::* CMULModFn)(bitCapInt toMod, bitCapInt modN, bitLenInt start, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Definition: qunit.hpp:452
void ApplyBuffer(PhaseShardPtr phaseShard, bitLenInt control, bitLenInt target, bool isAnti)
Definition: qunit.cpp:4081
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:175
int64_t devID
Definition: qunit.hpp:41
void TransformPhase(complex topLeft, complex bottomRight, complex *mtrxOut)
Definition: qunit.hpp:601
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:4167
virtual bool TrySeparateClifford(bitLenInt qubit)
Definition: qunit.cpp:586
virtual void SetAmplitude(bitCapInt perm, complex amp)
Sets the representational amplitude of a full permutation.
Definition: qunit.hpp:127
bool freezeBasis2Qb
Definition: qunit.hpp:33
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
virtual int64_t GetDevice()
Get the device index.
Definition: qunit.hpp:95
void RevertBasisToY1Qb(bitLenInt i)
Definition: qunit.hpp:674
void DirtyShardRange(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:714
QInterfacePtr CMULEntangle(std::vector< bitLenInt > controlVec, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > *controlsMapped)
Definition: qunit.cpp:3537
void CMULx(CMULFn fn, bitCapInt toMod, bitLenInt start, bitLenInt carryStart, bitLenInt length, std::vector< bitLenInt > controlVec)
Definition: qunit.cpp:3571
virtual bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Definition: qunit.hpp:156
bool INTSCOptimize(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:3079
QUnit(std::vector< QInterfaceEngine > eng, bitLenInt qBitCount, bitCapInt initState=0U, qrack_rand_gen_ptr rgp=nullptr, complex phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t deviceId=-1, bool useHardwareRNG=true, bool useSparseStateVec=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > devIDs={}, bitLenInt qubitThreshold=0U, real1_f separation_thresh=FP_NORM_EPSILON_F)
Definition: qunit.cpp:65
virtual void Dispose(bitLenInt start, bitLenInt length, bitCapInt disposedPerm)
Dispose a a contiguous set of qubits that are already in a permutation eigenstate.
Definition: qunit.hpp:176
virtual QInterfacePtr CloneBody(QUnitPtr copyPtr)
Definition: qunit.cpp:4060
void ToPermBasis(bitLenInt i)
Definition: qunit.cpp:2926
void TransformX2x2(const complex *mtrxIn, complex *mtrxOut)
Definition: qunit.hpp:569
virtual real1_f ACProbRdm(bitLenInt control, bitLenInt target)
Definition: qunit.hpp:114
bitLenInt FindShardIndex(QEngineShardPtr shard)
Definition: qunit.hpp:753
RevertControl
Definition: qunit.hpp:691
@ ONLY_TARGETS
Definition: qunit.hpp:691
@ CONTROLS_AND_TARGETS
Definition: qunit.hpp:691
@ ONLY_CONTROLS
Definition: qunit.hpp:691
QInterfacePtr MakeEngine(bitLenInt length, bitCapInt perm)
Definition: qunit.cpp:98
virtual QInterfacePtr EntangleAll(bool isForProb=false)
Definition: qunit.hpp:512
void ToPermBasisMeasure(bitLenInt qubit)
Definition: qunit.cpp:2954
bitCapInt GetIndexedEigenstate(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, const unsigned char *values)
Definition: qunit.cpp:3681
virtual bitLenInt Compose(QUnitPtr toCopy)
Definition: qunit.hpp:138
virtual void Decompose(bitLenInt start, QUnitPtr dest)
Definition: qunit.hpp:164
bool INTSOptimize(bitCapInt toMod, bitLenInt start, bitLenInt length, bool isAdd, bitLenInt overflowIndex)
Check if overflow arithmetic can be optimized.
Definition: qunit.cpp:3067
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qunit.hpp:69
void ConvertZToX(bitLenInt i)
Definition: qunit.cpp:2801
bool isSparse
Definition: qunit.hpp:35
void CommuteH(bitLenInt bitIndex)
Definition: qunit.cpp:4219
void INCxx(INCxxFn fn, bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt flag1Index, bitLenInt flag2Index)
Definition: qunit.cpp:3038
void ApplyBufferMap(bitLenInt bitIndex, ShardToPhaseMap bufferMap, RevertExclusivity exclusivity, bool isControl, bool isAnti, const std::set< bitLenInt > &exceptPartners, bool dumpSkipped)
Definition: qunit.cpp:4105
void TransformY2x2(const complex *mtrxIn, complex *mtrxOut)
Definition: qunit.hpp:585
void ConvertXToY(bitLenInt i)
Definition: qunit.cpp:2822
real1_f ExpectationFactorized(bool isRdm, bool isFloat, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const std::vector< real1_f > &weights, bitCapInt offset, bool roundRz)
Definition: qunit.hpp:478
void TransformXInvert(complex topRight, complex bottomLeft, complex *mtrxOut)
Definition: qunit.hpp:577
RevertExclusivity
Definition: qunit.hpp:690
@ ONLY_INVERT
Definition: qunit.hpp:690
@ ONLY_PHASE
Definition: qunit.hpp:690
@ INVERT_AND_PHASE
Definition: qunit.hpp:690
std::vector< bitLenInt > CMULEntangle(std::vector< bitLenInt > controlVec, bitLenInt start, bitCapInt carryStart, bitLenInt length)
virtual bitLenInt Compose(QUnitPtr toCopy, bitLenInt start)
Definition: qunit.hpp:140
void DirtyShardRangePhase(bitLenInt start, bitLenInt length)
Definition: qunit.hpp:721
void Flush0Eigenstate(bitLenInt i)
Definition: qunit.cpp:2910
QUnit(bitLenInt qBitCount, bitCapInt initState=0U, qrack_rand_gen_ptr rgp=nullptr, complex phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t deviceId=-1, bool useHardwareRNG=true, bool useSparseStateVec=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > devIDs={}, bitLenInt qubitThreshold=0U, real1_f separation_thresh=FP_NORM_EPSILON_F)
Definition: qunit.hpp:56
QEngineShardMap shards
Definition: qunit.hpp:43
bool useHostRam
Definition: qunit.hpp:34
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)
Definition: qunit.cpp:3911
void EndEmulation(bitLenInt target)
Definition: qunit.hpp:735
virtual void SetQuantumState(const complex *inputState)
Set an arbitrary pure quantum state representation.
Definition: qunit.cpp:123
void INTS(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex, bool hasCarry)
Definition: qunit.cpp:3333
void RevertBasisX(bitLenInt i)
Definition: qunit.hpp:609
Half-precision floating-point type.
Definition: half.hpp:2222
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:3706
virtual void INC(bitCapInt toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qunit.cpp:3304
virtual void POWModNOut(bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Raise a classical base to a quantum power, modulo N, (out of place)
Definition: qunit.cpp:3506
virtual void INCDECBCDC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (without overflow flag)
Definition: qunit.cpp:3428
virtual void CMULModNOut(bitCapInt toMul, 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:286
virtual void CMULModNOut(bitCapInt toMul, 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:259
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:3742
virtual void CIMULModNOut(bitCapInt toMul, 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:296
virtual void INCC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qunit.cpp:3310
virtual void INCBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length)
Add classical BCD integer (without sign)
Definition: qunit.cpp:3406
virtual void CIMULModNOut(bitCapInt toMul, 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:291
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:3844
virtual void MULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: qunit.hpp:278
virtual void INCDECC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC (without sign, with carry)
Definition: qunit.hpp:274
virtual void INCDECC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC.
Definition: arithmetic.cpp:63
virtual void DECS(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qunit.hpp:266
virtual void CDEC(bitCapInt toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract integer (without sign, with controls)
Definition: qunit.hpp:270
virtual void PhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length)
This is an expedient for an adaptive Grover's search for a function's global minimum.
Definition: qunit.cpp:3865
virtual void IMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:226
virtual void INCS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qunit.cpp:3389
virtual void IMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: qunit.hpp:282
virtual void CINC(bitCapInt toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qunit.cpp:2995
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:3793
virtual void DIV(bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Divide by integer.
Definition: qunit.cpp:3471
virtual void DECBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length)
Subtract classical BCD integer (without sign)
Definition: qunit.cpp:3417
virtual void CPOWModNOut(bitCapInt base, 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:3654
virtual void CPhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
The 6502 uses its carry flag also as a greater-than/less-than flag, for the CMP operation.
Definition: qunit.cpp:3885
virtual void DEC(bitCapInt toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: arithmetic.cpp:57
virtual void DEC(bitCapInt toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qunit.hpp:265
virtual void CMUL(bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication by integer.
Definition: qunit.cpp:3596
virtual void MUL(bitCapInt toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Multiply by integer.
Definition: qunit.cpp:3435
virtual void INCDECSC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (with overflow flag)
Definition: qunit.cpp:3394
virtual void DECC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract integer (without sign, with carry)
Definition: qunit.cpp:3321
virtual void DECS(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Subtract a classical integer from the register, with sign and without carry.
Definition: arithmetic.cpp:182
virtual void MULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:191
virtual void CDEC(bitCapInt toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract classical integer (without sign, with controls)
Definition: arithmetic.cpp:160
virtual void CDIV(bitCapInt toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled division by power of integer.
Definition: qunit.cpp:3625
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qunit.cpp:2591
virtual void MCPhase(const std::vector< bitLenInt > &controls, complex topLeft, complex bottomRight, bitLenInt target)
Apply a single bit transformation that only effects phase, with arbitrary control bits.
Definition: qunit.hpp:197
virtual void ZMask(bitCapInt mask)
Masked Z gate.
Definition: qunit.hpp:192
virtual void CNOT(bitLenInt control, bitLenInt target)
Controlled NOT gate.
Definition: qinterface.hpp:672
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:997
virtual void MACPhase(const std::vector< bitLenInt > &controls, complex topLeft, complex bottomRight, bitLenInt target)
Apply a single bit transformation that only effects phase, with arbitrary (anti-)control bits.
Definition: qunit.hpp:206
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:990
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, bitLenInt target, bitCapInt controlPerm)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits,...
Definition: qunit.cpp:2559
virtual void H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:876
virtual bool M(bitLenInt qubitIndex)
Measurement gate.
Definition: qinterface.hpp:976
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:2606
virtual void UCPhase(const std::vector< bitLenInt > &controls, complex topLeft, complex bottomRight, bitLenInt target, bitCapInt controlPerm)
Apply a single bit transformation that only effects phase, with arbitrary control bits,...
Definition: qunit.cpp:2372
virtual void MCInvert(const std::vector< bitLenInt > &controls, complex topRight, complex bottomLeft, bitLenInt target)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qunit.hpp:201
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:2601
virtual void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubitIndex, const complex *mtrxs)
Apply a "uniformly controlled" arbitrary single bit unitary transformation.
Definition: qinterface.hpp:590
virtual void Invert(complex topRight, complex bottomLeft, bitLenInt qubitIndex)
Apply a single bit transformation that reverses bit probability and might effect phase.
Definition: qunit.cpp:2321
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1054
virtual void PhaseParity(real1 radians, bitCapInt mask)
Definition: qunit.cpp:1040
virtual void AntiCNOT(bitLenInt control, bitLenInt target)
Anti controlled NOT gate.
Definition: qinterface.hpp:683
virtual void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qunit.cpp:2596
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:2616
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual void CUniformParityRZ(const std::vector< bitLenInt > &controls, 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:1240
virtual void UCInvert(const std::vector< bitLenInt > &controls, complex topRight, complex bottomLeft, bitLenInt target, bitCapInt controlPerm)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qunit.cpp:2439
virtual void Mtrx(const complex *mtrx, bitLenInt qubit)
Apply an arbitrary single bit unitary transformation.
Definition: qunit.cpp:2500
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:221
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:225
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qunit.cpp:1547
virtual bitCapInt MAll()
Measure permutation state of all coherent bits.
Definition: qunit.cpp:1496
virtual void MACInvert(const std::vector< bitLenInt > &controls, complex topRight, complex bottomLeft, bitLenInt target)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qunit.hpp:211
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:2611
virtual void Phase(complex topLeft, complex bottomRight, bitLenInt qubitIndex)
Apply a single bit transformation that only effects phase.
Definition: qunit.cpp:2260
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:2600
virtual bool ForceMParity(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:1175
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:3927
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.cpp:618
virtual real1_f ExpectationBitsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, bitCapInt offset=0U)
Get (reduced density matrix) expectation value of bits, given an array of qubit weights.
Definition: qunit.hpp:405
virtual real1_f ExpectationBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, bitCapInt offset=0U)
Get expectation value of bits, given an array of qubit weights.
Definition: qunit.hpp:400
virtual real1_f SumSqrDiff(QInterfacePtr toCompare)
Definition: qunit.hpp:395
virtual bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qunit.cpp:3955
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:422
virtual QInterfacePtr Clone()
Clone this QInterface.
Definition: qunit.cpp:4042
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:3937
virtual void SetSdrp(real1_f sdrp)
Set the "Schmidt decomposition rounding parameter" value, (between 0 and 1)
Definition: qunit.hpp:429
virtual real1_f Prob(bitLenInt qubit)
Direct measure of bit probability to be in |1> state.
Definition: qunit.hpp:370
virtual real1_f ProbParity(bitCapInt mask)
Overall probability of any odd permutation of the masked set of bits.
Definition: qunit.cpp:1117
virtual void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qunit.hpp:428
virtual void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qunit.hpp:415
virtual void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qunit.cpp:3947
virtual double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qunit.hpp:427
virtual real1_f ProbAllRdm(bool roundRz, bitCapInt perm)
Direct measure of full permutation probability, treating all ancillary qubits as post-selected T gate...
Definition: qunit.hpp:380
virtual real1_f ProbAll(bitCapInt perm)
Direct measure of full permutation probability.
Definition: qunit.hpp:379
Definition: complex16x2simd.hpp:25
void ThrowIfQbIdArrayIsBad(const std::vector< bitLenInt > &controls, const bitLenInt &qubitCount, std::string message)
Definition: qrack_functions.hpp:71
std::complex< half_float::half > complex
Definition: qrack_types.hpp:62
@ QINTERFACE_STABILIZER_HYBRID
Create a QStabilizerHybrid, switching between a QStabilizer and a QHybrid as efficient.
Definition: qinterface.hpp:90
std::shared_ptr< QUnit > QUnitPtr
Definition: qunit.hpp:24
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:28
constexpr real1_f ZERO_R1_F
Definition: qrack_types.hpp:152
constexpr real1_f FP_NORM_EPSILON_F
Definition: qrack_types.hpp:245
std::shared_ptr< PhaseShard > PhaseShardPtr
Definition: qengineshard.hpp:46
const real1 ONE_R1
Definition: qrack_types.hpp:153
constexpr real1_f ONE_R1_F
Definition: qrack_types.hpp:154
half_float::half real1
Definition: qrack_types.hpp:63
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:243
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:22
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:101
const real1 REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:155
const real1 PI_R1
Definition: qrack_types.hpp:158
float real1_f
Definition: qrack_types.hpp:64
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:242
QRACK_CONST complex I_CMPLX
Definition: qrack_types.hpp:241
std::map< QEngineShardPtr, PhaseShardPtr > ShardToPhaseMap
Definition: qengineshard.hpp:47
const real1 REAL1_EPSILON
Definition: qrack_types.hpp:157
@ PauliX
Pauli X operator. Corresponds to Q# constant "PauliX.".
Definition: qinterface.hpp:38
@ PauliY
Pauli Y operator. Corresponds to Q# constant "PauliY.".
Definition: qinterface.hpp:40
@ PauliZ
Pauli Z operator. Corresponds to Q# constant "PauliZ.".
Definition: qinterface.hpp:42
half log(half arg)
Natural logarithm.
Definition: half.hpp:3318
half exp(half arg)
Exponential function.
Definition: half.hpp:3201
#define QRACK_CONST
Definition: qrack_types.hpp:150
#define bitLenInt
Definition: qrack_types.hpp:44
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:146
#define bitCapInt
Definition: qrack_types.hpp:105
#define IS_NORM_0(c)
Definition: qrack_types.hpp:27
Definition: qunit.hpp:539
bool operator<(const QSortEntry &rhs)
Definition: qunit.hpp:542
bitLenInt mapped
Definition: qunit.hpp:541
bool operator>(const QSortEntry &rhs)
Definition: qunit.hpp:543
bitLenInt bit
Definition: qunit.hpp:540