Qrack  9.13
General classical-emulating-quantum development framework
qinterface_noisy.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano and the Qrack contributors 2017-2023. All rights reserved.
4 //
5 // This is a multithreaded, universal quantum register simulation, allowing
6 // (nonphysical) register cloning and direct measurement of probability and
7 // phase, to leverage what advantages classical emulation of qubits can have.
8 //
9 // Licensed under the GNU Lesser General Public License V3.
10 // See LICENSE.md in the project root or https://www.gnu.org/licenses/lgpl-3.0.en.html
11 // for details.
12 #pragma once
13 
14 #if ENABLE_ALU
15 #include "qalu.hpp"
16 #endif
17 
18 namespace Qrack {
19 
20 class QInterfaceNoisy;
21 typedef std::shared_ptr<QInterfaceNoisy> QInterfaceNoisyPtr;
22 
26 class QInterfaceNoisy : public QInterface {
27 protected:
28  double logFidelity;
31  std::vector<QInterfaceEngine> engines;
32 
34  {
35  real1_f n = noiseParam;
36 #if ENABLE_ENV_VARS
37  if (getenv("QRACK_GATE_DEPOLARIZATION")) {
38  n = (real1_f)std::stof(std::string(getenv("QRACK_GATE_DEPOLARIZATION")));
39  }
40 #endif
41  if (n <= ZERO_R1_F) {
42  return;
43  }
44  engine->DepolarizingChannelWeak1Qb(qb, n);
45  if ((n + FP_NORM_EPSILON) >= ONE_R1_F) {
46  logFidelity = -1 * std::numeric_limits<float>::infinity();
47  } else {
48  logFidelity += (double)log(ONE_R1_F - n);
49  }
50  }
51 
52  using QInterface::Copy;
53  void Copy(QInterfacePtr orig) { Copy(std::dynamic_pointer_cast<QInterfaceNoisy>(orig)); }
55  {
56  QInterface::Copy(orig);
57  logFidelity = orig->logFidelity;
58  noiseParam = orig->noiseParam;
59  engine = orig->engine;
60  engines = orig->engines;
61  }
62 
63 public:
64  QInterfaceNoisy(bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI, qrack_rand_gen_ptr rgp = nullptr,
65  const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false, bool randomGlobalPhase = true,
66  bool useHostMem = false, int64_t deviceId = -1, bool useHardwareRNG = true, bool useSparseStateVec = false,
67  real1_f norm_thresh = REAL1_EPSILON, std::vector<int64_t> devList = {}, bitLenInt qubitThreshold = 0U,
68  real1_f separation_thresh = _qrack_qunit_sep_thresh)
69  : QInterfaceNoisy({ QINTERFACE_TENSOR_NETWORK }, qBitCount, initState, rgp, phaseFac, doNorm, randomGlobalPhase,
70  useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold,
71  separation_thresh)
72  {
73  // Intentionally left blank;
74  }
75 
76  QInterfaceNoisy(std::vector<QInterfaceEngine> eng, bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI,
77  qrack_rand_gen_ptr rgp = nullptr, const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false,
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 = {},
80  bitLenInt qubitThreshold = 0U, real1_f separation_thresh = _qrack_qunit_sep_thresh);
81 
84  , engine(o->engine)
85  , engines(o->engines)
86  {
87  engine = o->engine->Clone();
88  }
89 
90  void SetNoiseParameter(real1_f lambda) { noiseParam = lambda; }
92 
93  double GetUnitaryFidelity() { return (double)exp(logFidelity); }
95 
97  {
99  engine->SetQubitCount(qb);
100  }
101 
102  bool isOpenCL() { return engine->isOpenCL(); }
103 
104  void SetConcurrency(uint32_t threadCount)
105  {
106  QInterface::SetConcurrency(threadCount);
107  engine->SetConcurrency(GetConcurrencyLevel());
108  }
109 
110  real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt& permutation)
111  {
112  return engine->ProbReg(start, length, permutation);
113  }
114 
116  {
117  SetQubitCount(qubitCount + length);
118  return engine->Allocate(start, length);
119  }
120  using QInterface::Compose;
122  {
123  SetQubitCount(qubitCount + toCopy->qubitCount);
124  return engine->Compose(toCopy->engine);
125  }
126  bitLenInt Compose(QInterfacePtr toCopy) { return Compose(std::dynamic_pointer_cast<QInterfaceNoisy>(toCopy)); }
128  {
129  SetQubitCount(qubitCount + toCopy->qubitCount);
130  return engine->Compose(toCopy->engine, start);
131  }
133  {
134  return Compose(std::dynamic_pointer_cast<QInterfaceNoisy>(toCopy), start);
135  }
137  {
138  SetQubitCount(qubitCount + toCopy->qubitCount);
139  return engine->ComposeNoClone(toCopy->engine);
140  }
142  {
143  return ComposeNoClone(std::dynamic_pointer_cast<QInterfaceNoisy>(toCopy));
144  }
145  using QInterface::Decompose;
147  {
148  Decompose(start, std::dynamic_pointer_cast<QInterfaceNoisy>(dest));
149  }
151  {
152  QInterfaceNoisyPtr dest = std::make_shared<QInterfaceNoisy>(this);
153  engine->Decompose(start, dest->engine);
154 
155  return dest;
156  }
158  {
159  return TryDecompose(start, std::dynamic_pointer_cast<QInterfaceNoisy>(dest), error_tol);
160  }
162  {
163  engine->Decompose(start, dest->engine);
164  SetQubitCount(qubitCount - dest->GetQubitCount());
165  }
166  void Dispose(bitLenInt start, bitLenInt length)
167  {
168  engine->Dispose(start, length);
169  SetQubitCount(qubitCount - length);
170  }
171  void Dispose(bitLenInt start, bitLenInt length, const bitCapInt& disposedPerm)
172  {
173  engine->Dispose(start, length, disposedPerm);
174  SetQubitCount(qubitCount - length);
175  }
176 
178  {
179  const bitLenInt nQubitCount = qubitCount - dest->GetQubitCount();
180  const bool result = engine->TryDecompose(start, dest->engine, error_tol);
181  if (result) {
182  SetQubitCount(nQubitCount);
183  }
184  return result;
185  }
186 
187  void SetQuantumState(const complex* inputState) { engine->SetQuantumState(inputState); }
188  void GetQuantumState(complex* outputState) { engine->GetQuantumState(outputState); }
189  void GetProbs(real1* outputProbs) { engine->GetProbs(outputProbs); }
190  complex GetAmplitude(const bitCapInt& perm) { return engine->GetAmplitude(perm); }
191  void SetAmplitude(const bitCapInt& perm, const complex& amp) { engine->SetAmplitude(perm, amp); }
192  void SetPermutation(const bitCapInt& perm, const complex& phaseFac = CMPLX_DEFAULT_ARG)
193  {
194  engine->SetPermutation(perm, phaseFac);
195  }
196 
197  void Mtrx(const complex* mtrx, bitLenInt qubitIndex)
198  {
199  engine->Mtrx(mtrx, qubitIndex);
200  Apply1QbNoise(qubitIndex);
201  }
202  void Phase(const complex& topLeft, const complex& bottomRight, bitLenInt qubitIndex)
203  {
204  engine->Phase(topLeft, bottomRight, qubitIndex);
205  Apply1QbNoise(qubitIndex);
206  }
207  void Invert(const complex& topRight, const complex& bottomLeft, bitLenInt qubitIndex)
208  {
209  engine->Invert(topRight, bottomLeft, qubitIndex);
210  Apply1QbNoise(qubitIndex);
211  }
212  void MCMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
213  {
214  engine->MCMtrx(controls, mtrx, target);
215  Apply1QbNoise(target);
216  }
217  void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
218  {
219  engine->MACMtrx(controls, mtrx, target);
220  Apply1QbNoise(target);
221  }
222 
224  void UniformlyControlledSingleBit(const std::vector<bitLenInt>& controls, bitLenInt qubitIndex,
225  const complex* mtrxs, const std::vector<bitCapInt> mtrxSkipPowers, const bitCapInt& mtrxSkipValueMask)
226  {
227  engine->UniformlyControlledSingleBit(controls, qubitIndex, mtrxs, mtrxSkipPowers, mtrxSkipValueMask);
228  Apply1QbNoise(qubitIndex);
229  for (const bitLenInt& control : controls) {
230  Apply1QbNoise(control);
231  }
232  }
233 
234  void XMask(const bitCapInt& _mask)
235  {
236  bitCapInt mask = _mask;
237  engine->XMask(mask);
238  bitCapInt v = mask;
239  while (bi_compare_0(mask) != 0) {
240  v = v & (v - ONE_BCI);
241  Apply1QbNoise(log2(mask ^ v));
242  mask = v;
243  }
244  }
245  void PhaseParity(real1_f radians, const bitCapInt& _mask)
246  {
247  bitCapInt mask = _mask;
248  engine->PhaseParity(radians, mask);
249  bitCapInt v = mask;
250  while (bi_compare_0(mask) != 0) {
251  v = v & (v - ONE_BCI);
252  Apply1QbNoise(log2(mask ^ v));
253  mask = v;
254  }
255  }
256 
257  real1_f CProb(bitLenInt control, bitLenInt target) { return engine->CProb(control, target); }
258  real1_f ACProb(bitLenInt control, bitLenInt target) { return engine->ACProb(control, target); }
259 
260  void CSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
261  {
262  engine->CSwap(controls, qubit1, qubit2);
263  Apply1QbNoise(qubit1);
264  Apply1QbNoise(qubit2);
265  for (const bitLenInt& control : controls) {
266  Apply1QbNoise(control);
267  }
268  }
269  void AntiCSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
270  {
271  engine->AntiCSwap(controls, qubit1, qubit2);
272  Apply1QbNoise(qubit1);
273  Apply1QbNoise(qubit2);
274  for (const bitLenInt& control : controls) {
275  Apply1QbNoise(control);
276  }
277  }
278  void CSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
279  {
280  engine->CSqrtSwap(controls, qubit1, qubit2);
281  Apply1QbNoise(qubit1);
282  Apply1QbNoise(qubit2);
283  for (const bitLenInt& control : controls) {
284  Apply1QbNoise(control);
285  }
286  }
287  void AntiCSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
288  {
289  engine->AntiCSqrtSwap(controls, qubit1, qubit2);
290  Apply1QbNoise(qubit1);
291  Apply1QbNoise(qubit2);
292  for (const bitLenInt& control : controls) {
293  Apply1QbNoise(control);
294  }
295  }
296  void CISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
297  {
298  engine->CISqrtSwap(controls, qubit1, qubit2);
299  Apply1QbNoise(qubit1);
300  Apply1QbNoise(qubit2);
301  for (const bitLenInt& control : controls) {
302  Apply1QbNoise(control);
303  }
304  }
305  void AntiCISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
306  {
307  engine->AntiCISqrtSwap(controls, qubit1, qubit2);
308  Apply1QbNoise(qubit1);
309  Apply1QbNoise(qubit2);
310  for (const bitLenInt& control : controls) {
311  Apply1QbNoise(control);
312  }
313  }
314 
315  bool ForceM(bitLenInt qubit, bool result, bool doForce = true, bool doApply = true)
316  {
317  return engine->ForceM(qubit, result, doForce, doApply);
318  }
319 
320  void Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
321  {
322  engine->Swap(qubitIndex1, qubitIndex2);
323  Apply1QbNoise(qubitIndex1);
324  Apply1QbNoise(qubitIndex2);
325  }
326  void ISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
327  {
328  engine->ISwap(qubitIndex1, qubitIndex2);
329  Apply1QbNoise(qubitIndex1);
330  Apply1QbNoise(qubitIndex2);
331  }
332  void IISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
333  {
334  engine->IISwap(qubitIndex1, qubitIndex2);
335  Apply1QbNoise(qubitIndex1);
336  Apply1QbNoise(qubitIndex2);
337  }
338  void SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
339  {
340  engine->SqrtSwap(qubitIndex1, qubitIndex2);
341  Apply1QbNoise(qubitIndex1);
342  Apply1QbNoise(qubitIndex2);
343  }
344  void ISqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
345  {
346  engine->ISqrtSwap(qubitIndex1, qubitIndex2);
347  Apply1QbNoise(qubitIndex1);
348  Apply1QbNoise(qubitIndex2);
349  }
350  void FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2)
351  {
352  engine->FSim(theta, phi, qubitIndex1, qubitIndex2);
353  Apply1QbNoise(qubitIndex1);
354  Apply1QbNoise(qubitIndex2);
355  }
356 
357  real1_f Prob(bitLenInt qubitIndex) { return engine->Prob(qubitIndex); }
358  real1_f ProbAll(const bitCapInt& fullRegister) { return engine->ProbAll(fullRegister); }
359  real1_f ProbMask(const bitCapInt& mask, const bitCapInt& permutation)
360  {
361  return engine->ProbMask(mask, permutation);
362  }
363 
365  {
366  return SumSqrDiff(std::dynamic_pointer_cast<QInterfaceNoisy>(toCompare));
367  }
368  real1_f SumSqrDiff(QInterfaceNoisyPtr toCompare) { return engine->SumSqrDiff(toCompare->engine); }
369 
370  void UpdateRunningNorm(real1_f norm_thresh = REAL1_DEFAULT_ARG) { engine->UpdateRunningNorm(norm_thresh); }
372  real1_f nrm = REAL1_DEFAULT_ARG, real1_f norm_thresh = REAL1_DEFAULT_ARG, real1_f phaseArg = ZERO_R1_F)
373  {
374  engine->NormalizeState(nrm, norm_thresh, phaseArg);
375  }
376 
377  real1_f ExpectationBitsAll(const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
378  {
379  return engine->ExpectationBitsAll(bits, offset);
380  }
381 
382  void Finish() { engine->Finish(); }
383 
384  bool isFinished() { return engine->isFinished(); }
385 
386  void Dump() { engine->Dump(); }
387 
388  QInterfacePtr Clone() { return std::make_shared<QInterfaceNoisy>(this); }
389 
390  void SetDevice(int64_t dID) { engine->SetDevice(dID); }
391 
392  int64_t GetDevice() { return engine->GetDevice(); }
393 
394  bitCapIntOcl GetMaxSize() { return engine->GetMaxSize(); };
395 };
396 } // namespace Qrack
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 &amp)
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