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