20 class QInterfaceNoisy;
37 if (getenv(
"QRACK_GATE_DEPOLARIZATION")) {
38 n = (
real1_f)std::stof(std::string(getenv(
"QRACK_GATE_DEPOLARIZATION")));
44 engine->DepolarizingChannelWeak1Qb(qb, n);
46 logFidelity = -1 * std::numeric_limits<float>::infinity();
66 bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
bool useSparseStateVec =
false,
70 useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold,
78 bool randomGlobalPhase =
true,
bool useHostMem =
false, int64_t deviceId = -1,
bool useHardwareRNG =
true,
79 bool useSparseStateVec =
false,
real1_f norm_thresh =
REAL1_EPSILON, std::vector<int64_t> devList = {},
112 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);
219 engine->MACMtrx(controls, mtrx, target);
225 const complex* mtrxs,
const std::vector<bitCapInt> mtrxSkipPowers,
const bitCapInt& mtrxSkipValueMask)
227 engine->UniformlyControlledSingleBit(controls, qubitIndex, mtrxs, mtrxSkipPowers, mtrxSkipValueMask);
229 for (
const bitLenInt& control : controls) {
248 engine->PhaseParity(radians, mask);
262 engine->CSwap(controls, qubit1, qubit2);
265 for (
const bitLenInt& control : controls) {
271 engine->AntiCSwap(controls, qubit1, qubit2);
274 for (
const bitLenInt& control : controls) {
280 engine->CSqrtSwap(controls, qubit1, qubit2);
283 for (
const bitLenInt& control : controls) {
289 engine->AntiCSqrtSwap(controls, qubit1, qubit2);
292 for (
const bitLenInt& control : controls) {
298 engine->CISqrtSwap(controls, qubit1, qubit2);
301 for (
const bitLenInt& control : controls) {
307 engine->AntiCISqrtSwap(controls, qubit1, qubit2);
310 for (
const bitLenInt& control : controls) {
317 return engine->ForceM(qubit, result, doForce, doApply);
322 engine->Swap(qubitIndex1, qubitIndex2);
328 engine->ISwap(qubitIndex1, qubitIndex2);
334 engine->IISwap(qubitIndex1, qubitIndex2);
340 engine->SqrtSwap(qubitIndex1, qubitIndex2);
346 engine->ISqrtSwap(qubitIndex1, qubitIndex2);
352 engine->FSim(theta, phi, qubitIndex1, qubitIndex2);
361 return engine->ProbMask(mask, permutation);
366 return SumSqrDiff(std::dynamic_pointer_cast<QInterfaceNoisy>(toCompare));
374 engine->NormalizeState(nrm, norm_thresh, phaseArg);
379 return engine->ExpectationBitsAll(bits, offset);
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:134
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:370
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 AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qinterface_noisy.hpp:269
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:217
void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qinterface_noisy.hpp:386
void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubitIndex, const complex *mtrxs, const std::vector< bitCapInt > mtrxSkipPowers, const bitCapInt &mtrxSkipValueMask)
Definition: qinterface_noisy.hpp:224
void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qinterface_noisy.hpp:260
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:64
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:326
double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qinterface_noisy.hpp:93
void SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Square root of Swap gate.
Definition: qinterface_noisy.hpp:338
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:364
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:377
real1_f SumSqrDiff(QInterfacePtr toCompare)
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
Definition: qinterface_noisy.hpp:364
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:287
real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt &permutation)
Direct measure of register permutation probability.
Definition: qinterface_noisy.hpp:110
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:91
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:388
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:382
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:278
void SetQubitCount(bitLenInt qb)
Definition: qinterface_noisy.hpp:96
std::vector< QInterfaceEngine > engines
Definition: qinterface_noisy.hpp:31
void PhaseParity(real1_f radians, const bitCapInt &_mask)
Parity phase gate.
Definition: qinterface_noisy.hpp:245
void SetConcurrency(uint32_t threadCount)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface_noisy.hpp:104
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:90
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:54
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:258
real1_f noiseParam
Definition: qinterface_noisy.hpp:29
bitCapIntOcl GetMaxSize()
Definition: qinterface_noisy.hpp:394
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:315
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:320
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:350
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:234
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:82
void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qinterface_noisy.hpp:390
real1_f SumSqrDiff(QInterfaceNoisyPtr toCompare)
Definition: qinterface_noisy.hpp:368
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:358
void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qinterface_noisy.hpp:94
void ISqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Inverse square root of Swap gate.
Definition: qinterface_noisy.hpp:344
bool isOpenCL()
Returns "true" if current simulation is OpenCL-based.
Definition: qinterface_noisy.hpp:102
bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qinterface_noisy.hpp:384
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:392
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:359
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:305
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:257
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:332
real1_f Prob(bitLenInt qubitIndex)
Direct measure of bit probability to be in |1> state.
Definition: qinterface_noisy.hpp:357
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:296
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:371
void Copy(QInterfacePtr orig)
Definition: qinterface_noisy.hpp:53
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 Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:364
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:627
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:2965
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:235
QRACK_CONST real1_f TRYDECOMPOSE_EPSILON
Definition: qrack_types.hpp:260
std::complex< real1 > complex
Definition: qrack_types.hpp:128
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:258
std::shared_ptr< QInterfaceNoisy > QInterfaceNoisyPtr
Definition: qinterface_noisy.hpp:20
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:200
float real1_f
Definition: qrack_types.hpp:95
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:257
const bitCapInt ONE_BCI
Definition: qrack_types.hpp:129
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:130
bitLenInt log2(bitCapInt n)
Definition: qrack_functions.hpp:134
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:177
#define bitLenInt
Definition: qrack_types.hpp:38
#define ZERO_R1_F
Definition: qrack_types.hpp:160
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:156
#define bitCapInt
Definition: qrack_types.hpp:62
#define bitCapIntOcl
Definition: qrack_types.hpp:50
#define ONE_R1_F
Definition: qrack_types.hpp:163