Qrack  9.9
General classical-emulating-quantum development framework
qstabilizerhybrid.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 #include "mpsshard.hpp"
15 #include "qengine.hpp"
16 #include "qunitclifford.hpp"
17 
18 #define QINTERFACE_TO_QALU(qReg) std::dynamic_pointer_cast<QAlu>(qReg)
19 #define QINTERFACE_TO_QPARITY(qReg) std::dynamic_pointer_cast<QParity>(qReg)
20 
21 namespace Qrack {
22 
26 
28  : amp(a)
29  , stabilizer(s)
30  {
31  // Intentionally left blank.
32  }
33 };
34 
35 class QStabilizerHybrid;
36 typedef std::shared_ptr<QStabilizerHybrid> QStabilizerHybridPtr;
37 
42 #if ENABLE_ALU
43 class QStabilizerHybrid : public QAlu, public QParity, public QInterface {
44 #else
45 class QStabilizerHybrid : public QParity, public QInterface {
46 #endif
47 protected:
48  bool useHostRam;
50  bool isSparse;
51  bool useTGadget;
61  int64_t devID;
63  double logFidelity;
66  std::vector<int64_t> deviceIDs;
67  std::vector<QInterfaceEngine> engineTypes;
68  std::vector<QInterfaceEngine> cloneEngineTypes;
69  std::vector<MpsShardPtr> shards;
71 
74  QInterfacePtr MakeEngine(const bitCapInt& perm, bitLenInt qbCount);
75 
76  void InvertBuffer(bitLenInt qubit);
77  void FlushH(bitLenInt qubit);
78  void FlushIfBlocked(bitLenInt control, bitLenInt target, bool isPhase = false);
80  bool TrimControls(const std::vector<bitLenInt>& lControls, std::vector<bitLenInt>& output, bool anti = false);
81  void CacheEigenstate(bitLenInt target);
82  void FlushBuffers();
83  void DumpBuffers()
84  {
85  for (size_t i = 0U; i < shards.size(); ++i) {
86  shards[i] = NULL;
87  }
88  }
89  bool EitherIsBuffered(bool logical)
90  {
91  const size_t maxLcv = logical ? (size_t)qubitCount : shards.size();
92  for (size_t i = 0U; i < maxLcv; ++i) {
93  if (shards[i]) {
94  // We have a cached non-Clifford operation.
95  return true;
96  }
97  }
98 
99  return false;
100  }
101  bool IsBuffered() { return EitherIsBuffered(false); }
102  bool IsLogicalBuffered() { return EitherIsBuffered(true); }
103  bool EitherIsProbBuffered(bool logical)
104  {
105  const size_t maxLcv = logical ? (size_t)qubitCount : shards.size();
106  for (size_t i = 0U; i < maxLcv; ++i) {
107  MpsShardPtr shard = shards[i];
108  if (!shard) {
109  continue;
110  }
111  if (shard->IsHPhase() || shard->IsHInvert()) {
112  FlushH(i);
113  }
114  if (shard->IsInvert()) {
115  InvertBuffer(i);
116  }
117  if (!shard->IsPhase()) {
118  // We have a cached non-Clifford operation.
119  return true;
120  }
121  }
122 
123  return false;
124  }
125  bool IsProbBuffered() { return EitherIsProbBuffered(false); }
127 
128  std::unique_ptr<complex[]> GetQubitReducedDensityMatrix(bitLenInt qubit)
129  {
130  // Form the reduced density matrix of the single qubit.
131  const real1 z = (real1)(ONE_R1_F - 2 * stabilizer->Prob(qubit));
132  stabilizer->H(qubit);
133  const real1 x = (real1)(ONE_R1_F - 2 * stabilizer->Prob(qubit));
134  stabilizer->S(qubit);
135  const real1 y = (real1)(ONE_R1_F - 2 * stabilizer->Prob(qubit));
136  stabilizer->IS(qubit);
137  stabilizer->H(qubit);
138 
139  std::unique_ptr<complex[]> dMtrx(new complex[4]);
140  dMtrx[0] = (ONE_CMPLX + z) / complex((real1)2, ZERO_R1);
141  dMtrx[1] = x / complex((real1)2, ZERO_R1) - I_CMPLX * (y / complex((real1)2, ZERO_R1));
142  dMtrx[2] = x / complex((real1)2, ZERO_R1) + I_CMPLX * (y / complex((real1)2, ZERO_R1));
143  dMtrx[3] = (ONE_CMPLX + z) / complex((real1)2, ZERO_R1);
144  if (shards[qubit]) {
145  const complex adj[4]{ std::conj(shards[qubit]->gate[0]), std::conj(shards[qubit]->gate[2]),
146  std::conj(shards[qubit]->gate[1]), std::conj(shards[qubit]->gate[3]) };
147  complex out[4];
148  mul2x2(dMtrx.get(), adj, out);
149  mul2x2(shards[qubit]->gate, out, dMtrx.get());
150  }
151 
152  return dMtrx;
153  }
154 
155  template <typename F>
156  void CheckShots(unsigned shots, const bitCapInt& m, real1_f partProb, const std::vector<bitCapInt>& qPowers,
157  std::vector<real1_f>& rng, F fn)
158  {
159  for (int64_t shot = rng.size() - 1U; shot >= 0; --shot) {
160  if (rng[shot] >= partProb) {
161  break;
162  }
163 
164  bitCapInt sample = ZERO_BCI;
165  for (size_t i = 0U; i < qPowers.size(); ++i) {
166  if (bi_compare_0(m & qPowers[i]) != 0) {
167  bi_or_ip(&sample, pow2(i));
168  }
169  }
170  fn(sample, shot);
171 
172  rng.erase(rng.begin() + shot);
173  if (rng.empty()) {
174  break;
175  }
176  }
177  }
178 
179  std::vector<real1_f> GenerateShotProbs(unsigned shots)
180  {
181  std::vector<real1_f> rng;
182  rng.reserve(shots);
183  for (unsigned shot = 0U; shot < shots; ++shot) {
184  rng.push_back(Rand());
185  }
186  std::sort(rng.begin(), rng.end());
187  std::reverse(rng.begin(), rng.end());
188 
189  return rng;
190  }
191 
192  real1_f FractionalRzAngleWithFlush(bitLenInt i, real1_f angle, bool isGateSuppressed = false)
193  {
194  const real1_f sectorAngle = PI_R1 / 2;
195  const real1_f Period = 2 * PI_R1;
196  while (angle >= Period) {
197  angle -= Period;
198  }
199  while (angle < 0U) {
200  angle += Period;
201  }
202 
203  const long sector = std::lround((real1_s)(angle / sectorAngle));
204  if (!isGateSuppressed) {
205  switch (sector) {
206  case 1:
207  stabilizer->S(i);
208  break;
209  case 2:
210  stabilizer->Z(i);
211  break;
212  case 3:
213  stabilizer->IS(i);
214  break;
215  case 0:
216  default:
217  break;
218  }
219  }
220 
221  angle -= (sector * sectorAngle);
222  if (angle > PI_R1) {
223  angle -= Period;
224  }
225  if (angle <= -PI_R1) {
226  angle += Period;
227  }
228 
229  return angle;
230  }
231 
233  {
234  for (size_t i = 0U; i < qubitCount; ++i) {
235  // Flush all buffers as close as possible to Clifford.
236  const MpsShardPtr& shard = shards[i];
237  if (!shard) {
238  continue;
239  }
240  if (shard->IsHPhase() || shard->IsHInvert()) {
241  FlushH(i);
242  }
243  if (shard->IsInvert()) {
244  InvertBuffer(i);
245  }
246  if (!shard->IsPhase()) {
247  // We have a cached non-phase operation.
248  continue;
249  }
250  const real1 angle = (real1)(FractionalRzAngleWithFlush(i, std::arg(shard->gate[3U] / shard->gate[0U])) / 2);
251  if ((2 * abs(angle) / PI_R1) <= FP_NORM_EPSILON) {
252  shards[i] = NULL;
253  continue;
254  }
255  const real1 angleCos = cos(angle);
256  const real1 angleSin = sin(angle);
257  shard->gate[0U] = complex(angleCos, -angleSin);
258  shard->gate[3U] = complex(angleCos, angleSin);
259  }
260 
261  RdmCloneFlush();
262  }
263 
265  {
266  QStabilizerHybridPtr clone = std::dynamic_pointer_cast<QStabilizerHybrid>(Clone());
267  clone->RdmCloneFlush(ONE_R1 / 2);
268 
269  return clone;
270  }
271  void RdmCloneFlush(real1_f threshold = FP_NORM_EPSILON);
272 
273  real1_f ExpVarFactorized(bool isExp, bool isFloat, const std::vector<bitLenInt>& bits,
274  const std::vector<bitCapInt>& perms, const std::vector<real1_f>& weights, const bitCapInt& offset, bool roundRz)
275  {
276  if (engine) {
277  return isExp ? isFloat ? engine->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
278  : engine->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
279  : isFloat ? engine->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
280  : engine->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset);
281  }
282 
283  if (!roundRz) {
284  return isExp ? isFloat ? stabilizer->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
285  : stabilizer->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
286  : isFloat ? stabilizer->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
287  : stabilizer->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset);
288  }
289 
290  return isExp ? isFloat
291  ? RdmCloneHelper()->stabilizer->ExpectationFloatsFactorizedRdm(roundRz, bits, weights)
292  : RdmCloneHelper()->stabilizer->ExpectationBitsFactorizedRdm(roundRz, bits, perms, offset)
293  : isFloat ? RdmCloneHelper()->stabilizer->VarianceFloatsFactorizedRdm(roundRz, bits, weights)
294  : RdmCloneHelper()->stabilizer->VarianceBitsFactorizedRdm(roundRz, bits, perms, offset);
295  }
296 
298  {
299  if (stabilizer->TrySeparate(i)) {
300  stabilizer->Dispose(i, 1U);
301  shards.erase(shards.begin() + i);
302  } else {
303  const bitLenInt deadIndex = qubitCount + ancillaCount - 1U;
304  stabilizer->SetBit(i, false);
305  if (i != deadIndex) {
306  stabilizer->Swap(i, deadIndex);
307  shards[i].swap(shards[deadIndex]);
308  }
309  shards.erase(shards.begin() + deadIndex);
311  }
312  --ancillaCount;
313  }
314 
316  QStabilizerHybridPtr toCompare, bool isDiscreteBool, real1_f error_tol = TRYDECOMPOSE_EPSILON);
317 
318  void ISwapHelper(bitLenInt qubit1, bitLenInt qubit2, bool inverse);
319 
320  complex GetAmplitudeOrProb(const bitCapInt& perm, bool isProb = false);
321 
322 public:
323  QStabilizerHybrid(std::vector<QInterfaceEngine> eng, bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI,
324  qrack_rand_gen_ptr rgp = nullptr, const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false,
325  bool randomGlobalPhase = true, bool useHostMem = false, int64_t deviceId = -1, bool useHardwareRNG = true,
326  bool useSparseStateVec = false, real1_f norm_thresh = REAL1_EPSILON, std::vector<int64_t> devList = {},
327  bitLenInt qubitThreshold = 0U, real1_f separation_thresh = _qrack_qunit_sep_thresh);
328 
329  QStabilizerHybrid(bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI, qrack_rand_gen_ptr rgp = nullptr,
330  const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false, bool randomGlobalPhase = true,
331  bool useHostMem = false, int64_t deviceId = -1, bool useHardwareRNG = true, bool useSparseStateVec = false,
332  real1_f norm_thresh = REAL1_EPSILON, std::vector<int64_t> devList = {}, bitLenInt qubitThreshold = 0U,
333  real1_f separation_thresh = _qrack_qunit_sep_thresh)
334  : QStabilizerHybrid({ QINTERFACE_OPTIMAL_BASE }, qBitCount, initState, rgp, phaseFac, doNorm, randomGlobalPhase,
335  useHostMem, deviceId, useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold,
336  separation_thresh)
337  {
338  }
339 
340  void SetNcrp(real1_f ncrp) { roundingThreshold = ncrp; };
341  void SetTInjection(bool useGadget) { useTGadget = useGadget; }
342  bool GetTInjection() { return useTGadget; }
343  double GetUnitaryFidelity() { return exp(logFidelity); }
345 
346  void Finish()
347  {
348  if (stabilizer) {
349  stabilizer->Finish();
350  } else {
351  engine->Finish();
352  }
353  };
354 
355  bool isFinished() { return (!stabilizer || stabilizer->isFinished()) && (!engine || engine->isFinished()); }
356 
357  void Dump()
358  {
359  if (stabilizer) {
360  stabilizer->Dump();
361  } else {
362  engine->Dump();
363  }
364  }
365 
366  void SetConcurrency(uint32_t threadCount)
367  {
368  QInterface::SetConcurrency(threadCount);
369  if (engine) {
371  }
372  }
373 
375  {
376  if (!ancillaCount || stabilizer->IsSeparable(qubit)) {
377  return Prob(qubit);
378  }
379 
380  std::unique_ptr<complex[]> dMtrx = GetQubitReducedDensityMatrix(qubit);
381  QRACK_CONST complex ONE_CMPLX_NEG = complex(-ONE_R1, ZERO_R1);
382  QRACK_CONST complex pauliZ[4]{ ONE_CMPLX, ZERO_CMPLX, ZERO_CMPLX, ONE_CMPLX_NEG };
383  complex pMtrx[4];
384  mul2x2(dMtrx.get(), pauliZ, pMtrx);
385  return (ONE_R1 - std::real(pMtrx[0] + pMtrx[1])) / 2;
386  }
387 
389  {
390  AntiCNOT(control, target);
391  const real1_f prob = ProbRdm(target);
392  AntiCNOT(control, target);
393 
394  return prob;
395  }
396 
398  {
399  CNOT(control, target);
400  const real1_f prob = ProbRdm(target);
401  CNOT(control, target);
402 
403  return prob;
404  }
405 
411  void SwitchToEngine();
412 
413  bool isClifford() { return !engine; }
414 
415  bool isClifford(bitLenInt qubit) { return !engine && !shards[qubit]; };
416 
417  bool isBinaryDecisionTree() { return engine && engine->isBinaryDecisionTree(); };
418 
419  using QInterface::Compose;
420  bitLenInt Compose(QStabilizerHybridPtr toCopy) { return ComposeEither(toCopy, false); };
421  bitLenInt Compose(QInterfacePtr toCopy) { return Compose(std::dynamic_pointer_cast<QStabilizerHybrid>(toCopy)); }
424  {
425  return Compose(std::dynamic_pointer_cast<QStabilizerHybrid>(toCopy), start);
426  }
427  bitLenInt ComposeNoClone(QStabilizerHybridPtr toCopy) { return ComposeEither(toCopy, true); };
429  {
430  return ComposeNoClone(std::dynamic_pointer_cast<QStabilizerHybrid>(toCopy));
431  }
432  bitLenInt ComposeEither(QStabilizerHybridPtr toCopy, bool willDestroy);
434  {
435  Decompose(start, std::dynamic_pointer_cast<QStabilizerHybrid>(dest));
436  }
437  void Decompose(bitLenInt start, QStabilizerHybridPtr dest);
439  void Dispose(bitLenInt start, bitLenInt length);
440  void Dispose(bitLenInt start, bitLenInt length, const bitCapInt& disposedPerm);
441  using QInterface::Allocate;
442  bitLenInt Allocate(bitLenInt start, bitLenInt length);
443 
444  void GetQuantumState(complex* outputState);
445  void GetProbs(real1* outputProbs);
446  complex GetAmplitude(const bitCapInt& perm) { return GetAmplitudeOrProb(perm, false); }
447  real1_f ProbAll(const bitCapInt& perm) { return (real1_f)norm(GetAmplitudeOrProb(perm, true)); }
448  void SetQuantumState(const complex* inputState);
449  void SetAmplitude(const bitCapInt& perm, const complex& amp)
450  {
451  SwitchToEngine();
452  engine->SetAmplitude(perm, amp);
453  }
454  void SetPermutation(const bitCapInt& perm, const complex& phaseFac = CMPLX_DEFAULT_ARG);
455 
456  void Swap(bitLenInt qubit1, bitLenInt qubit2);
457  void ISwap(bitLenInt qubit1, bitLenInt qubit2) { ISwapHelper(qubit1, qubit2, false); }
458  void IISwap(bitLenInt qubit1, bitLenInt qubit2) { ISwapHelper(qubit1, qubit2, true); }
459  void CSwap(const std::vector<bitLenInt>& lControls, bitLenInt qubit1, bitLenInt qubit2);
460  void CSqrtSwap(const std::vector<bitLenInt>& lControls, bitLenInt qubit1, bitLenInt qubit2);
461  void AntiCSqrtSwap(const std::vector<bitLenInt>& lControls, bitLenInt qubit1, bitLenInt qubit2);
462  void CISqrtSwap(const std::vector<bitLenInt>& lControls, bitLenInt qubit1, bitLenInt qubit2);
463  void AntiCISqrtSwap(const std::vector<bitLenInt>& lControls, bitLenInt qubit1, bitLenInt qubit2);
464 
465  void XMask(const bitCapInt& mask);
466  void YMask(const bitCapInt& mask);
467  void ZMask(const bitCapInt& mask);
468 
469  real1_f Prob(bitLenInt qubit);
470 
471  bool ForceM(bitLenInt qubit, bool result, bool doForce = true, bool doApply = true);
472 
473  bitCapInt MAll();
474 
475  void Mtrx(const complex* mtrx, bitLenInt target);
476  void MCMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target);
477  void MCPhase(
478  const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight, bitLenInt target);
479  void MCInvert(
480  const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft, bitLenInt target);
481  void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target);
482  void MACPhase(
483  const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight, bitLenInt target);
484  void MACInvert(
485  const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft, bitLenInt target);
486 
489  const std::vector<bitLenInt>& controls, bitLenInt qubitIndex, const complex* mtrxs);
490 
491  std::map<bitCapInt, int> MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots);
492  void MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots, unsigned long long* shotsArray);
493 
494  real1_f ProbParity(const bitCapInt& mask);
495  bool ForceMParity(const bitCapInt& mask, bool result, bool doForce = true);
496  void CUniformParityRZ(const std::vector<bitLenInt>& controls, const bitCapInt& mask, real1_f angle)
497  {
498  SwitchToEngine();
499  QINTERFACE_TO_QPARITY(engine)->CUniformParityRZ(controls, mask, angle);
500  }
501 
502 #if ENABLE_ALU
503  using QInterface::M;
504  bool M(bitLenInt q) { return QInterface::M(q); }
505  using QInterface::X;
506  void X(bitLenInt q) { QInterface::X(q); }
507  void CPhaseFlipIfLess(const bitCapInt& greaterPerm, bitLenInt start, bitLenInt length, bitLenInt flagIndex)
508  {
509  SwitchToEngine();
510  QINTERFACE_TO_QALU(engine)->CPhaseFlipIfLess(greaterPerm, start, length, flagIndex);
511  }
512  void PhaseFlipIfLess(const bitCapInt& greaterPerm, bitLenInt start, bitLenInt length)
513  {
514  SwitchToEngine();
515  QINTERFACE_TO_QALU(engine)->PhaseFlipIfLess(greaterPerm, start, length);
516  }
517 
518  void INC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length)
519  {
520  if (stabilizer) {
521  QInterface::INC(toAdd, start, length);
522  return;
523  }
524 
525  engine->INC(toAdd, start, length);
526  }
527  void DEC(const bitCapInt& toSub, bitLenInt start, bitLenInt length)
528  {
529  if (stabilizer) {
530  QInterface::DEC(toSub, start, length);
531  return;
532  }
533 
534  engine->DEC(toSub, start, length);
535  }
536  void DECS(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
537  {
538  if (stabilizer) {
539  QInterface::DECS(toSub, start, length, overflowIndex);
540  return;
541  }
542 
543  engine->DECS(toSub, start, length, overflowIndex);
544  }
545  void CINC(const bitCapInt& toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls)
546  {
547  if (stabilizer) {
548  QInterface::CINC(toAdd, inOutStart, length, controls);
549  return;
550  }
551 
552  engine->CINC(toAdd, inOutStart, length, controls);
553  }
554  void INCS(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
555  {
556  if (stabilizer) {
557  QInterface::INCS(toAdd, start, length, overflowIndex);
558  return;
559  }
560 
561  engine->INCS(toAdd, start, length, overflowIndex);
562  }
563  void INCDECC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
564  {
565  if (stabilizer) {
566  QInterface::INCDECC(toAdd, start, length, carryIndex);
567  return;
568  }
569 
570  engine->INCDECC(toAdd, start, length, carryIndex);
571  }
572  void INCDECSC(
573  const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
574  {
575  SwitchToEngine();
576  QINTERFACE_TO_QALU(engine)->INCDECSC(toAdd, start, length, overflowIndex, carryIndex);
577  }
578  void INCDECSC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
579  {
580  SwitchToEngine();
581  QINTERFACE_TO_QALU(engine)->INCDECSC(toAdd, start, length, carryIndex);
582  }
583 #if ENABLE_BCD
584  void INCBCD(const bitCapInt& toAdd, bitLenInt start, bitLenInt length)
585  {
586  SwitchToEngine();
587  QINTERFACE_TO_QALU(engine)->INCBCD(toAdd, start, length);
588  }
589  void INCDECBCDC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
590  {
591  SwitchToEngine();
592  QINTERFACE_TO_QALU(engine)->INCDECBCDC(toAdd, start, length, carryIndex);
593  }
594 #endif
595  void MUL(const bitCapInt& toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
596  {
597  SwitchToEngine();
598  QINTERFACE_TO_QALU(engine)->MUL(toMul, inOutStart, carryStart, length);
599  }
600  void DIV(const bitCapInt& toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
601  {
602  SwitchToEngine();
603  QINTERFACE_TO_QALU(engine)->DIV(toDiv, inOutStart, carryStart, length);
604  }
606  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
607  {
608  SwitchToEngine();
609  QINTERFACE_TO_QALU(engine)->MULModNOut(toMul, modN, inStart, outStart, length);
610  }
612  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
613  {
614  SwitchToEngine();
615  QINTERFACE_TO_QALU(engine)->IMULModNOut(toMul, modN, inStart, outStart, length);
616  }
618  const bitCapInt& base, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
619  {
620  SwitchToEngine();
621  QINTERFACE_TO_QALU(engine)->POWModNOut(base, modN, inStart, outStart, length);
622  }
623  void CMUL(const bitCapInt& toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length,
624  const std::vector<bitLenInt>& controls)
625  {
626  SwitchToEngine();
627  QINTERFACE_TO_QALU(engine)->CMUL(toMul, inOutStart, carryStart, length, controls);
628  }
629  void CDIV(const bitCapInt& toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length,
630  const std::vector<bitLenInt>& controls)
631  {
632  SwitchToEngine();
633  QINTERFACE_TO_QALU(engine)->CDIV(toDiv, inOutStart, carryStart, length, controls);
634  }
635  void CMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
636  bitLenInt length, const std::vector<bitLenInt>& controls)
637  {
638  SwitchToEngine();
639  QINTERFACE_TO_QALU(engine)->CMULModNOut(toMul, modN, inStart, outStart, length, controls);
640  }
641  void CIMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
642  bitLenInt length, const std::vector<bitLenInt>& controls)
643  {
644  SwitchToEngine();
645  QINTERFACE_TO_QALU(engine)->CIMULModNOut(toMul, modN, inStart, outStart, length, controls);
646  }
647  void CPOWModNOut(const bitCapInt& base, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
648  bitLenInt length, const std::vector<bitLenInt>& controls)
649  {
650  SwitchToEngine();
651  QINTERFACE_TO_QALU(engine)->CPOWModNOut(base, modN, inStart, outStart, length, controls);
652  }
653 
654  bitCapInt IndexedLDA(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength,
655  const unsigned char* values, bool resetValue = true)
656  {
657  SwitchToEngine();
658  return QINTERFACE_TO_QALU(engine)->IndexedLDA(
659  indexStart, indexLength, valueStart, valueLength, values, resetValue);
660  }
661  bitCapInt IndexedADC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength,
662  bitLenInt carryIndex, const unsigned char* values)
663  {
664  SwitchToEngine();
665  return QINTERFACE_TO_QALU(engine)->IndexedADC(
666  indexStart, indexLength, valueStart, valueLength, carryIndex, values);
667  }
668  bitCapInt IndexedSBC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength,
669  bitLenInt carryIndex, const unsigned char* values)
670  {
671  SwitchToEngine();
672  return QINTERFACE_TO_QALU(engine)->IndexedSBC(
673  indexStart, indexLength, valueStart, valueLength, carryIndex, values);
674  }
675  void Hash(bitLenInt start, bitLenInt length, const unsigned char* values)
676  {
677  SwitchToEngine();
678  QINTERFACE_TO_QALU(engine)->Hash(start, length, values);
679  }
680 #endif
681 
682  void PhaseFlip()
683  {
684  if (stabilizer) {
685  stabilizer->PhaseFlip();
686  } else {
687  engine->PhaseFlip();
688  }
689  }
690  void ZeroPhaseFlip(bitLenInt start, bitLenInt length)
691  {
692  SwitchToEngine();
693  engine->ZeroPhaseFlip(start, length);
694  }
695 
696  void SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
697  {
698  if (stabilizer) {
699  QInterface::SqrtSwap(qubitIndex1, qubitIndex2);
700  return;
701  }
702 
703  SwitchToEngine();
704  engine->SqrtSwap(qubitIndex1, qubitIndex2);
705  }
706  void ISqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
707  {
708  if (stabilizer) {
709  QInterface::ISqrtSwap(qubitIndex1, qubitIndex2);
710  return;
711  }
712 
713  SwitchToEngine();
714  engine->ISqrtSwap(qubitIndex1, qubitIndex2);
715  }
716  void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)
717  {
718  const std::vector<bitLenInt> controls{ qubit1 };
719  const real1 sinTheta = (real1)sin(theta);
720 
721  if ((sinTheta * sinTheta) <= FP_NORM_EPSILON) {
722  MCPhase(controls, ONE_CMPLX, exp(complex(ZERO_R1, (real1)phi)), qubit2);
723  return;
724  }
725 
726  const real1 sinThetaDiffNeg = ONE_R1 + sinTheta;
727  if ((sinThetaDiffNeg * sinThetaDiffNeg) <= FP_NORM_EPSILON) {
728  ISwap(qubit1, qubit2);
729  MCPhase(controls, ONE_CMPLX, exp(complex(ZERO_R1, (real1)phi)), qubit2);
730  return;
731  }
732 
733  const real1 sinThetaDiffPos = ONE_R1 - sinTheta;
734  if ((sinThetaDiffPos * sinThetaDiffPos) <= FP_NORM_EPSILON) {
735  IISwap(qubit1, qubit2);
736  MCPhase(controls, ONE_CMPLX, exp(complex(ZERO_R1, (real1)phi)), qubit2);
737  return;
738  }
739 
740  SwitchToEngine();
741  engine->FSim(theta, phi, qubit1, qubit2);
742  }
743 
744  real1_f ProbMask(const bitCapInt& mask, const bitCapInt& permutation)
745  {
746  SwitchToEngine();
747  return engine->ProbMask(mask, permutation);
748  }
749 
751  {
752  return ApproxCompareHelper(std::dynamic_pointer_cast<QStabilizerHybrid>(toCompare), false);
753  }
755  {
756  return error_tol >=
757  ApproxCompareHelper(std::dynamic_pointer_cast<QStabilizerHybrid>(toCompare), true, error_tol);
758  }
759 
761  {
762  if (engine) {
763  engine->UpdateRunningNorm(norm_thresh);
764  }
765  }
766 
767  void NormalizeState(
768  real1_f nrm = REAL1_DEFAULT_ARG, real1_f norm_thresh = REAL1_DEFAULT_ARG, real1_f phaseArg = ZERO_R1_F);
769 
770  real1_f ProbAllRdm(bool roundRz, const bitCapInt& fullRegister);
771  real1_f ProbMaskRdm(bool roundRz, const bitCapInt& mask, const bitCapInt& permutation);
772  real1_f ExpectationBitsAll(const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
773  {
774  if (stabilizer) {
775  return QInterface::ExpectationBitsAll(bits, offset);
776  }
777 
778  return engine->ExpectationBitsAll(bits, offset);
779  }
780  real1_f ExpectationBitsAllRdm(bool roundRz, const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
781  {
782  if (engine) {
783  return engine->ExpectationBitsAllRdm(roundRz, bits, offset);
784  }
785 
786  if (!roundRz) {
787  return stabilizer->ExpectationBitsAll(bits, offset);
788  }
789 
790  return RdmCloneHelper()->stabilizer->ExpectationBitsAll(bits, offset);
791  }
793  const std::vector<bitLenInt>& bits, const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI)
794  {
795  if (stabilizer) {
796  return QInterface::ExpectationBitsFactorized(bits, perms, offset);
797  }
798 
799  return engine->ExpectationBitsFactorized(bits, perms, offset);
800  }
801  real1_f ExpectationBitsFactorizedRdm(bool roundRz, const std::vector<bitLenInt>& bits,
802  const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI)
803  {
804  return ExpVarFactorized(true, false, bits, perms, std::vector<real1_f>(), offset, roundRz);
805  }
806  real1_f ExpectationFloatsFactorized(const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights)
807  {
808  if (stabilizer) {
809  return QInterface::ExpectationFloatsFactorized(bits, weights);
810  }
811 
812  return engine->ExpectationFloatsFactorized(bits, weights);
813  }
815  bool roundRz, const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights)
816  {
817  return ExpVarFactorized(true, true, bits, std::vector<bitCapInt>(), weights, ZERO_BCI, roundRz);
818  }
819  real1_f VarianceBitsAll(const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
820  {
821  if (stabilizer) {
822  return QInterface::VarianceBitsAll(bits, offset);
823  }
824 
825  return engine->VarianceBitsAll(bits, offset);
826  }
827  real1_f VarianceBitsAllRdm(bool roundRz, const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
828  {
829  if (engine) {
830  return engine->VarianceBitsAllRdm(roundRz, bits, offset);
831  }
832 
833  if (!roundRz) {
834  return stabilizer->VarianceBitsAll(bits, offset);
835  }
836 
837  return RdmCloneHelper()->stabilizer->VarianceBitsAll(bits, offset);
838  }
840  const std::vector<bitLenInt>& bits, const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI)
841  {
842  if (stabilizer) {
843  return QInterface::VarianceBitsFactorized(bits, perms, offset);
844  }
845 
846  return engine->VarianceBitsFactorized(bits, perms, offset);
847  }
848  real1_f VarianceBitsFactorizedRdm(bool roundRz, const std::vector<bitLenInt>& bits,
849  const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI)
850  {
851  return ExpVarFactorized(true, false, bits, perms, std::vector<real1_f>(), offset, roundRz);
852  }
853  real1_f VarianceFloatsFactorized(const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights)
854  {
855  if (stabilizer) {
856  return QInterface::VarianceFloatsFactorized(bits, weights);
857  }
858 
859  return engine->VarianceFloatsFactorized(bits, weights);
860  }
862  bool roundRz, const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights)
863  {
864  return ExpVarFactorized(true, true, bits, std::vector<bitCapInt>(), weights, ZERO_BCI, roundRz);
865  }
866 
867  bool TrySeparate(bitLenInt qubit);
868  bool TrySeparate(bitLenInt qubit1, bitLenInt qubit2);
869  bool TrySeparate(const std::vector<bitLenInt>& qubits, real1_f error_tol);
870 
872 
873  void SetDevice(int64_t dID)
874  {
875  devID = dID;
876  if (engine) {
877  engine->SetDevice(dID);
878  }
879  }
880 
881  int64_t GetDeviceID() { return devID; }
882 
884  {
885  if (stabilizer) {
886  return QInterface::GetMaxSize();
887  }
888 
889  return engine->GetMaxSize();
890  }
891 
892  friend std::ostream& operator<<(std::ostream& os, const QStabilizerHybridPtr s);
893  friend std::istream& operator>>(std::istream& is, const QStabilizerHybridPtr s);
894 };
895 } // namespace Qrack
void bi_or_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:429
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:134
unsigned GetConcurrencyLevel()
Definition: parallel_for.hpp:41
Definition: qalu.hpp:22
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:138
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:257
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:452
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:346
bitLenInt qubitCount
Definition: qinterface.hpp:143
real1_f Rand()
Generate a random real number between 0 and 1.
Definition: qinterface.hpp:268
Definition: qparity.hpp:22
A "Qrack::QStabilizerHybrid" internally switched between Qrack::QStabilizer and Qrack::QEngine to max...
Definition: qstabilizerhybrid.hpp:43
real1_f VarianceBitsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get (reduced density matrix) expectation value of bits, given an array of qubit weights.
Definition: qstabilizerhybrid.hpp:848
bool TrimControls(const std::vector< bitLenInt > &lControls, std::vector< bitLenInt > &output, bool anti=false)
Definition: qstabilizerhybrid.cpp:285
real1_f ExpectationBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Get permutation expectation value of bits.
Definition: qstabilizerhybrid.hpp:772
void CPhaseFlipIfLess(const 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: qstabilizerhybrid.hpp:507
void CMUL(const bitCapInt &toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication by integer.
Definition: qstabilizerhybrid.hpp:623
void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: qstabilizerhybrid.cpp:1069
void SetPermutation(const bitCapInt &perm, const complex &phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qstabilizerhybrid.cpp:927
real1_f ProbAll(const bitCapInt &perm)
Direct measure of full permutation probability.
Definition: qstabilizerhybrid.hpp:447
bitLenInt ComposeNoClone(QInterfacePtr toCopy)
This is a variant of Compose() for a toCopy argument that will definitely not be reused once "Compose...
Definition: qstabilizerhybrid.hpp:428
bitLenInt maxEngineQubitCount
Definition: qstabilizerhybrid.hpp:56
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: qstabilizerhybrid.cpp:1288
void CISqrtSwap(const std::vector< bitLenInt > &lControls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary control bits.
Definition: qstabilizerhybrid.cpp:1006
bitLenInt ComposeEither(QStabilizerHybridPtr toCopy, bool willDestroy)
Definition: qstabilizerhybrid.cpp:498
void IISwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse ISwap - Swap values of two bits in register, and apply phase factor of -i if bits are differe...
Definition: qstabilizerhybrid.hpp:458
void SetTInjection(bool useGadget)
Set the option to use T-injection gadgets (off by default)
Definition: qstabilizerhybrid.hpp:341
real1_f FractionalRzAngleWithFlush(bitLenInt i, real1_f angle, bool isGateSuppressed=false)
Definition: qstabilizerhybrid.hpp:192
int64_t devID
Definition: qstabilizerhybrid.hpp:61
void MACInvert(const std::vector< bitLenInt > &controls, const complex &topRight, const complex &bottomLeft, bitLenInt target)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qstabilizerhybrid.cpp:1363
bitLenInt maxStateMapCacheQubitCount
Definition: qstabilizerhybrid.hpp:58
bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qstabilizerhybrid.hpp:355
QStabilizerHybridPtr RdmCloneHelper()
Definition: qstabilizerhybrid.hpp:264
void FlushBuffers()
Definition: qstabilizerhybrid.cpp:266
real1_f VarianceBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Direct measure of variance of listed permutation probability.
Definition: qstabilizerhybrid.hpp:819
std::vector< int64_t > deviceIDs
Definition: qstabilizerhybrid.hpp:66
bool doNormalize
Definition: qstabilizerhybrid.hpp:49
friend std::ostream & operator<<(std::ostream &os, const QStabilizerHybridPtr s)
Definition: qstabilizerhybrid.cpp:2132
void SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Square root of Swap gate.
Definition: qstabilizerhybrid.hpp:696
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:452
void AntiCSqrtSwap(const std::vector< bitLenInt > &lControls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary (anti) control bits.
Definition: qstabilizerhybrid.cpp:990
real1_f ProbRdm(bitLenInt qubit)
Direct measure of bit probability to be in |1> state, treating all ancillary qubits as post-selected ...
Definition: qstabilizerhybrid.hpp:374
void SetNcrp(real1_f ncrp)
Set the "Near-clifford rounding parameter" value, (between 0 and 1)
Definition: qstabilizerhybrid.hpp:340
void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: qstabilizerhybrid.cpp:944
void INCDECBCDC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (without overflow flag)
Definition: qstabilizerhybrid.hpp:589
void GetProbs(real1 *outputProbs)
Get the pure quantum state representation.
Definition: qstabilizerhybrid.cpp:685
void INCBCD(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add classical BCD integer (without sign)
Definition: qstabilizerhybrid.hpp:584
void RdmCloneFlush(real1_f threshold=FP_NORM_EPSILON)
Flush non-Clifford phase gate gadgets with angle below a threshold.
Definition: qstabilizerhybrid.cpp:1883
void CSqrtSwap(const std::vector< bitLenInt > &lControls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary control bits.
Definition: qstabilizerhybrid.cpp:974
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:609
void PhaseFlip()
Phase flip always - equivalent to Z X Z X on any bit in the QInterface.
Definition: qstabilizerhybrid.hpp:682
void FlushIfBlocked(bitLenInt control, bitLenInt target, bool isPhase=false)
Definition: qstabilizerhybrid.cpp:156
bitCapInt MAll()
Measure permutation state of all coherent bits.
Definition: qstabilizerhybrid.cpp:1577
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:346
void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qstabilizerhybrid.hpp:554
bool isClifford()
Returns "true" if current state is identifiably within the Clifford set, or "false" if it is not or c...
Definition: qstabilizerhybrid.hpp:413
double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qstabilizerhybrid.hpp:343
void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qstabilizerhybrid.hpp:527
void FlushCliffordFromBuffers()
Definition: qstabilizerhybrid.hpp:232
void ClearAncilla(bitLenInt i)
Definition: qstabilizerhybrid.hpp:297
bool useTGadget
Definition: qstabilizerhybrid.hpp:51
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: qstabilizerhybrid.hpp:661
real1_f ProbMask(const bitCapInt &mask, const bitCapInt &permutation)
Direct measure of masked permutation probability.
Definition: qstabilizerhybrid.hpp:744
real1_f ExpectationFloatsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Get (reduced density matrix) expectation value of bits, given a (floating-point) array of qubit weigh...
Definition: qstabilizerhybrid.hpp:814
real1_f VarianceFloatsFactorized(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Direct measure of variance of listed bit string probability.
Definition: qstabilizerhybrid.hpp:853
QStabilizerHybrid(std::vector< QInterfaceEngine > eng, 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: qstabilizerhybrid.cpp:43
complex GetAmplitude(const bitCapInt &perm)
Get the representational amplitude of a full permutation.
Definition: qstabilizerhybrid.hpp:446
void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qstabilizerhybrid.hpp:545
void INCDECSC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (without overflow flag)
Definition: qstabilizerhybrid.hpp:578
void CacheEigenstate(bitLenInt target)
Definition: qstabilizerhybrid.cpp:325
void InvertBuffer(bitLenInt qubit)
Definition: qstabilizerhybrid.cpp:138
void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC (without sign, with carry)
Definition: qstabilizerhybrid.hpp:563
bitLenInt ancillaCount
Definition: qstabilizerhybrid.hpp:54
void DumpBuffers()
Definition: qstabilizerhybrid.hpp:83
real1_f SumSqrDiff(QInterfacePtr toCompare)
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
Definition: qstabilizerhybrid.hpp:750
std::vector< MpsShardPtr > shards
Definition: qstabilizerhybrid.hpp:69
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: qstabilizerhybrid.hpp:668
void YMask(const bitCapInt &mask)
Masked Y gate.
Definition: qstabilizerhybrid.cpp:1054
real1_f ACProbRdm(bitLenInt control, bitLenInt target)
Definition: qstabilizerhybrid.hpp:397
bool IsBuffered()
Definition: qstabilizerhybrid.hpp:101
void CMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled multiplication modulo N by integer, (out of place)
Definition: qstabilizerhybrid.hpp:635
complex phaseFactor
Definition: qstabilizerhybrid.hpp:62
void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
Definition: qstabilizerhybrid.cpp:1161
void INCDECSC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
Common driver method behind INCSC and DECSC (with overflow flag)
Definition: qstabilizerhybrid.hpp:572
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: qstabilizerhybrid.hpp:760
bitLenInt maxAncillaCount
Definition: qstabilizerhybrid.hpp:57
void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qstabilizerhybrid.hpp:536
bool isSparse
Definition: qstabilizerhybrid.hpp:50
bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Compose() a QInterface peer, inserting its qubit into index order at start index.
Definition: qstabilizerhybrid.hpp:423
real1_f roundingThreshold
Definition: qstabilizerhybrid.hpp:60
bitLenInt ComposeNoClone(QStabilizerHybridPtr toCopy)
Definition: qstabilizerhybrid.hpp:427
void PhaseFlipIfLess(const bitCapInt &greaterPerm, bitLenInt start, bitLenInt length)
This is an expedient for an adaptive Grover's search for a function's global minimum.
Definition: qstabilizerhybrid.hpp:512
bool TrySeparate(bitLenInt qubit)
Single-qubit TrySeparate()
Definition: qstabilizerhybrid.cpp:2091
QInterfacePtr engine
Definition: qstabilizerhybrid.hpp:64
real1_f VarianceBitsAllRdm(bool roundRz, const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Direct measure of (reduced density matrix) variance of listed permutation probability.
Definition: qstabilizerhybrid.hpp:827
double logFidelity
Definition: qstabilizerhybrid.hpp:63
void ISwap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register, and apply phase factor of i if bits are different.
Definition: qstabilizerhybrid.hpp:457
real1_f ProbMaskRdm(bool roundRz, const bitCapInt &mask, const bitCapInt &permutation)
Direct measure of masked permutation probability, treating all ancillary qubits as post-selected T ga...
Definition: qstabilizerhybrid.cpp:406
void X(bitLenInt q)
Definition: qstabilizerhybrid.hpp:506
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: qstabilizerhybrid.hpp:654
std::vector< QInterfaceEngine > cloneEngineTypes
Definition: qstabilizerhybrid.hpp:68
void ISwapHelper(bitLenInt qubit1, bitLenInt qubit2, bool inverse)
Definition: qstabilizerhybrid.cpp:2035
std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qstabilizerhybrid.cpp:1684
void CUniformParityRZ(const std::vector< bitLenInt > &controls, const 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: qstabilizerhybrid.hpp:496
bitLenInt Compose(QStabilizerHybridPtr toCopy)
Definition: qstabilizerhybrid.hpp:420
real1_f ExpectationBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qstabilizerhybrid.hpp:792
void Mtrx(const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation.
Definition: qstabilizerhybrid.cpp:1085
real1_f VarianceBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qstabilizerhybrid.hpp:839
bool EitherIsBuffered(bool logical)
Definition: qstabilizerhybrid.hpp:89
real1_f ExpectationFloatsFactorized(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Get expectation value of bits, given a (floating-point) array of qubit weights.
Definition: qstabilizerhybrid.hpp:806
bool M(bitLenInt q)
Definition: qstabilizerhybrid.hpp:504
void IMULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Inverse of multiplication modulo N by integer, (out of place)
Definition: qstabilizerhybrid.hpp:611
bitCapIntOcl GetMaxSize()
Definition: qstabilizerhybrid.hpp:883
bool useHostRam
Definition: qstabilizerhybrid.hpp:48
void MULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: qstabilizerhybrid.hpp:605
bool GetTInjection()
Get the option to use T-injection gadgets.
Definition: qstabilizerhybrid.hpp:342
void AntiCISqrtSwap(const std::vector< bitLenInt > &lControls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary (anti) control bits.
Definition: qstabilizerhybrid.cpp:1022
real1_f ProbAllRdm(bool roundRz, const bitCapInt &fullRegister)
Direct measure of full permutation probability, treating all ancillary qubits as post-selected T gate...
Definition: qstabilizerhybrid.cpp:393
void ZeroPhaseFlip(bitLenInt start, bitLenInt length)
Reverse the phase of the state where the register equals zero.
Definition: qstabilizerhybrid.hpp:690
QInterfacePtr Clone()
Clone this QInterface.
Definition: qstabilizerhybrid.cpp:365
bool IsLogicalBuffered()
Definition: qstabilizerhybrid.hpp:102
real1_f ExpectationBitsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get (reduced density matrix) expectation value of bits, given an array of qubit weights.
Definition: qstabilizerhybrid.hpp:801
void CSwap(const std::vector< bitLenInt > &lControls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qstabilizerhybrid.cpp:958
void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qstabilizerhybrid.hpp:873
void MCPhase(const std::vector< bitLenInt > &controls, const complex &topLeft, const complex &bottomRight, bitLenInt target)
Apply a single bit transformation that only effects phase, with arbitrary control bits.
Definition: qstabilizerhybrid.cpp:1187
real1_f ApproxCompareHelper(QStabilizerHybridPtr toCompare, bool isDiscreteBool, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Definition: qstabilizerhybrid.cpp:1952
void ISqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)
Inverse square root of Swap gate.
Definition: qstabilizerhybrid.hpp:706
bool isBinaryDecisionTree()
Returns "true" if current state representation is definitely a binary decision tree,...
Definition: qstabilizerhybrid.hpp:417
bool EitherIsProbBuffered(bool logical)
Definition: qstabilizerhybrid.hpp:103
void SetAmplitude(const bitCapInt &perm, const complex &amp)
Sets the representational amplitude of a full permutation.
Definition: qstabilizerhybrid.hpp:449
void Dispose(bitLenInt start, bitLenInt length)
Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separa...
Definition: qstabilizerhybrid.cpp:628
bool isRoundingFlushed
Definition: qstabilizerhybrid.hpp:52
real1_f separabilityThreshold
Definition: qstabilizerhybrid.hpp:59
complex GetAmplitudeOrProb(const bitCapInt &perm, bool isProb=false)
Definition: qstabilizerhybrid.cpp:702
QStabilizerHybrid(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: qstabilizerhybrid.hpp:329
void Decompose(bitLenInt start, QInterfacePtr dest)
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
Definition: qstabilizerhybrid.hpp:433
QUnitCliffordPtr stabilizer
Definition: qstabilizerhybrid.hpp:65
void SetQuantumState(const complex *inputState)
Set an arbitrary pure quantum state representation.
Definition: qstabilizerhybrid.cpp:888
bitLenInt deadAncillaCount
Definition: qstabilizerhybrid.hpp:55
void CIMULModNOut(const bitCapInt &toMul, const 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: qstabilizerhybrid.hpp:641
void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qstabilizerhybrid.hpp:518
bitLenInt thresholdQubits
Definition: qstabilizerhybrid.hpp:53
real1_f ExpectationBitsAllRdm(bool roundRz, const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Get permutation expectation value of bits, treating all ancillary qubits as post-selected T gate gadg...
Definition: qstabilizerhybrid.hpp:780
void SwitchToEngine()
Switches between CPU and GPU used modes.
Definition: qstabilizerhybrid.cpp:423
void DIV(const bitCapInt &toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Divide by integer.
Definition: qstabilizerhybrid.hpp:600
std::vector< QInterfaceEngine > engineTypes
Definition: qstabilizerhybrid.hpp:67
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: qstabilizerhybrid.cpp:2078
bool isClifford(bitLenInt qubit)
Returns "true" if current qubit state is identifiably within the Clifford set, or "false" if it is no...
Definition: qstabilizerhybrid.hpp:415
void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qstabilizerhybrid.hpp:346
bool CollapseSeparableShard(bitLenInt qubit)
Definition: qstabilizerhybrid.cpp:242
bool IsLogicalProbBuffered()
Definition: qstabilizerhybrid.hpp:126
bool ForceMParity(const 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: qstabilizerhybrid.cpp:1866
friend std::istream & operator>>(std::istream &is, const QStabilizerHybridPtr s)
Definition: qstabilizerhybrid.cpp:2160
void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qstabilizerhybrid.hpp:344
void MACPhase(const std::vector< bitLenInt > &controls, const complex &topLeft, const complex &bottomRight, bitLenInt target)
Apply a single bit transformation that only effects phase, with arbitrary (anti-)control bits.
Definition: qstabilizerhybrid.cpp:1314
void CheckShots(unsigned shots, const bitCapInt &m, real1_f partProb, const std::vector< bitCapInt > &qPowers, std::vector< real1_f > &rng, F fn)
Definition: qstabilizerhybrid.hpp:156
real1_f Prob(bitLenInt qubit)
Direct measure of bit probability to be in |1> state.
Definition: qstabilizerhybrid.cpp:1411
std::unique_ptr< complex[]> GetQubitReducedDensityMatrix(bitLenInt qubit)
Definition: qstabilizerhybrid.hpp:128
void CPOWModNOut(const bitCapInt &base, const 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: qstabilizerhybrid.hpp:647
void CDIV(const bitCapInt &toDiv, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Controlled division by power of integer.
Definition: qstabilizerhybrid.hpp:629
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: qstabilizerhybrid.cpp:1496
real1_f ProbParity(const bitCapInt &mask)
Overall probability of any odd permutation of the masked set of bits.
Definition: qstabilizerhybrid.cpp:1853
void GetQuantumState(complex *outputState)
Get the pure quantum state representation.
Definition: qstabilizerhybrid.cpp:668
QInterfacePtr MakeEngine(const bitCapInt &perm=ZERO_BCI)
Definition: qstabilizerhybrid.cpp:121
void XMask(const bitCapInt &mask)
Masked X gate.
Definition: qstabilizerhybrid.cpp:1039
void MUL(const bitCapInt &toMul, bitLenInt inOutStart, bitLenInt carryStart, bitLenInt length)
Multiply by integer.
Definition: qstabilizerhybrid.hpp:595
void Hash(bitLenInt start, bitLenInt length, const unsigned char *values)
Transform a length of qubit register via lookup through a hash table.
Definition: qstabilizerhybrid.hpp:675
void FlushH(bitLenInt qubit)
Definition: qstabilizerhybrid.cpp:147
bool ApproxCompare(QInterfacePtr toCompare, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Compare state vectors approximately, to determine whether this state vector is the same as the target...
Definition: qstabilizerhybrid.hpp:754
void POWModNOut(const bitCapInt &base, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Raise a classical base to a quantum power, modulo N, (out of place)
Definition: qstabilizerhybrid.hpp:617
QUnitStateVectorPtr stateMapCache
Definition: qstabilizerhybrid.hpp:70
void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
Definition: qstabilizerhybrid.hpp:716
void SetConcurrency(uint32_t threadCount)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qstabilizerhybrid.hpp:366
real1_f VarianceFloatsFactorizedRdm(bool roundRz, const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Direct measure of (reduced density matrix) variance of bits, given an array of qubit weights.
Definition: qstabilizerhybrid.hpp:861
QUnitCliffordPtr MakeStabilizer(const bitCapInt &perm=ZERO_BCI)
Definition: qstabilizerhybrid.cpp:116
real1_f ExpVarFactorized(bool isExp, bool isFloat, const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const std::vector< real1_f > &weights, const bitCapInt &offset, bool roundRz)
Definition: qstabilizerhybrid.hpp:273
bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qstabilizerhybrid.hpp:421
real1_f CProbRdm(bitLenInt control, bitLenInt target)
Definition: qstabilizerhybrid.hpp:388
std::vector< real1_f > GenerateShotProbs(unsigned shots)
Definition: qstabilizerhybrid.hpp:179
void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qstabilizerhybrid.hpp:357
int64_t GetDeviceID()
Definition: qstabilizerhybrid.hpp:881
void MCInvert(const std::vector< bitLenInt > &controls, const complex &topRight, const complex &bottomLeft, bitLenInt target)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qstabilizerhybrid.cpp:1240
bool IsProbBuffered()
Definition: qstabilizerhybrid.hpp:125
Half-precision floating-point type.
Definition: half.hpp:2222
virtual void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Subtract a classical integer from the register, with sign and without carry.
Definition: qinterface.hpp:2175
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC.
Definition: arithmetic.cpp:52
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: arithmetic.cpp:78
virtual void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qinterface.hpp:2164
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2116
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: arithmetic.cpp:20
virtual void CNOT(bitLenInt control, bitLenInt target)
Controlled NOT gate.
Definition: qinterface.hpp:691
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:609
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1066
virtual void AntiCNOT(bitLenInt control, bitLenInt target)
Anti controlled NOT gate.
Definition: qinterface.hpp:702
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual bool M(bitLenInt qubit)
Measurement gate.
Definition: qinterface.hpp:995
virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse square root of Swap gate.
Definition: gates.cpp:225
virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Square root of Swap gate.
Definition: gates.cpp:202
virtual real1_f VarianceBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qinterface.cpp:573
virtual real1_f VarianceFloatsFactorized(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Direct measure of variance of listed bit string probability.
Definition: qinterface.cpp:613
virtual real1_f ExpectationBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Get permutation expectation value of bits.
Definition: qinterface.hpp:2589
bitCapIntOcl GetMaxSize()
Get maximum number of amplitudes that can be allocated on current device.
Definition: qinterface.hpp:2957
virtual real1_f VarianceBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Direct measure of variance of listed permutation probability.
Definition: qinterface.hpp:2473
virtual real1_f ExpectationBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qinterface.cpp:536
virtual real1_f ExpectationFloatsFactorized(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Get expectation value of bits, given a (floating-point) array of qubit weights.
Definition: qinterface.cpp:763
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
@ QINTERFACE_OPTIMAL_BASE
Definition: qinterface.hpp:121
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:213
QRACK_CONST real1_f TRYDECOMPOSE_EPSILON
Definition: qrack_types.hpp:245
std::shared_ptr< QStabilizerHybrid > QStabilizerHybridPtr
Definition: qstabilizerhybrid.hpp:35
void mul2x2(complex const *left, complex const *right, complex *out)
Definition: functions.cpp:111
half_float::half real1
Definition: qrack_types.hpp:90
std::complex< real1 > complex
Definition: qrack_types.hpp:124
std::shared_ptr< QUnitStateVector > QUnitStateVectorPtr
Definition: qunitstatevector.hpp:17
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:243
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:114
std::shared_ptr< QUnitClifford > QUnitCliffordPtr
Definition: qunitclifford.hpp:20
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:101
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:187
QRACK_CONST complex ONE_CMPLX
Definition: qrack_types.hpp:239
QRACK_CONST real1 ONE_R1
Definition: qrack_types.hpp:176
QRACK_CONST real1 ZERO_R1
Definition: qrack_types.hpp:175
float real1_f
Definition: qrack_types.hpp:91
float real1_s
Definition: qrack_types.hpp:92
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:242
std::shared_ptr< MpsShard > MpsShardPtr
Definition: mpsshard.hpp:18
QRACK_CONST complex I_CMPLX
Definition: qrack_types.hpp:241
QRACK_CONST complex ZERO_CMPLX
Definition: qrack_types.hpp:240
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:170
void reverse(BidirectionalIterator first, BidirectionalIterator last, const bitCapInt &stride)
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:126
HALF_CONSTEXPR half abs(half arg)
Absolute value.
Definition: half.hpp:2975
half sin(half arg)
Sine function.
Definition: half.hpp:3885
half cos(half arg)
Cosine function.
Definition: half.hpp:3922
long lround(half arg)
Nearest integer.
Definition: half.hpp:4505
half exp(half arg)
Exponential function.
Definition: half.hpp:3201
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:169
#define QRACK_CONST
Definition: qrack_types.hpp:166
#define bitLenInt
Definition: qrack_types.hpp:38
#define ZERO_R1_F
Definition: qrack_types.hpp:156
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:152
#define bitCapInt
Definition: qrack_types.hpp:62
#define bitCapIntOcl
Definition: qrack_types.hpp:50
#define ONE_R1_F
Definition: qrack_types.hpp:157
#define QINTERFACE_TO_QALU(qReg)
Definition: qstabilizerhybrid.hpp:18
#define QINTERFACE_TO_QPARITY(qReg)
Definition: qstabilizerhybrid.hpp:19
Definition: qstabilizerhybrid.hpp:23
QUnitCliffordAmp(const complex &a, QUnitCliffordPtr s)
Definition: qstabilizerhybrid.hpp:27
QUnitCliffordPtr stabilizer
Definition: qstabilizerhybrid.hpp:25
complex amp
Definition: qstabilizerhybrid.hpp:24