20 class QInterfaceNoisy;
37 if (getenv(
"QRACK_GATE_DEPOLARIZATION")) {
38 n = (
real1_f)std::stof(std::string(getenv(
"QRACK_GATE_DEPOLARIZATION")));
45 engine->DepolarizingChannelWeak1Qb(qb, n);
48 logFidelity = -1 * std::numeric_limits<float>::infinity();
68 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
72 useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold,
80 bool randomGlobalPhase =
true,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
81 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devList = {},
111 return engine->ProbReg(start, length, permutation);
118 return engine->Allocate(start, length);
124 return engine->Compose(toCopy->engine);
130 return engine->Compose(toCopy->engine, start);
134 return Compose(std::dynamic_pointer_cast<QInterfaceNoisy>(toCopy), start);
139 return engine->ComposeNoClone(toCopy->engine);
143 return ComposeNoClone(std::dynamic_pointer_cast<QInterfaceNoisy>(toCopy));
148 Decompose(start, std::dynamic_pointer_cast<QInterfaceNoisy>(dest));
153 engine->Decompose(start, dest->engine);
159 return TryDecompose(start, std::dynamic_pointer_cast<QInterfaceNoisy>(dest), error_tol);
163 engine->Decompose(start, dest->engine);
168 engine->Dispose(start, length);
173 engine->Dispose(start, length, disposedPerm);
180 const bool result =
engine->TryDecompose(start, dest->engine, error_tol);
194 engine->SetPermutation(perm, phaseFac);
199 engine->Mtrx(mtrx, qubitIndex);
204 engine->Phase(topLeft, bottomRight, qubitIndex);
209 engine->Invert(topRight, bottomLeft, qubitIndex);
214 engine->MCMtrx(controls, mtrx, target);
216 for (
const bitLenInt& control : controls) {
222 engine->MACMtrx(controls, mtrx, target);
224 for (
const bitLenInt& control : controls) {
231 const complex* mtrxs,
const std::vector<bitCapInt> mtrxSkipPowers,
const bitCapInt& mtrxSkipValueMask)
233 engine->UniformlyControlledSingleBit(controls, qubitIndex, mtrxs, mtrxSkipPowers, mtrxSkipValueMask);
235 for (
const bitLenInt& control : controls) {
254 engine->PhaseParity(radians, mask);
268 engine->CSwap(controls, qubit1, qubit2);
271 for (
const bitLenInt& control : controls) {
277 engine->AntiCSwap(controls, qubit1, qubit2);
280 for (
const bitLenInt& control : controls) {
286 engine->CSqrtSwap(controls, qubit1, qubit2);
289 for (
const bitLenInt& control : controls) {
295 engine->AntiCSqrtSwap(controls, qubit1, qubit2);
298 for (
const bitLenInt& control : controls) {
304 engine->CISqrtSwap(controls, qubit1, qubit2);
307 for (
const bitLenInt& control : controls) {
313 engine->AntiCISqrtSwap(controls, qubit1, qubit2);
316 for (
const bitLenInt& control : controls) {
323 return engine->ForceM(qubit, result, doForce, doApply);
328 engine->Swap(qubitIndex1, qubitIndex2);
334 engine->ISwap(qubitIndex1, qubitIndex2);
340 engine->IISwap(qubitIndex1, qubitIndex2);
346 engine->SqrtSwap(qubitIndex1, qubitIndex2);
352 engine->ISqrtSwap(qubitIndex1, qubitIndex2);
358 engine->FSim(theta, phi, qubitIndex1, qubitIndex2);
367 return engine->ProbMask(mask, permutation);
372 return SumSqrDiff(std::dynamic_pointer_cast<QInterfaceNoisy>(toCompare));
380 engine->NormalizeState(nrm, norm_thresh, phaseArg);
385 return engine->ExpectationBitsAll(bits, offset);
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:140
unsigned GetConcurrencyLevel()
Definition: parallel_for.hpp:41
A "Qrack::QInterfaceNoisy" that wraps any other QInterface with a simple noise model.
Definition: qinterface_noisy.hpp:26
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: qinterface_noisy.hpp:376
void Apply1QbNoise(bitLenInt qb)
Definition: qinterface_noisy.hpp:33
void Phase(const complex &topLeft, const complex &bottomRight, bitLenInt qubitIndex)
Apply a single bit transformation that only effects phase.
Definition: qinterface_noisy.hpp:202
void SetDeviceList(std::vector< int64_t > dIDs)
Set the device index list, if more than one device is available.
Definition: qinterface_noisy.hpp:397
void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qinterface_noisy.hpp:275
void Invert(const complex &topRight, const complex &bottomLeft, bitLenInt qubitIndex)
Apply a single bit transformation that reverses bit probability and might effect phase.
Definition: qinterface_noisy.hpp:207
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: qinterface_noisy.hpp:220
void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qinterface_noisy.hpp:392
void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubitIndex, const complex *mtrxs, const std::vector< bitCapInt > mtrxSkipPowers, const bitCapInt &mtrxSkipValueMask)
Definition: qinterface_noisy.hpp:230
void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qinterface_noisy.hpp:266
QInterfaceNoisy(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 useSparseStateVec=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > devList={}, bitLenInt qubitThreshold=0U, real1_f separation_thresh=_qrack_qunit_sep_thresh)
Definition: qinterface_noisy.hpp:66
void ISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Swap values of two bits in register, and apply phase factor of i if bits are different.
Definition: qinterface_noisy.hpp:332
double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qinterface_noisy.hpp:98
void SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Square root of Swap gate.
Definition: qinterface_noisy.hpp:344
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:371
void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
Definition: qinterface_noisy.hpp:212
real1_f ExpectationBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Get permutation expectation value of bits.
Definition: qinterface_noisy.hpp:383
real1_f SumSqrDiff(QInterfacePtr toCompare)
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
Definition: qinterface_noisy.hpp:370
void AntiCSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary (anti) control bits.
Definition: qinterface_noisy.hpp:293
real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt &permutation)
Direct measure of register permutation probability.
Definition: qinterface_noisy.hpp:109
void Dispose(bitLenInt start, bitLenInt length)
Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separa...
Definition: qinterface_noisy.hpp:166
real1_f GetNoiseParameter()
Get the noise level option (only for a noisy interface)
Definition: qinterface_noisy.hpp:96
bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface_noisy.hpp:126
QInterfacePtr Clone()
Clone this QInterface.
Definition: qinterface_noisy.hpp:394
QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qinterface_noisy.hpp:150
void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qinterface_noisy.hpp:388
void CSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary control bits.
Definition: qinterface_noisy.hpp:284
std::vector< QInterfaceEngine > engines
Definition: qinterface_noisy.hpp:31
void SetSdrp(real1_f sdrp)
Set the "Schmidt decomposition rounding parameter" value, (between 0 and 1)
Definition: qinterface_noisy.hpp:92
void PhaseParity(real1_f radians, const bitCapInt &_mask)
Parity phase gate.
Definition: qinterface_noisy.hpp:251
void SetConcurrency(uint32_t threadCount)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface_noisy.hpp:103
void Decompose(bitLenInt start, QInterfaceNoisyPtr dest)
Definition: qinterface_noisy.hpp:161
bool TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Attempt to Decompose() a bit range.
Definition: qinterface_noisy.hpp:157
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
double logFidelity
Definition: qinterface_noisy.hpp:28
void SetNoiseParameter(real1_f lambda)
Set the noise level option (only for a noisy interface)
Definition: qinterface_noisy.hpp:95
bitLenInt Compose(QInterfaceNoisyPtr toCopy)
Definition: qinterface_noisy.hpp:121
void SetQuantumState(const complex *inputState)
Set an arbitrary pure quantum state representation.
Definition: qinterface_noisy.hpp:187
void Copy(QInterfaceNoisyPtr orig)
Definition: qinterface_noisy.hpp:56
void Mtrx(const complex *mtrx, bitLenInt qubitIndex)
Apply an arbitrary single bit unitary transformation.
Definition: qinterface_noisy.hpp:197
bool TryDecompose(bitLenInt start, QInterfaceNoisyPtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Definition: qinterface_noisy.hpp:177
real1_f ACProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |0>.
Definition: qinterface_noisy.hpp:264
real1_f noiseParam
Definition: qinterface_noisy.hpp:29
bitCapIntOcl GetMaxSize()
Definition: qinterface_noisy.hpp:401
bitLenInt ComposeNoClone(QInterfaceNoisyPtr toCopy)
Definition: qinterface_noisy.hpp:136
bool ForceM(bitLenInt qubit, bool result, bool doForce=true, bool doApply=true)
Act as if is a measurement was applied, except force the (usually random) result.
Definition: qinterface_noisy.hpp:321
bitLenInt Compose(QInterfaceNoisyPtr toCopy, bitLenInt start)
Definition: qinterface_noisy.hpp:127
void Decompose(bitLenInt start, QInterfacePtr dest)
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
Definition: qinterface_noisy.hpp:146
QInterfacePtr engine
Definition: qinterface_noisy.hpp:30
void Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Swap values of two bits in register.
Definition: qinterface_noisy.hpp:326
void FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2)
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
Definition: qinterface_noisy.hpp:356
void SetReactiveSeparate(bool isAggSep)
Set reactive separation option (on by default if available)
Definition: qinterface_noisy.hpp:93
void Dispose(bitLenInt start, bitLenInt length, const bitCapInt &disposedPerm)
Dispose a a contiguous set of qubits that are already in a permutation eigenstate.
Definition: qinterface_noisy.hpp:171
void SetAmplitude(const bitCapInt &perm, const complex &)
Sets the representational amplitude of a full permutation.
Definition: qinterface_noisy.hpp:191
void XMask(const bitCapInt &_mask)
Masked X gate.
Definition: qinterface_noisy.hpp:240
void GetQuantumState(complex *outputState)
Get the pure quantum state representation.
Definition: qinterface_noisy.hpp:188
bitLenInt ComposeNoClone(QInterfacePtr toCopy)
This is a variant of Compose() for a toCopy argument that will definitely not be reused once "Compose...
Definition: qinterface_noisy.hpp:141
QInterfaceNoisy(QInterfaceNoisy *o)
Definition: qinterface_noisy.hpp:84
void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qinterface_noisy.hpp:396
real1_f SumSqrDiff(QInterfaceNoisyPtr toCompare)
Definition: qinterface_noisy.hpp:374
void SetPermutation(const bitCapInt &perm, const complex &phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qinterface_noisy.hpp:192
bitLenInt Allocate(bitLenInt start, bitLenInt length)
Allocate new "length" count of |0> state qubits at specified qubit index start position.
Definition: qinterface_noisy.hpp:115
real1_f ProbAll(const bitCapInt &fullRegister)
Direct measure of full permutation probability.
Definition: qinterface_noisy.hpp:364
void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qinterface_noisy.hpp:99
void ISqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Inverse square root of Swap gate.
Definition: qinterface_noisy.hpp:350
bool isOpenCL()
Returns "true" if current simulation is OpenCL-based.
Definition: qinterface_noisy.hpp:101
bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qinterface_noisy.hpp:390
complex GetAmplitude(const bitCapInt &perm)
Get the representational amplitude of a full permutation.
Definition: qinterface_noisy.hpp:190
int64_t GetDevice()
Get the device index.
Definition: qinterface_noisy.hpp:398
std::vector< int64_t > GetDeviceList()
Get the device index.
Definition: qinterface_noisy.hpp:399
bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Compose() a QInterface peer, inserting its qubit into index order at start index.
Definition: qinterface_noisy.hpp:132
void GetProbs(real1 *outputProbs)
Get the pure quantum state representation.
Definition: qinterface_noisy.hpp:189
real1_f ProbMask(const bitCapInt &mask, const bitCapInt &permutation)
Direct measure of masked permutation probability.
Definition: qinterface_noisy.hpp:365
void AntiCISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary (anti) control bits.
Definition: qinterface_noisy.hpp:311
real1_f CProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |1>.
Definition: qinterface_noisy.hpp:263
void IISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Inverse ISwap - Swap values of two bits in register, and apply phase factor of -i if bits are differe...
Definition: qinterface_noisy.hpp:338
real1_f Prob(bitLenInt qubitIndex)
Direct measure of bit probability to be in |1> state.
Definition: qinterface_noisy.hpp:363
void CISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary control bits.
Definition: qinterface_noisy.hpp:302
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: qinterface_noisy.hpp:377
void Copy(QInterfacePtr orig)
Definition: qinterface_noisy.hpp:55
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:141
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:275
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
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:268
bitLenInt qubitCount
Definition: qinterface.hpp:146
Half-precision floating-point type.
Definition: half.hpp:2222
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 void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qinterface.hpp:2992
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
@ QINTERFACE_TENSOR_NETWORK
Circuit-simplification layer.
Definition: qinterface.hpp:107
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
std::complex< real1 > complex
Definition: qrack_types.hpp:136
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:268
std::shared_ptr< QInterfaceNoisy > QInterfaceNoisyPtr
Definition: qinterface_noisy.hpp:20
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:208
float real1_f
Definition: qrack_types.hpp:103
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:267
const bitCapInt ONE_BCI
Definition: qrack_types.hpp:137
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:138
bitLenInt log2(bitCapInt n)
Definition: qrack_functions.hpp:141
half log(half arg)
Natural logarithm.
Definition: half.hpp:3318
half exp(half arg)
Exponential function.
Definition: half.hpp:3201
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:185
#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 bitCapIntOcl
Definition: qrack_types.hpp:54
#define ONE_R1_F
Definition: qrack_types.hpp:171