Qrack  10.0
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 
45  engine->DepolarizingChannelWeak1Qb(qb, n);
46 
47  if ((n + FP_NORM_EPSILON) >= ONE_R1_F) {
48  logFidelity = -1 * std::numeric_limits<float>::infinity();
49  } else {
50  logFidelity += (double)log(ONE_R1_F - n);
51  }
52  }
53 
54  using QInterface::Copy;
55  void Copy(QInterfacePtr orig) { Copy(std::dynamic_pointer_cast<QInterfaceNoisy>(orig)); }
57  {
58  QInterface::Copy(orig);
59  logFidelity = orig->logFidelity;
60  noiseParam = orig->noiseParam;
61  engine = orig->engine;
62  engines = orig->engines;
63  }
64 
65 public:
66  QInterfaceNoisy(bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI, qrack_rand_gen_ptr rgp = nullptr,
67  const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false, bool randomGlobalPhase = true,
68  bool useHostMem = false, int64_t deviceId = -1, bool useHardwareRNG = true, bool useSparseStateVec = false,
69  real1_f norm_thresh = REAL1_EPSILON, std::vector<int64_t> devList = {}, bitLenInt qubitThreshold = 0U,
70  real1_f separation_thresh = _qrack_qunit_sep_thresh)
71  : QInterfaceNoisy({ QINTERFACE_TENSOR_NETWORK }, qBitCount, initState, rgp, phaseFac, doNorm, randomGlobalPhase,
72  useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold,
73  separation_thresh)
74  {
75  // Intentionally left blank;
76  }
77 
78  QInterfaceNoisy(std::vector<QInterfaceEngine> eng, bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI,
79  qrack_rand_gen_ptr rgp = nullptr, const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false,
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 = {},
82  bitLenInt qubitThreshold = 0U, real1_f separation_thresh = _qrack_qunit_sep_thresh);
83 
86  , engine(o->engine)
87  , engines(o->engines)
88  {
89  engine = o->engine->Clone();
90  }
91 
92  void SetSdrp(real1_f sdrp) { engine->SetSdrp(sdrp); }
93  void SetReactiveSeparate(bool isAggSep) { engine->SetReactiveSeparate(isAggSep); }
94 
95  void SetNoiseParameter(real1_f lambda) { noiseParam = lambda; }
97 
98  double GetUnitaryFidelity() { return (double)exp(logFidelity); }
100 
101  bool isOpenCL() { return engine->isOpenCL(); }
102 
103  void SetConcurrency(uint32_t threadCount)
104  {
105  QInterface::SetConcurrency(threadCount);
106  engine->SetConcurrency(GetConcurrencyLevel());
107  }
108 
109  real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt& permutation)
110  {
111  return engine->ProbReg(start, length, permutation);
112  }
113 
114  using QInterface::Allocate;
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  for (const bitLenInt& control : controls) {
217  Apply1QbNoise(control);
218  }
219  }
220  void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
221  {
222  engine->MACMtrx(controls, mtrx, target);
223  Apply1QbNoise(target);
224  for (const bitLenInt& control : controls) {
225  Apply1QbNoise(control);
226  }
227  }
228 
230  void UniformlyControlledSingleBit(const std::vector<bitLenInt>& controls, bitLenInt qubitIndex,
231  const complex* mtrxs, const std::vector<bitCapInt> mtrxSkipPowers, const bitCapInt& mtrxSkipValueMask)
232  {
233  engine->UniformlyControlledSingleBit(controls, qubitIndex, mtrxs, mtrxSkipPowers, mtrxSkipValueMask);
234  Apply1QbNoise(qubitIndex);
235  for (const bitLenInt& control : controls) {
236  Apply1QbNoise(control);
237  }
238  }
239 
240  void XMask(const bitCapInt& _mask)
241  {
242  bitCapInt mask = _mask;
243  engine->XMask(mask);
244  bitCapInt v = mask;
245  while (bi_compare_0(mask) != 0) {
246  v = v & (v - ONE_BCI);
247  Apply1QbNoise(log2(mask ^ v));
248  mask = v;
249  }
250  }
251  void PhaseParity(real1_f radians, const bitCapInt& _mask)
252  {
253  bitCapInt mask = _mask;
254  engine->PhaseParity(radians, mask);
255  bitCapInt v = mask;
256  while (bi_compare_0(mask) != 0) {
257  v = v & (v - ONE_BCI);
258  Apply1QbNoise(log2(mask ^ v));
259  mask = v;
260  }
261  }
262 
263  real1_f CProb(bitLenInt control, bitLenInt target) { return engine->CProb(control, target); }
264  real1_f ACProb(bitLenInt control, bitLenInt target) { return engine->ACProb(control, target); }
265 
266  void CSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
267  {
268  engine->CSwap(controls, qubit1, qubit2);
269  Apply1QbNoise(qubit1);
270  Apply1QbNoise(qubit2);
271  for (const bitLenInt& control : controls) {
272  Apply1QbNoise(control);
273  }
274  }
275  void AntiCSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
276  {
277  engine->AntiCSwap(controls, qubit1, qubit2);
278  Apply1QbNoise(qubit1);
279  Apply1QbNoise(qubit2);
280  for (const bitLenInt& control : controls) {
281  Apply1QbNoise(control);
282  }
283  }
284  void CSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
285  {
286  engine->CSqrtSwap(controls, qubit1, qubit2);
287  Apply1QbNoise(qubit1);
288  Apply1QbNoise(qubit2);
289  for (const bitLenInt& control : controls) {
290  Apply1QbNoise(control);
291  }
292  }
293  void AntiCSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
294  {
295  engine->AntiCSqrtSwap(controls, qubit1, qubit2);
296  Apply1QbNoise(qubit1);
297  Apply1QbNoise(qubit2);
298  for (const bitLenInt& control : controls) {
299  Apply1QbNoise(control);
300  }
301  }
302  void CISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
303  {
304  engine->CISqrtSwap(controls, qubit1, qubit2);
305  Apply1QbNoise(qubit1);
306  Apply1QbNoise(qubit2);
307  for (const bitLenInt& control : controls) {
308  Apply1QbNoise(control);
309  }
310  }
311  void AntiCISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2)
312  {
313  engine->AntiCISqrtSwap(controls, qubit1, qubit2);
314  Apply1QbNoise(qubit1);
315  Apply1QbNoise(qubit2);
316  for (const bitLenInt& control : controls) {
317  Apply1QbNoise(control);
318  }
319  }
320 
321  bool ForceM(bitLenInt qubit, bool result, bool doForce = true, bool doApply = true)
322  {
323  return engine->ForceM(qubit, result, doForce, doApply);
324  }
325 
326  void Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
327  {
328  engine->Swap(qubitIndex1, qubitIndex2);
329  Apply1QbNoise(qubitIndex1);
330  Apply1QbNoise(qubitIndex2);
331  }
332  void ISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
333  {
334  engine->ISwap(qubitIndex1, qubitIndex2);
335  Apply1QbNoise(qubitIndex1);
336  Apply1QbNoise(qubitIndex2);
337  }
338  void IISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
339  {
340  engine->IISwap(qubitIndex1, qubitIndex2);
341  Apply1QbNoise(qubitIndex1);
342  Apply1QbNoise(qubitIndex2);
343  }
344  void SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
345  {
346  engine->SqrtSwap(qubitIndex1, qubitIndex2);
347  Apply1QbNoise(qubitIndex1);
348  Apply1QbNoise(qubitIndex2);
349  }
350  void ISqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
351  {
352  engine->ISqrtSwap(qubitIndex1, qubitIndex2);
353  Apply1QbNoise(qubitIndex1);
354  Apply1QbNoise(qubitIndex2);
355  }
356  void FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2)
357  {
358  engine->FSim(theta, phi, qubitIndex1, qubitIndex2);
359  Apply1QbNoise(qubitIndex1);
360  Apply1QbNoise(qubitIndex2);
361  }
362 
363  real1_f Prob(bitLenInt qubitIndex) { return engine->Prob(qubitIndex); }
364  real1_f ProbAll(const bitCapInt& fullRegister) { return engine->ProbAll(fullRegister); }
365  real1_f ProbMask(const bitCapInt& mask, const bitCapInt& permutation)
366  {
367  return engine->ProbMask(mask, permutation);
368  }
369 
371  {
372  return SumSqrDiff(std::dynamic_pointer_cast<QInterfaceNoisy>(toCompare));
373  }
374  real1_f SumSqrDiff(QInterfaceNoisyPtr toCompare) { return engine->SumSqrDiff(toCompare->engine); }
375 
376  void UpdateRunningNorm(real1_f norm_thresh = REAL1_DEFAULT_ARG) { engine->UpdateRunningNorm(norm_thresh); }
378  real1_f nrm = REAL1_DEFAULT_ARG, real1_f norm_thresh = REAL1_DEFAULT_ARG, real1_f phaseArg = ZERO_R1_F)
379  {
380  engine->NormalizeState(nrm, norm_thresh, phaseArg);
381  }
382 
383  real1_f ExpectationBitsAll(const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
384  {
385  return engine->ExpectationBitsAll(bits, offset);
386  }
387 
388  void Finish() { engine->Finish(); }
389 
390  bool isFinished() { return engine->isFinished(); }
391 
392  void Dump() { engine->Dump(); }
393 
394  QInterfacePtr Clone() { return std::make_shared<QInterfaceNoisy>(this); }
395 
396  void SetDevice(int64_t dID) { engine->SetDevice(dID); }
397  void SetDeviceList(std::vector<int64_t> dIDs) { engine->SetDeviceList(dIDs); }
398  int64_t GetDevice() { return engine->GetDevice(); }
399  std::vector<int64_t> GetDeviceList() { return engine->GetDeviceList(); }
400 
401  bitCapIntOcl GetMaxSize() { return engine->GetMaxSize(); };
402 };
403 } // namespace Qrack
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 &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: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