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