Qrack  9.9
General classical-emulating-quantum development framework
qinterface.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 
13 #pragma once
14 
15 #include "common/parallel_for.hpp"
16 #include "common/pauli.hpp"
17 #include "common/rdrandwrapper.hpp"
18 #include "hamiltonian.hpp"
19 
20 #include <map>
21 #include <random>
22 
23 #if ENABLE_UINT128
24 #include <ostream>
25 #endif
26 
27 namespace Qrack {
28 
29 class QInterface;
30 typedef std::shared_ptr<QInterface> QInterfacePtr;
31 
38 
43 
48 
53 
58 
63 
68 
73 
78 
83 
92 
98 
103 
108 
113 
114 #if ENABLE_OPENCL || ENABLE_CUDA
116 
118 #else
120 
122 #endif
123 
125 
127 
129 };
130 
138 class QInterface : public ParallelFor {
139 protected:
142  bool useRDRAND;
144  uint32_t randomSeed;
148  std::uniform_real_distribution<real1_s> rand_distribution;
149  std::shared_ptr<RdRandom> hardware_rand_generator;
150 
151  // Compilers have difficulty figuring out types and overloading if the "norm" handle is passed to std::transform. If
152  // you need a safe pointer to norm(), try this:
153  static inline real1_f normHelper(const complex& c) { return (real1_f)norm(c); }
154 
155  static inline real1_f clampProb(real1_f toClamp)
156  {
157  if (toClamp < ZERO_R1_F) {
158  toClamp = ZERO_R1_F;
159  }
160  if (toClamp > ONE_R1_F) {
161  toClamp = ONE_R1_F;
162  }
163  return toClamp;
164  }
165 
167  {
168  if (randGlobalPhase) {
169  real1_f angle = Rand() * 2 * (real1_f)PI_R1;
170  return complex((real1)cos(angle), (real1)sin(angle));
171  } else {
172  return ONE_CMPLX;
173  }
174  }
175 
176  template <typename Fn> void MACWrapper(const std::vector<bitLenInt>& controls, Fn fn)
177  {
178  bitCapInt xMask = ZERO_BCI;
179  for (size_t i = 0U; i < controls.size(); ++i) {
180  bi_or_ip(&xMask, pow2(controls[i]));
181  }
182 
183  XMask(xMask);
184  fn(controls);
185  XMask(xMask);
186  }
187 
188  virtual bitCapInt SampleClone(const std::vector<bitCapInt>& qPowers)
189  {
190  QInterfacePtr clone = Clone();
191 
192  const bitCapInt rawSample = clone->MAll();
193  bitCapInt sample = ZERO_BCI;
194  for (size_t i = 0U; i < qPowers.size(); ++i) {
195  if (bi_compare_0(rawSample & qPowers[i]) != 0) {
196  bi_or_ip(&sample, pow2(i));
197  }
198  }
199 
200  return sample;
201  }
202 
203  virtual real1_f ExpVarUnitaryAll(bool isExp, const std::vector<bitLenInt>& bits,
204  const std::vector<std::shared_ptr<complex>>& basisOps, std::vector<real1_f> eigenVals = {});
205  virtual real1_f ExpVarUnitaryAll(bool isExp, const std::vector<bitLenInt>& bits,
206  const std::vector<real1_f>& basisOps, std::vector<real1_f> eigenVals = {});
207  virtual real1_f ExpVarBitsAll(bool isExp, const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
208  {
209  std::vector<bitCapInt> perms;
210  perms.reserve(bits.size() << 1U);
211  for (size_t i = 0U; i < bits.size(); ++i) {
212  perms.push_back(ZERO_BCI);
213  perms.push_back(pow2(i));
214  }
215 
216  return isExp ? ExpectationBitsFactorized(bits, perms, offset) : VarianceBitsFactorized(bits, perms, offset);
217  }
218 
219 public:
220  QInterface(bitLenInt n, qrack_rand_gen_ptr rgp = nullptr, bool doNorm = false, bool useHardwareRNG = true,
221  bool randomGlobalPhase = true, real1_f norm_thresh = REAL1_EPSILON);
222 
225  : doNormalize(false)
226  , randGlobalPhase(true)
227  , useRDRAND(true)
228  , qubitCount(0U)
229  , randomSeed(0)
231  , maxQPower(ONE_BCI)
232  , rand_distribution(0.0, 1.0)
234  {
235  // Intentionally left blank
236  }
237 
238  virtual ~QInterface()
239  {
240  // Virtual destructor for inheritance
241  }
242 
243  void SetRandomSeed(uint32_t seed)
244  {
245  if (rand_generator != NULL) {
246  rand_generator->seed(seed);
247  }
248  }
249 
250  virtual void SetQubitCount(bitLenInt qb)
251  {
252  qubitCount = qb;
254  }
255 
257  virtual void SetConcurrency(uint32_t threadsPerEngine) { SetConcurrencyLevel(threadsPerEngine); }
258 
260  virtual bitLenInt GetQubitCount() { return qubitCount; }
261 
263  virtual bitCapInt GetMaxQPower() { return maxQPower; }
264 
265  virtual bool GetIsArbitraryGlobalPhase() { return randGlobalPhase; }
266 
269  {
270  if (hardware_rand_generator != NULL) {
271  return hardware_rand_generator->Next();
272  } else {
274  }
275  }
276 
281  virtual void SetQuantumState(const complex* inputState) = 0;
282 
287  virtual void GetQuantumState(complex* outputState) = 0;
288 
293  virtual void GetProbs(real1* outputProbs) = 0;
294 
299  virtual complex GetAmplitude(const bitCapInt& perm) = 0;
300 
305  virtual void SetAmplitude(const bitCapInt& perm, const complex& amp) = 0;
306 
308  virtual void SetPermutation(const bitCapInt& perm, const complex& phaseFac = CMPLX_DEFAULT_ARG);
309 
346  virtual bitLenInt Compose(QInterfacePtr toCopy) { return Compose(toCopy, qubitCount); }
351  virtual bitLenInt ComposeNoClone(QInterfacePtr toCopy) { return Compose(toCopy); }
355  virtual std::map<QInterfacePtr, bitLenInt> Compose(std::vector<QInterfacePtr> toCopy);
359  virtual bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start);
360 
398  virtual void Decompose(bitLenInt start, QInterfacePtr dest) = 0;
399 
403  virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length) = 0;
404 
442  virtual void Dispose(bitLenInt start, bitLenInt length) = 0;
443 
447  virtual void Dispose(bitLenInt start, bitLenInt length, const bitCapInt& disposedPerm) = 0;
448 
452  virtual bitLenInt Allocate(bitLenInt length) { return Allocate(qubitCount, length); }
453 
457  virtual bitLenInt Allocate(bitLenInt start, bitLenInt length) = 0;
458 
467  virtual void Mtrx(const complex* mtrx, bitLenInt qubit) = 0;
468 
472  virtual void MCMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target) = 0;
473 
477  virtual void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
478  {
479  if (IS_NORM_0(mtrx[1U]) && IS_NORM_0(mtrx[2U])) {
480  MACPhase(controls, mtrx[0U], mtrx[3U], target);
481  } else if (IS_NORM_0(mtrx[0U]) && IS_NORM_0(mtrx[3U])) {
482  MACInvert(controls, mtrx[1U], mtrx[2U], target);
483  } else {
484  MACWrapper(controls, [this, mtrx, target](const std::vector<bitLenInt>& lc) { MCMtrx(lc, mtrx, target); });
485  }
486  }
487 
492  virtual void UCMtrx(
493  const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target, const bitCapInt& controlPerm);
494 
498  virtual void Phase(const complex& topLeft, const complex& bottomRight, bitLenInt qubit)
499  {
500  if ((randGlobalPhase || IS_NORM_0(ONE_CMPLX - topLeft)) && IS_NORM_0(topLeft - bottomRight)) {
501  return;
502  }
503 
504  const complex mtrx[4U]{ topLeft, ZERO_CMPLX, ZERO_CMPLX, bottomRight };
505  Mtrx(mtrx, qubit);
506  }
507 
511  virtual void Invert(const complex& topRight, const complex& bottomLeft, bitLenInt qubit)
512  {
513  const complex mtrx[4U]{ ZERO_CMPLX, topRight, bottomLeft, ZERO_CMPLX };
514  Mtrx(mtrx, qubit);
515  }
516 
520  virtual void MCPhase(
521  const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight, bitLenInt target)
522  {
523  if (IS_NORM_0(ONE_CMPLX - topLeft) && IS_NORM_0(ONE_CMPLX - bottomRight)) {
524  return;
525  }
526 
527  const complex mtrx[4U]{ topLeft, ZERO_CMPLX, ZERO_CMPLX, bottomRight };
528  MCMtrx(controls, mtrx, target);
529  }
530 
535  virtual void MCInvert(
536  const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft, bitLenInt target)
537  {
538  const complex mtrx[4U]{ ZERO_CMPLX, topRight, bottomLeft, ZERO_CMPLX };
539  MCMtrx(controls, mtrx, target);
540  }
541 
545  virtual void MACPhase(
546  const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight, bitLenInt target)
547  {
548  if (IS_NORM_0(ONE_CMPLX - topLeft) && IS_NORM_0(ONE_CMPLX - bottomRight)) {
549  return;
550  }
551 
552  MACWrapper(controls, [this, topLeft, bottomRight, target](const std::vector<bitLenInt>& lc) {
553  MCPhase(lc, topLeft, bottomRight, target);
554  });
555  }
556 
561  virtual void MACInvert(
562  const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft, bitLenInt target)
563  {
564  MACWrapper(controls, [this, topRight, bottomLeft, target](const std::vector<bitLenInt>& lc) {
565  MCInvert(lc, topRight, bottomLeft, target);
566  });
567  }
568 
573  virtual void UCPhase(const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight,
574  bitLenInt target, const bitCapInt& perm)
575  {
576  if (IS_NORM_0(ONE_CMPLX - topLeft) && IS_NORM_0(ONE_CMPLX - bottomRight)) {
577  return;
578  }
579 
580  const complex mtrx[4U]{ topLeft, ZERO_CMPLX, ZERO_CMPLX, bottomRight };
581  UCMtrx(controls, mtrx, target, perm);
582  }
583 
588  virtual void UCInvert(const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft,
589  bitLenInt target, const bitCapInt& perm)
590  {
591  const complex mtrx[4U]{ ZERO_CMPLX, topRight, bottomLeft, ZERO_CMPLX };
592  UCMtrx(controls, mtrx, target, perm);
593  }
594 
610  const std::vector<bitLenInt>& controls, bitLenInt qubit, const complex* mtrxs)
611  {
612  UniformlyControlledSingleBit(controls, qubit, mtrxs, std::vector<bitCapInt>(), ZERO_BCI);
613  }
614  virtual void UniformlyControlledSingleBit(const std::vector<bitLenInt>& controls, bitLenInt qubit,
615  const complex* mtrxs, const std::vector<bitCapInt>& mtrxSkipPowers, const bitCapInt& mtrxSkipValueMask);
616 
632  virtual void TimeEvolve(Hamiltonian h, real1_f timeDiff);
633 
637  virtual void CSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
638 
642  virtual void AntiCSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
643 
647  virtual void CSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
648 
652  virtual void AntiCSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
653 
657  virtual void CISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
658 
662  virtual void AntiCISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
663 
669  virtual void CCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target)
670  {
671  const std::vector<bitLenInt> controls{ control1, control2 };
672  MCInvert(controls, ONE_CMPLX, ONE_CMPLX, target);
673  }
674 
680  virtual void AntiCCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target)
681  {
682  const std::vector<bitLenInt> controls{ control1, control2 };
683  MACInvert(controls, ONE_CMPLX, ONE_CMPLX, target);
684  }
685 
691  virtual void CNOT(bitLenInt control, bitLenInt target)
692  {
693  const std::vector<bitLenInt> controls{ control };
694  MCInvert(controls, ONE_CMPLX, ONE_CMPLX, target);
695  }
696 
702  virtual void AntiCNOT(bitLenInt control, bitLenInt target)
703  {
704  const std::vector<bitLenInt> controls{ control };
705  MACInvert(controls, ONE_CMPLX, ONE_CMPLX, target);
706  }
707 
714  virtual void CY(bitLenInt control, bitLenInt target)
715  {
716  const std::vector<bitLenInt> controls{ control };
717  MCInvert(controls, -I_CMPLX, I_CMPLX, target);
718  }
719 
725  virtual void AntiCY(bitLenInt control, bitLenInt target)
726  {
727  const std::vector<bitLenInt> controls{ control };
728  MACInvert(controls, -I_CMPLX, I_CMPLX, target);
729  }
730 
737  virtual void CCY(bitLenInt control1, bitLenInt control2, bitLenInt target)
738  {
739  const std::vector<bitLenInt> controls{ control1, control2 };
740  MCInvert(controls, -I_CMPLX, I_CMPLX, target);
741  }
742 
748  virtual void AntiCCY(bitLenInt control1, bitLenInt control2, bitLenInt target)
749  {
750  const std::vector<bitLenInt> controls{ control1, control2 };
751  MACInvert(controls, -I_CMPLX, I_CMPLX, target);
752  }
753 
760  virtual void CZ(bitLenInt control, bitLenInt target)
761  {
762  const std::vector<bitLenInt> controls{ control };
763  MCPhase(controls, ONE_CMPLX, -ONE_CMPLX, target);
764  }
765 
771  virtual void AntiCZ(bitLenInt control, bitLenInt target)
772  {
773  const std::vector<bitLenInt> controls{ control };
774  MACPhase(controls, ONE_CMPLX, -ONE_CMPLX, target);
775  }
776 
783  virtual void CCZ(bitLenInt control1, bitLenInt control2, bitLenInt target)
784  {
785  const std::vector<bitLenInt> controls{ control1, control2 };
786  MCPhase(controls, ONE_CMPLX, -ONE_CMPLX, target);
787  }
788 
794  virtual void AntiCCZ(bitLenInt control1, bitLenInt control2, bitLenInt target)
795  {
796  const std::vector<bitLenInt> controls{ control1, control2 };
797  MACPhase(controls, ONE_CMPLX, -ONE_CMPLX, target);
798  }
799 
806  virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda);
807 
813  virtual void U2(bitLenInt target, real1_f phi, real1_f lambda) { U(target, (real1_f)(M_PI / 2), phi, lambda); }
814 
820  virtual void IU2(bitLenInt target, real1_f phi, real1_f lambda)
821  {
822  U(target, (real1_f)(M_PI / 2), (real1_f)(-lambda - PI_R1), (real1_f)(-phi + PI_R1));
823  }
824 
830  virtual void AI(bitLenInt target, real1_f azimuth, real1_f inclination);
831 
837  virtual void IAI(bitLenInt target, real1_f azimuth, real1_f inclination);
838 
844  virtual void CAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination);
845 
852  virtual void AntiCAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination);
853 
860  virtual void CIAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination);
861 
868  virtual void AntiCIAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination);
869 
877  virtual void CU(
878  const std::vector<bitLenInt>& controls, bitLenInt target, real1_f theta, real1_f phi, real1_f lambda);
879 
887  virtual void AntiCU(
888  const std::vector<bitLenInt>& controls, bitLenInt target, real1_f theta, real1_f phi, real1_f lambda);
889 
895  virtual void H(bitLenInt qubit)
896  {
900  Mtrx(mtrx, qubit);
901  }
902 
908  virtual void SqrtH(bitLenInt qubit)
909  {
910  QRACK_CONST complex m00 =
911  complex((real1)((ONE_R1 + SQRT2_R1) / (2 * SQRT2_R1)), (real1)((-ONE_R1 + SQRT2_R1) / (2 * SQRT2_R1)));
912  QRACK_CONST complex m01 = complex((real1)(SQRT1_2_R1 / 2), (real1)(-SQRT1_2_R1 / 2));
913  QRACK_CONST complex m10 = m01;
914  QRACK_CONST complex m11 =
915  complex((real1)((-ONE_R1 + SQRT2_R1) / (2 * SQRT2_R1)), (real1)((ONE_R1 + SQRT2_R1) / (2 * SQRT2_R1)));
916  QRACK_CONST complex mtrx[4]{ m00, m01, m10, m11 };
917  Mtrx(mtrx, qubit);
918  }
919 
925  virtual void SH(bitLenInt qubit)
926  {
929  QRACK_CONST complex C_I_SQRT1_2_NEG = complex(ZERO_R1, -SQRT1_2_R1);
930  QRACK_CONST complex mtrx[4]{ C_SQRT1_2, C_SQRT1_2, C_I_SQRT1_2, C_I_SQRT1_2_NEG };
931  Mtrx(mtrx, qubit);
932  }
933 
939  virtual void HIS(bitLenInt qubit)
940  {
943  QRACK_CONST complex C_I_SQRT1_2_NEG = complex(ZERO_R1, -SQRT1_2_R1);
944  QRACK_CONST complex mtrx[4]{ C_SQRT1_2, C_I_SQRT1_2_NEG, C_SQRT1_2, C_I_SQRT1_2 };
945  Mtrx(mtrx, qubit);
946  }
947 
995  virtual bool M(bitLenInt qubit) { return ForceM(qubit, false, false); };
996 
1002  virtual bool ForceM(bitLenInt qubit, bool result, bool doForce = true, bool doApply = true) = 0;
1003 
1009  virtual void S(bitLenInt qubit) { Phase(ONE_CMPLX, I_CMPLX, qubit); }
1010 
1016  virtual void IS(bitLenInt qubit) { Phase(ONE_CMPLX, -I_CMPLX, qubit); }
1017 
1023  virtual void T(bitLenInt qubit) { Phase(ONE_CMPLX, complex(SQRT1_2_R1, SQRT1_2_R1), qubit); }
1024 
1030  virtual void IT(bitLenInt qubit) { Phase(ONE_CMPLX, complex(SQRT1_2_R1, -SQRT1_2_R1), qubit); }
1031 
1037  virtual void PhaseRootN(bitLenInt n, bitLenInt qubit)
1038  {
1039  if (n == 0) {
1040  return;
1041  }
1042 
1043  Phase(ONE_CMPLX, pow(-ONE_CMPLX, (real1)(ONE_R1 / pow2Ocl(n - 1U))), qubit);
1044  }
1045 
1051  virtual void PhaseRootNMask(bitLenInt n, const bitCapInt& mask);
1052 
1058  virtual void PhaseParity(real1_f radians, const bitCapInt& mask);
1059 
1066  virtual void X(bitLenInt qubit) { Invert(ONE_CMPLX, ONE_CMPLX, qubit); }
1067 
1074  virtual void XMask(const bitCapInt& mask);
1075 
1083  virtual void Y(bitLenInt qubit) { Invert(-I_CMPLX, I_CMPLX, qubit); }
1084 
1091  virtual void YMask(const bitCapInt& mask);
1092 
1099  virtual void Z(bitLenInt qubit) { Phase(ONE_CMPLX, -ONE_CMPLX, qubit); }
1100 
1107  virtual void ZMask(const bitCapInt& mask);
1108 
1115  virtual void SqrtX(bitLenInt qubit)
1116  {
1117  QRACK_CONST complex ONE_PLUS_I_DIV_2 = complex((real1)(ONE_R1 / 2), (real1)(ONE_R1 / 2));
1118  QRACK_CONST complex ONE_MINUS_I_DIV_2 = complex((real1)(ONE_R1 / 2), (real1)(-ONE_R1 / 2));
1119  QRACK_CONST complex mtrx[4]{ ONE_PLUS_I_DIV_2, ONE_MINUS_I_DIV_2, ONE_MINUS_I_DIV_2, ONE_PLUS_I_DIV_2 };
1120  Mtrx(mtrx, qubit);
1121  }
1122 
1129  virtual void ISqrtX(bitLenInt qubit)
1130  {
1131  QRACK_CONST complex ONE_PLUS_I_DIV_2 = complex((real1)(ONE_R1 / 2), (real1)(ONE_R1 / 2));
1132  QRACK_CONST complex ONE_MINUS_I_DIV_2 = complex((real1)(ONE_R1 / 2), (real1)(-ONE_R1 / 2));
1133  QRACK_CONST complex mtrx[4]{ ONE_MINUS_I_DIV_2, ONE_PLUS_I_DIV_2, ONE_PLUS_I_DIV_2, ONE_MINUS_I_DIV_2 };
1134  Mtrx(mtrx, qubit);
1135  }
1136 
1144  virtual void SqrtY(bitLenInt qubit)
1145  {
1146  QRACK_CONST complex ONE_PLUS_I_DIV_2 = complex((real1)(ONE_R1 / 2), (real1)(ONE_R1 / 2));
1147  QRACK_CONST complex ONE_PLUS_I_DIV_2_NEG = complex((real1)(-ONE_R1 / 2), (real1)(-ONE_R1 / 2));
1148  QRACK_CONST complex mtrx[4]{ ONE_PLUS_I_DIV_2, ONE_PLUS_I_DIV_2_NEG, ONE_PLUS_I_DIV_2, ONE_PLUS_I_DIV_2 };
1149  Mtrx(mtrx, qubit);
1150  }
1151 
1159  virtual void ISqrtY(bitLenInt qubit)
1160  {
1161  QRACK_CONST complex ONE_MINUS_I_DIV_2 = complex((real1)(ONE_R1 / 2), (real1)(-ONE_R1 / 2));
1162  QRACK_CONST complex ONE_MINUS_I_DIV_2_NEG = complex((real1)(-ONE_R1 / 2), (real1)(ONE_R1 / 2));
1163  QRACK_CONST complex mtrx[4]{ ONE_MINUS_I_DIV_2, ONE_MINUS_I_DIV_2, ONE_MINUS_I_DIV_2_NEG, ONE_MINUS_I_DIV_2 };
1164  Mtrx(mtrx, qubit);
1165  }
1166 
1172  virtual void SqrtW(bitLenInt qubit)
1173  {
1175  QRACK_CONST complex m01 = complex((real1)(-ONE_R1 / 2), (real1)(-ONE_R1 / 2));
1176  QRACK_CONST complex m10 = complex((real1)(ONE_R1 / 2), (real1)(-ONE_R1 / 2));
1177  QRACK_CONST complex mtrx[4]{ diag, m01, m10, diag };
1178  Mtrx(mtrx, qubit);
1179  }
1180 
1186  virtual void ISqrtW(bitLenInt qubit)
1187  {
1189  QRACK_CONST complex m01 = complex((real1)(ONE_R1 / 2), (real1)(ONE_R1 / 2));
1190  QRACK_CONST complex m10 = complex((real1)(-ONE_R1 / 2), (real1)(ONE_R1 / 2));
1191  QRACK_CONST complex mtrx[4]{ diag, m01, m10, diag };
1192  Mtrx(mtrx, qubit);
1193  }
1194 
1201  virtual void CH(bitLenInt control, bitLenInt target)
1202  {
1203  const std::vector<bitLenInt> controls{ control };
1207  MCMtrx(controls, mtrx, target);
1208  }
1209 
1216  virtual void AntiCH(bitLenInt control, bitLenInt target)
1217  {
1218  const std::vector<bitLenInt> controls{ control };
1222  MACMtrx(controls, mtrx, target);
1223  }
1224 
1231  virtual void CS(bitLenInt control, bitLenInt target)
1232  {
1233  const std::vector<bitLenInt> controls{ control };
1234  MCPhase(controls, ONE_CMPLX, I_CMPLX, target);
1235  }
1236 
1243  virtual void AntiCS(bitLenInt control, bitLenInt target)
1244  {
1245  const std::vector<bitLenInt> controls{ control };
1246  MACPhase(controls, ONE_CMPLX, I_CMPLX, target);
1247  }
1248 
1255  virtual void CIS(bitLenInt control, bitLenInt target)
1256  {
1257  const std::vector<bitLenInt> controls{ control };
1258  MCPhase(controls, ONE_CMPLX, -I_CMPLX, target);
1259  }
1260 
1267  virtual void AntiCIS(bitLenInt control, bitLenInt target)
1268  {
1269  const std::vector<bitLenInt> controls{ control };
1270  MACPhase(controls, ONE_CMPLX, -I_CMPLX, target);
1271  }
1272 
1279  virtual void CT(bitLenInt control, bitLenInt target)
1280  {
1281  const std::vector<bitLenInt> controls{ control };
1282  MCPhase(controls, ONE_CMPLX, complex(SQRT1_2_R1, SQRT1_2_R1), target);
1283  }
1284 
1291  virtual void CIT(bitLenInt control, bitLenInt target)
1292  {
1293  const std::vector<bitLenInt> controls{ control };
1294  MCPhase(controls, ONE_CMPLX, complex(SQRT1_2_R1, -SQRT1_2_R1), target);
1295  }
1296 
1303  virtual void CPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
1304  {
1305  if (n == 0) {
1306  return;
1307  }
1308 
1309  const std::vector<bitLenInt> controls{ control };
1310  MCPhase(controls, ONE_CMPLX, pow(-ONE_CMPLX, (real1)(ONE_R1 / pow2Ocl(n - 1U))), target);
1311  }
1312 
1319  virtual void AntiCPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
1320  {
1321  if (n == 0) {
1322  return;
1323  }
1324 
1325  const std::vector<bitLenInt> controls{ control };
1326  MACPhase(controls, ONE_CMPLX, pow(-ONE_CMPLX, (real1)(ONE_R1 / pow2Ocl(n - 1U))), target);
1327  }
1328 
1335  virtual void CIPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
1336  {
1337  if (n == 0) {
1338  return;
1339  }
1340 
1341  const std::vector<bitLenInt> controls{ control };
1342  MCPhase(controls, ONE_CMPLX, pow(-ONE_CMPLX, (real1)(-ONE_R1 / pow2Ocl(n - 1U))), target);
1343  }
1344 
1351  virtual void AntiCIPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
1352  {
1353  if (n == 0) {
1354  return;
1355  }
1356 
1357  const std::vector<bitLenInt> controls{ control };
1358  MACPhase(controls, ONE_CMPLX, pow(-ONE_CMPLX, (real1)(-ONE_R1 / pow2Ocl(n - 1U))), target);
1359  }
1360 
1377  virtual void AND(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit);
1378 
1384  virtual void OR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit);
1385 
1391  virtual void XOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit);
1392 
1397  virtual void CLAND(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit);
1398 
1403  virtual void CLOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit);
1404 
1409  virtual void CLXOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit);
1410 
1416  virtual void NAND(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit);
1417 
1423  virtual void NOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit);
1424 
1430  virtual void XNOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit);
1431 
1436  virtual void CLNAND(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit);
1437 
1442  virtual void CLNOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit);
1443 
1448  virtual void CLXNOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit);
1449 
1471  virtual void UniformlyControlledRY(const std::vector<bitLenInt>& controls, bitLenInt qubit, real1 const* angles);
1472 
1483  virtual void UniformlyControlledRZ(const std::vector<bitLenInt>& controls, bitLenInt qubit, real1 const* angles);
1484 
1490  virtual void RT(real1_f radians, bitLenInt qubit);
1491 
1497  virtual void RX(real1_f radians, bitLenInt qubit);
1498 
1504  virtual void RY(real1_f radians, bitLenInt qubit);
1505 
1511  virtual void RZ(real1_f radians, bitLenInt qubit);
1512 
1519  virtual void CRZ(real1_f radians, bitLenInt control, bitLenInt target);
1520 
1527  virtual void CRY(real1_f radians, bitLenInt control, bitLenInt target);
1528 
1529 #if ENABLE_ROT_API
1536  virtual void RTDyad(int numerator, int denomPower, bitLenInt qubit);
1537 
1543  virtual void RXDyad(int numerator, int denomPower, bitLenInt qubit);
1544 
1550  virtual void Exp(real1_f radians, bitLenInt qubit);
1551 
1557  virtual void Exp(
1558  const std::vector<bitLenInt>& controls, bitLenInt qubit, const complex* matrix2x2, bool antiCtrled = false);
1559 
1566  virtual void ExpDyad(int numerator, int denomPower, bitLenInt qubit);
1567 
1573  virtual void ExpX(real1_f radians, bitLenInt qubit);
1574 
1581  virtual void ExpXDyad(int numerator, int denomPower, bitLenInt qubit);
1582 
1588  virtual void ExpY(real1_f radians, bitLenInt qubit);
1589 
1596  virtual void ExpYDyad(int numerator, int denomPower, bitLenInt qubit);
1597 
1603  virtual void ExpZ(real1_f radians, bitLenInt qubit);
1604 
1611  virtual void ExpZDyad(int numerator, int denomPower, bitLenInt qubit);
1612 
1618  virtual void CRX(real1_f radians, bitLenInt control, bitLenInt target);
1619 
1625  virtual void CRXDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target);
1626 
1632  virtual void RYDyad(int numerator, int denomPower, bitLenInt qubit);
1633 
1640  virtual void CRYDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target);
1641 
1647  virtual void RZDyad(int numerator, int denomPower, bitLenInt qubit);
1648 
1655  virtual void CRZDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target);
1656 
1664  virtual void CRT(real1_f radians, bitLenInt control, bitLenInt target);
1665 
1672  virtual void CRTDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target);
1673 #endif
1674 
1687  virtual void H(bitLenInt start, bitLenInt length);
1688 
1690  virtual void X(bitLenInt start, bitLenInt length) { XMask(bitRegMask(start, length)); }
1691 
1692 #if ENABLE_REG_GATES
1693 
1695  virtual void U(bitLenInt start, bitLenInt length, real1_f theta, real1_f phi, real1_f lambda);
1696 
1698  virtual void U2(bitLenInt start, bitLenInt length, real1_f phi, real1_f lambda);
1699 
1701  virtual void SH(bitLenInt start, bitLenInt length);
1702 
1704  virtual void HIS(bitLenInt start, bitLenInt length);
1705 
1707  virtual void SqrtH(bitLenInt start, bitLenInt length);
1708 
1710  virtual void S(bitLenInt start, bitLenInt length);
1711 
1713  virtual void IS(bitLenInt start, bitLenInt length);
1714 
1716  virtual void T(bitLenInt start, bitLenInt length);
1717 
1719  virtual void IT(bitLenInt start, bitLenInt length);
1720 
1722  virtual void PhaseRootN(bitLenInt n, bitLenInt start, bitLenInt length);
1723 
1725  virtual void IPhaseRootN(bitLenInt n, bitLenInt start, bitLenInt length);
1726 
1728  virtual void Y(bitLenInt start, bitLenInt length);
1729 
1731  virtual void SqrtX(bitLenInt start, bitLenInt length);
1732 
1734  virtual void ISqrtX(bitLenInt start, bitLenInt length);
1735 
1737  virtual void SqrtY(bitLenInt start, bitLenInt length);
1738 
1740  virtual void ISqrtY(bitLenInt start, bitLenInt length);
1741 
1743  virtual void Z(bitLenInt start, bitLenInt length);
1744 
1746  virtual void CNOT(bitLenInt inputBits, bitLenInt targetBits, bitLenInt length);
1747 
1749  virtual void AntiCNOT(bitLenInt inputBits, bitLenInt targetBits, bitLenInt length);
1750 
1752  virtual void CCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length);
1753 
1755  virtual void AntiCCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length);
1756 
1758  virtual void CY(bitLenInt control, bitLenInt target, bitLenInt length);
1759 
1761  virtual void AntiCY(bitLenInt inputBits, bitLenInt targetBits, bitLenInt length);
1762 
1764  virtual void CCY(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length);
1765 
1767  virtual void AntiCCY(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length);
1768 
1770  virtual void CZ(bitLenInt control, bitLenInt target, bitLenInt length);
1771 
1773  virtual void AntiCZ(bitLenInt inputBits, bitLenInt targetBits, bitLenInt length);
1774 
1776  virtual void CCZ(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length);
1777 
1779  virtual void AntiCCZ(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length);
1780 
1782  virtual void Swap(bitLenInt start1, bitLenInt start2, bitLenInt length);
1783 
1785  virtual void ISwap(bitLenInt start1, bitLenInt start2, bitLenInt length);
1786 
1788  virtual void IISwap(bitLenInt start1, bitLenInt start2, bitLenInt length);
1789 
1791  virtual void SqrtSwap(bitLenInt start1, bitLenInt start2, bitLenInt length);
1792 
1794  virtual void ISqrtSwap(bitLenInt start1, bitLenInt start2, bitLenInt length);
1795 
1797  virtual void FSim(real1_f theta, real1_f phi, bitLenInt start1, bitLenInt start2, bitLenInt length);
1798 
1805  virtual void AND(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length);
1806 
1813  virtual void CLAND(bitLenInt qInputStart, const bitCapInt& classicalInput, bitLenInt outputStart, bitLenInt length);
1814 
1816  virtual void OR(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length);
1817 
1819  virtual void CLOR(bitLenInt qInputStart, const bitCapInt& classicalInput, bitLenInt outputStart, bitLenInt length);
1820 
1822  virtual void XOR(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length);
1823 
1825  virtual void CLXOR(bitLenInt qInputStart, const bitCapInt& classicalInput, bitLenInt outputStart, bitLenInt length);
1826 
1828  virtual void NAND(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length);
1829 
1831  virtual void CLNAND(
1832  bitLenInt qInputStart, const bitCapInt& classicalInput, bitLenInt outputStart, bitLenInt length);
1833 
1835  virtual void NOR(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length);
1836 
1838  virtual void CLNOR(bitLenInt qInputStart, const bitCapInt& classicalInput, bitLenInt outputStart, bitLenInt length);
1839 
1841  virtual void XNOR(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length);
1842 
1844  virtual void CLXNOR(
1845  bitLenInt qInputStart, const bitCapInt& classicalInput, bitLenInt outputStart, bitLenInt length);
1846 
1847 #if ENABLE_ROT_API
1853  virtual void RT(real1_f radians, bitLenInt start, bitLenInt length);
1854 
1861  virtual void RTDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
1862 
1868  virtual void RX(real1_f radians, bitLenInt start, bitLenInt length);
1869 
1875  virtual void RXDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
1876 
1882  virtual void CRX(real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length);
1883 
1889  virtual void CRXDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length);
1890 
1896  virtual void RY(real1_f radians, bitLenInt start, bitLenInt length);
1897 
1904  virtual void RYDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
1905 
1912  virtual void CRY(real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length);
1913 
1920  virtual void CRYDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length);
1921 
1927  virtual void RZ(real1_f radians, bitLenInt start, bitLenInt length);
1928 
1934  virtual void RZDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
1935 
1942  virtual void CRZ(real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length);
1943 
1950  virtual void CRZDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length);
1951 
1958  virtual void CRT(real1_f radians, bitLenInt control, bitLenInt target, bitLenInt length);
1959 
1966  virtual void CRTDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length);
1967 
1973  virtual void Exp(real1_f radians, bitLenInt start, bitLenInt length);
1974 
1981  virtual void ExpDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
1982 
1988  virtual void ExpX(real1_f radians, bitLenInt start, bitLenInt length);
1989 
1996  virtual void ExpXDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
1997 
2003  virtual void ExpY(real1_f radians, bitLenInt start, bitLenInt length);
2004 
2011  virtual void ExpYDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
2012 
2018  virtual void ExpZ(real1_f radians, bitLenInt start, bitLenInt length);
2019 
2026  virtual void ExpZDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length);
2027 #endif
2028 
2035  virtual void CH(bitLenInt control, bitLenInt target, bitLenInt length);
2036 
2043  virtual void CS(bitLenInt control, bitLenInt target, bitLenInt length);
2044 
2051  virtual void CIS(bitLenInt control, bitLenInt target, bitLenInt length);
2052 
2059  virtual void CT(bitLenInt control, bitLenInt target, bitLenInt length);
2060 
2067  virtual void CIT(bitLenInt control, bitLenInt target, bitLenInt length);
2068 
2075  virtual void CPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target, bitLenInt length);
2076 
2083  virtual void CIPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target, bitLenInt length);
2084 
2086 #endif
2087 
2095  virtual void ROL(bitLenInt shift, bitLenInt start, bitLenInt length);
2096 
2098  virtual void ROR(bitLenInt shift, bitLenInt start, bitLenInt length);
2099 
2101  virtual void ASL(bitLenInt shift, bitLenInt start, bitLenInt length);
2102 
2104  virtual void ASR(bitLenInt shift, bitLenInt start, bitLenInt length);
2105 
2107  virtual void LSL(bitLenInt shift, bitLenInt start, bitLenInt length);
2108 
2110  virtual void LSR(bitLenInt shift, bitLenInt start, bitLenInt length);
2111 
2113  virtual void INC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length);
2114 
2116  virtual void DEC(const bitCapInt& toSub, bitLenInt start, bitLenInt length)
2117  {
2118  const bitCapInt invToSub = pow2(length) - toSub;
2119  INC(invToSub, start, length);
2120  }
2121 
2123  virtual void INCDECC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
2124 
2126  virtual void INCC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
2127  {
2128  const bool hasCarry = M(carryIndex);
2129  if (hasCarry) {
2130  X(carryIndex);
2131  INCDECC(toAdd + 1U, start, length, carryIndex);
2132  } else {
2133  INCDECC(toAdd, start, length, carryIndex);
2134  }
2135  }
2136 
2138  virtual void DECC(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
2139  {
2140  const bool hasCarry = M(carryIndex);
2141  bitCapInt invToSub = pow2(length) - toSub;
2142  if (hasCarry) {
2143  X(carryIndex);
2144  } else {
2145  --invToSub;
2146  }
2147 
2148  INCDECC(invToSub, start, length, carryIndex);
2149  }
2150 
2152  virtual void CINC(
2153  const bitCapInt& toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls);
2154 
2156  virtual void CDEC(
2157  const bitCapInt& toSub, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls)
2158  {
2159  const bitCapInt invToSub = pow2(length) - toSub;
2160  CINC(invToSub, inOutStart, length, controls);
2161  }
2162 
2164  virtual void INCS(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
2165  {
2166  const bitCapInt signMask = pow2(length - 1U);
2167  INC(signMask, start, length);
2168  INCDECC(toAdd & ~signMask, start, length, overflowIndex);
2169  if (bi_compare_0(toAdd & signMask) == 0) {
2170  DEC(signMask, start, length);
2171  }
2172  }
2173 
2175  virtual void DECS(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
2176  {
2177  const bitCapInt invToSub = pow2(length) - toSub;
2178  INCS(invToSub, start, length, overflowIndex);
2179  }
2180 
2182  virtual void MULModNOut(
2183  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length);
2184 
2186  virtual void IMULModNOut(
2187  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length);
2188 
2190  virtual void CMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
2191  bitLenInt length, const std::vector<bitLenInt>& controls);
2192 
2194  virtual void CIMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
2195  bitLenInt length, const std::vector<bitLenInt>& controls);
2196 
2202  virtual void FullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
2203  {
2204  // See https://quantumcomputing.stackexchange.com/questions/1654/how-do-i-add-11-using-a-quantum-computer
2205 
2206  // Assume outputBit is in 0 state.
2207  CCNOT(inputBit1, inputBit2, carryOut);
2208  CNOT(inputBit1, inputBit2);
2209  CCNOT(inputBit2, carryInSumOut, carryOut);
2210  CNOT(inputBit2, carryInSumOut);
2211  CNOT(inputBit1, inputBit2);
2212  }
2213 
2219  virtual void IFullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
2220  {
2221  // See https://quantumcomputing.stackexchange.com/questions/1654/how-do-i-add-11-using-a-quantum-computer
2222  // Quantum computing is reversible! Simply perform the inverse operations in reverse order!
2223  // (CNOT and CCNOT are self-inverse.)
2224 
2225  // Assume outputBit is in 0 state.
2226  CNOT(inputBit1, inputBit2);
2227  CNOT(inputBit2, carryInSumOut);
2228  CCNOT(inputBit2, carryInSumOut, carryOut);
2229  CNOT(inputBit1, inputBit2);
2230  CCNOT(inputBit1, inputBit2, carryOut);
2231  }
2232 
2238  virtual void CFullAdd(const std::vector<bitLenInt>& controls, bitLenInt inputBit1, bitLenInt inputBit2,
2239  bitLenInt carryInSumOut, bitLenInt carryOut);
2240 
2246  virtual void CIFullAdd(const std::vector<bitLenInt>& controls, bitLenInt inputBit1, bitLenInt inputBit2,
2247  bitLenInt carryInSumOut, bitLenInt carryOut);
2248 
2254  virtual void ADC(bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry);
2255 
2261  virtual void IADC(bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry);
2262 
2268  virtual void CADC(const std::vector<bitLenInt>& controls, bitLenInt input1, bitLenInt input2, bitLenInt output,
2269  bitLenInt length, bitLenInt carry);
2270 
2276  virtual void CIADC(const std::vector<bitLenInt>& controls, bitLenInt input1, bitLenInt input2, bitLenInt output,
2277  bitLenInt length, bitLenInt carry);
2278 
2293  virtual void QFT(bitLenInt start, bitLenInt length, bool trySeparate = false);
2294 
2301  virtual void QFTR(const std::vector<bitLenInt>& qubits, bool trySeparate = false);
2302 
2309  virtual void IQFT(bitLenInt start, bitLenInt length, bool trySeparate = false);
2310 
2317  virtual void IQFTR(const std::vector<bitLenInt>& qubits, bool trySeparate = false);
2318 
2320  virtual void ZeroPhaseFlip(bitLenInt start, bitLenInt length);
2321 
2323  virtual void PhaseFlip() { Phase(-ONE_CMPLX, -ONE_CMPLX, 0); }
2324 
2326  virtual void SetReg(bitLenInt start, bitLenInt length, const bitCapInt& value);
2327 
2329  virtual bitCapInt MReg(bitLenInt start, bitLenInt length) { return ForceMReg(start, length, ZERO_BCI, false); }
2330 
2332  virtual bitCapInt MAll() { return MReg(0, qubitCount); }
2333 
2339  virtual bitCapInt ForceMReg(
2340  bitLenInt start, bitLenInt length, const bitCapInt& result, bool doForce = true, bool doApply = true);
2341 
2343  virtual bitCapInt M(const std::vector<bitLenInt>& bits) { return ForceM(bits, std::vector<bool>()); }
2344 
2346  virtual bitCapInt ForceM(const std::vector<bitLenInt>& bits, const std::vector<bool>& values, bool doApply = true);
2347 
2349  virtual void Swap(bitLenInt qubit1, bitLenInt qubit2);
2350 
2352  virtual void ISwap(bitLenInt qubit1, bitLenInt qubit2);
2353 
2355  virtual void IISwap(bitLenInt qubit1, bitLenInt qubit2);
2356 
2358  virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2);
2359 
2361  virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2);
2362 
2364  virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2) = 0;
2365 
2367  virtual void Reverse(bitLenInt first, bitLenInt last)
2368  {
2369  while ((last > 0U) && (first < (last - 1U))) {
2370  --last;
2371  Swap(first, last);
2372  ++first;
2373  }
2374  }
2375 
2389  virtual real1_f Prob(bitLenInt qubit) = 0;
2395  virtual real1_f CProb(bitLenInt control, bitLenInt target)
2396  {
2397  AntiCNOT(control, target);
2398  const real1_f prob = Prob(target);
2399  AntiCNOT(control, target);
2400 
2401  return prob;
2402  }
2408  virtual real1_f ACProb(bitLenInt control, bitLenInt target)
2409  {
2410  CNOT(control, target);
2411  const real1_f prob = Prob(target);
2412  CNOT(control, target);
2413 
2414  return prob;
2415  }
2416 
2422  virtual real1_f ProbAll(const bitCapInt& fullRegister)
2423  {
2424  return clampProb((real1_f)norm(GetAmplitude(fullRegister)));
2425  }
2426 
2432  virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt& permutation);
2433 
2443  virtual real1_f ProbMask(const bitCapInt& mask, const bitCapInt& permutation);
2444 
2453  virtual void ProbMaskAll(const bitCapInt& mask, real1* probsArray);
2454 
2463  virtual void ProbBitsAll(const std::vector<bitLenInt>& bits, real1* probsArray);
2464 
2473  virtual real1_f VarianceBitsAll(const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
2474  {
2475  return ExpVarBitsAll(false, bits, offset);
2476  }
2477 
2487  bool roundRz, const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
2488  {
2489  return VarianceBitsAll(bits, offset);
2490  }
2491 
2500  virtual real1_f VariancePauliAll(std::vector<bitLenInt> bits, std::vector<Pauli> paulis);
2501 
2511  const std::vector<bitLenInt>& bits, const std::vector<real1_f>& basisOps, std::vector<real1_f> eigenVals = {})
2512  {
2513  return ExpVarUnitaryAll(false, bits, basisOps, eigenVals);
2514  }
2515 
2524  virtual real1_f VarianceUnitaryAll(const std::vector<bitLenInt>& bits,
2525  const std::vector<std::shared_ptr<complex>>& basisOps, std::vector<real1_f> eigenVals = {})
2526  {
2527  return ExpVarUnitaryAll(false, bits, basisOps, eigenVals);
2528  }
2529 
2538  virtual real1_f VarianceFloatsFactorized(const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights);
2539 
2550  bool roundRz, const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights)
2551  {
2552  return VarianceFloatsFactorized(bits, weights);
2553  }
2554 
2564  const std::vector<bitLenInt>& bits, const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI);
2565 
2575  virtual real1_f VarianceBitsFactorizedRdm(bool roundRz, const std::vector<bitLenInt>& bits,
2576  const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI)
2577  {
2578  return VarianceBitsFactorized(bits, perms, offset);
2579  }
2580 
2589  virtual real1_f ExpectationBitsAll(const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
2590  {
2591  return ExpVarBitsAll(true, bits, offset);
2592  }
2593 
2602  virtual real1_f ExpectationPauliAll(std::vector<bitLenInt> bits, std::vector<Pauli> paulis);
2603 
2612  virtual real1_f ExpectationUnitaryAll(const std::vector<bitLenInt>& bits,
2613  const std::vector<std::shared_ptr<complex>>& basisOps, std::vector<real1_f> eigenVals = {})
2614  {
2615  return ExpVarUnitaryAll(true, bits, basisOps, eigenVals);
2616  }
2617 
2627  const std::vector<bitLenInt>& bits, const std::vector<real1_f>& basisOps, std::vector<real1_f> eigenVals = {})
2628  {
2629  return ExpVarUnitaryAll(true, bits, basisOps, eigenVals);
2630  }
2631 
2641  const std::vector<bitLenInt>& bits, const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI);
2642 
2652  virtual real1_f ExpectationBitsFactorizedRdm(bool roundRz, const std::vector<bitLenInt>& bits,
2653  const std::vector<bitCapInt>& perms, const bitCapInt& offset = ZERO_BCI)
2654  {
2655  return ExpectationBitsFactorized(bits, perms, offset);
2656  }
2657 
2667  const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights);
2668 
2679  bool roundRz, const std::vector<bitLenInt>& bits, const std::vector<real1_f>& weights)
2680  {
2681  return ExpectationFloatsFactorized(bits, weights);
2682  }
2683 
2690  virtual real1_f ProbRdm(bitLenInt qubit) { return Prob(qubit); }
2696  virtual real1_f ProbAllRdm(bool roundRz, const bitCapInt& fullRegister) { return ProbAll(fullRegister); }
2706  virtual real1_f ProbMaskRdm(bool roundRz, const bitCapInt& mask, const bitCapInt& permutation)
2707  {
2708  return ProbMask(mask, permutation);
2709  }
2719  bool roundRz, const std::vector<bitLenInt>& bits, const bitCapInt& offset = ZERO_BCI)
2720  {
2721  return ExpectationBitsAll(bits, offset);
2722  }
2723 
2738  virtual std::map<bitCapInt, int> MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots);
2739 
2747  virtual void MultiShotMeasureMask(
2748  const std::vector<bitCapInt>& qPowers, unsigned shots, unsigned long long* shotsArray);
2749 
2759  virtual void SetBit(bitLenInt qubit, bool value)
2760  {
2761  if (value != M(qubit)) {
2762  X(qubit);
2763  }
2764  }
2765 
2772  virtual bool ApproxCompare(QInterfacePtr toCompare, real1_f error_tol = TRYDECOMPOSE_EPSILON)
2773  {
2774  return SumSqrDiff(toCompare) <= error_tol;
2775  }
2776 
2782  virtual real1_f SumSqrDiff(QInterfacePtr toCompare) = 0;
2783 
2789  virtual bool TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol = TRYDECOMPOSE_EPSILON);
2790 
2797  virtual void UpdateRunningNorm(real1_f norm_thresh = REAL1_DEFAULT_ARG) = 0;
2798 
2805  virtual void NormalizeState(
2806  real1_f nrm = REAL1_DEFAULT_ARG, real1_f norm_thresh = REAL1_DEFAULT_ARG, real1_f phaseArg = ZERO_R1_F) = 0;
2807 
2813  virtual void Finish() {}
2814 
2819  virtual bool isFinished() { return true; }
2820 
2825  virtual void Dump() {}
2826 
2831  virtual bool isBinaryDecisionTree() { return false; }
2832 
2837  virtual bool isClifford() { return false; }
2838 
2843  virtual bool isClifford(bitLenInt qubit) { return false; }
2844 
2848  virtual bool isOpenCL() { return false; }
2849 
2863  virtual bool TrySeparate(const std::vector<bitLenInt>& qubits, real1_f error_tol) { return false; }
2867  virtual bool TrySeparate(bitLenInt qubit) { return false; }
2871  virtual bool TrySeparate(bitLenInt qubit1, bitLenInt qubit2) { return false; }
2881  virtual double GetUnitaryFidelity() { return 1.0; }
2885  virtual void ResetUnitaryFidelity() {}
2889  virtual void SetSdrp(real1_f sdrp){};
2893  virtual void SetNcrp(real1_f ncrp){};
2901  virtual void SetReactiveSeparate(bool isAggSep) {}
2909  virtual bool GetReactiveSeparate() { return false; }
2917  virtual void SetTInjection(bool useGadget) {}
2925  virtual bool GetTInjection() { return false; }
2931  virtual void SetNoiseParameter(real1_f lambda) {}
2937  virtual real1_f GetNoiseParameter() { return ZERO_R1_F; }
2938 
2942  virtual QInterfacePtr Clone() = 0;
2943 
2947  virtual void SetDevice(int64_t dID) = 0;
2948 
2952  virtual int64_t GetDevice() { return -1; }
2953 
2957  bitCapIntOcl GetMaxSize() { return pow2Ocl(sizeof(bitCapInt) * 8); };
2958 
2963  {
2964  complex amp;
2965  bitCapInt perm = ZERO_BCI;
2966  do {
2967  amp = GetAmplitude(perm);
2968  bi_increment(&perm, 1U);
2969  } while ((abs(amp) <= REAL1_EPSILON) && (perm < maxQPower));
2970 
2971  return (real1_f)std::arg(amp);
2972  }
2973 
2979  virtual void DepolarizingChannelWeak1Qb(bitLenInt qubit, real1_f lambda);
2980 
2993 
2995 };
2996 } // namespace Qrack
void bi_or_ip(BigInteger *left, const BigInteger &right)
Definition: big_integer.hpp:429
void bi_increment(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:214
int bi_compare_0(const BigInteger &left)
Definition: big_integer.hpp:134
Definition: parallel_for.hpp:19
void SetConcurrencyLevel(unsigned num)
Definition: parallel_for.hpp:28
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:138
virtual void GetQuantumState(complex *outputState)=0
Get the pure quantum state representation.
bitCapInt maxQPower
Definition: qinterface.hpp:146
void SetRandomSeed(uint32_t seed)
Definition: qinterface.hpp:243
virtual void SetConcurrency(uint32_t threadsPerEngine)
Set the number of threads in parallel for loops, per component QEngine.
Definition: qinterface.hpp:257
real1 amplitudeFloor
Definition: qinterface.hpp:145
void MACWrapper(const std::vector< bitLenInt > &controls, Fn fn)
Definition: qinterface.hpp:176
bool useRDRAND
Definition: qinterface.hpp:142
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:452
virtual bitCapInt GetMaxQPower()
Get the maximum number of basis states, namely for qubits.
Definition: qinterface.hpp:263
virtual void Dispose(bitLenInt start, bitLenInt length, const bitCapInt &disposedPerm)=0
Dispose a a contiguous set of qubits that are already in a permutation eigenstate.
std::shared_ptr< RdRandom > hardware_rand_generator
Definition: qinterface.hpp:149
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:346
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)=0
Schmidt decompose a length of qubits.
qrack_rand_gen_ptr rand_generator
Definition: qinterface.hpp:147
virtual bitLenInt ComposeNoClone(QInterfacePtr toCopy)
This is a variant of Compose() for a toCopy argument that will definitely not be reused once "Compose...
Definition: qinterface.hpp:351
bool randGlobalPhase
Definition: qinterface.hpp:141
virtual void SetPermutation(const bitCapInt &perm, const complex &phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qinterface.cpp:96
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
QInterface()
Default constructor, primarily for protected internal use.
Definition: qinterface.hpp:224
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:250
std::uniform_real_distribution< real1_s > rand_distribution
Definition: qinterface.hpp:148
virtual void SetAmplitude(const bitCapInt &perm, const complex &amp)=0
Sets the representational amplitude of a full permutation.
virtual bitLenInt Allocate(bitLenInt start, bitLenInt length)=0
Allocate new "length" count of |0> state qubits at specified qubit index start position.
virtual void SetQuantumState(const complex *inputState)=0
Set an arbitrary pure quantum state representation.
virtual bitCapInt SampleClone(const std::vector< bitCapInt > &qPowers)
Definition: qinterface.hpp:188
static real1_f normHelper(const complex &c)
Definition: qinterface.hpp:153
static real1_f clampProb(real1_f toClamp)
Definition: qinterface.hpp:155
virtual real1_f ExpVarUnitaryAll(bool isExp, const std::vector< bitLenInt > &bits, const std::vector< std::shared_ptr< complex >> &basisOps, std::vector< real1_f > eigenVals={})
Definition: qinterface.cpp:472
bitLenInt qubitCount
Definition: qinterface.hpp:143
virtual bitLenInt GetQubitCount()
Get the count of bits in this register.
Definition: qinterface.hpp:260
uint32_t randomSeed
Definition: qinterface.hpp:144
real1_f Rand()
Generate a random real number between 0 and 1.
Definition: qinterface.hpp:268
virtual real1_f ExpVarBitsAll(bool isExp, const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Definition: qinterface.hpp:207
virtual void Dispose(bitLenInt start, bitLenInt length)=0
Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separa...
virtual bool GetIsArbitraryGlobalPhase()
Definition: qinterface.hpp:265
bool doNormalize
Definition: qinterface.hpp:140
complex GetNonunitaryPhase()
Definition: qinterface.hpp:166
virtual ~QInterface()
Definition: qinterface.hpp:238
virtual void GetProbs(real1 *outputProbs)=0
Get the pure quantum state representation.
virtual complex GetAmplitude(const bitCapInt &perm)=0
Get the representational amplitude of a full permutation.
Half-precision floating-point type.
Definition: half.hpp:2222
virtual void MULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: arithmetic.cpp:126
virtual void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Subtract a classical integer from the register, with sign and without carry.
Definition: qinterface.hpp:2175
virtual void ASL(bitLenInt shift, bitLenInt start, bitLenInt length)
Arithmetic shift left, with last 2 bits as sign and carry.
Definition: qinterface.cpp:326
virtual void IFullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
Inverse of FullAdd.
Definition: qinterface.hpp:2219
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC.
Definition: arithmetic.cpp:52
virtual void CADC(const std::vector< bitLenInt > &controls, bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
Add a quantum integer to a quantum integer, with carry and with controls.
Definition: arithmetic.cpp:371
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: arithmetic.cpp:78
virtual void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qinterface.hpp:2164
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qinterface.hpp:2138
virtual void ADC(bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
Add a quantum integer to a quantum integer, with carry.
Definition: arithmetic.cpp:329
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2116
virtual void CFullAdd(const std::vector< bitLenInt > &controls, bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
Controlled quantum analog of classical "Full Adder" gate.
Definition: arithmetic.cpp:275
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: arithmetic.cpp:20
virtual void LSR(bitLenInt shift, bitLenInt start, bitLenInt length)
Logical shift right, filling the extra bits with |0>
Definition: qinterface.cpp:377
virtual void FullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
Quantum analog of classical "Full Adder" gate.
Definition: qinterface.hpp:2202
virtual 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: arithmetic.cpp:164
virtual void CIFullAdd(const std::vector< bitLenInt > &controls, bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)
Inverse of CFullAdd.
Definition: arithmetic.cpp:301
virtual void CIADC(const std::vector< bitLenInt > &controls, bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
Inverse of CADC.
Definition: arithmetic.cpp:393
virtual void ROL(bitLenInt shift, bitLenInt start, bitLenInt length)
Circular shift left - shift bits left, and carry last bits.
Definition: qinterface.cpp:290
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract classical integer (without sign, with controls)
Definition: qinterface.hpp:2156
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qinterface.hpp:2126
virtual void IADC(bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)
Inverse of ADC.
Definition: arithmetic.cpp:350
virtual 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: arithmetic.cpp:200
virtual 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: arithmetic.cpp:239
virtual void ROR(bitLenInt shift, bitLenInt start, bitLenInt length)
Circular shift right - shift bits right, and carry first bits.
Definition: qinterface.cpp:308
virtual void LSL(bitLenInt shift, bitLenInt start, bitLenInt length)
Logical shift left, filling the extra bits with |0>
Definition: qinterface.cpp:362
virtual void ASR(bitLenInt shift, bitLenInt start, bitLenInt length)
Arithmetic shift right, with last 2 bits as sign and carry.
Definition: qinterface.cpp:344
virtual void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: gates.cpp:145
virtual void CPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
Controlled "PhaseRootN" gate.
Definition: qinterface.hpp:1303
virtual void CIPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
Controlled inverse "PhaseRootN" gate.
Definition: qinterface.hpp:1335
virtual void AntiCIAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination)
(Anti-)Controlled inverse "Azimuth, Inclination" (RY-RZ)
Definition: rotational.cpp:115
virtual void ISqrtX(bitLenInt qubit)
Inverse square root of X gate.
Definition: qinterface.hpp:1129
virtual void ISqrtY(bitLenInt qubit)
Inverse square root of Y gate.
Definition: qinterface.hpp:1159
virtual void CZ(bitLenInt control, bitLenInt target)
Controlled Z gate.
Definition: qinterface.hpp:760
virtual void CU(const std::vector< bitLenInt > &controls, bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
Controlled general unitary gate.
Definition: rotational.cpp:29
virtual void SH(bitLenInt qubit)
Y-basis transformation gate.
Definition: qinterface.hpp:925
virtual void AntiCS(bitLenInt control, bitLenInt target)
(Anti-)controlled S gate
Definition: qinterface.hpp:1243
virtual void CCZ(bitLenInt control1, bitLenInt control2, bitLenInt target)
Doubly-Controlled Z gate.
Definition: qinterface.hpp:783
virtual void UCPhase(const std::vector< bitLenInt > &controls, const complex &topLeft, const complex &bottomRight, bitLenInt target, const bitCapInt &perm)
Apply a single bit transformation that only effects phase, with arbitrary control bits,...
Definition: qinterface.hpp:573
virtual void CS(bitLenInt control, bitLenInt target)
Controlled S gate.
Definition: qinterface.hpp:1231
virtual void CIS(bitLenInt control, bitLenInt target)
Controlled inverse S gate.
Definition: qinterface.hpp:1255
virtual void SqrtY(bitLenInt qubit)
Square root of Y gate.
Definition: qinterface.hpp:1144
virtual void CNOT(bitLenInt control, bitLenInt target)
Controlled NOT gate.
Definition: qinterface.hpp:691
virtual void TimeEvolve(Hamiltonian h, real1_f timeDiff)
To define a Hamiltonian, give a vector of controlled single bit gates ("HamiltonianOp" instances) tha...
Definition: gates.cpp:429
virtual void SqrtW(bitLenInt qubit)
Square root of W gate.
Definition: qinterface.hpp:1172
virtual void IS(bitLenInt qubit)
Inverse S gate.
Definition: qinterface.hpp:1016
virtual void MACMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary (anti-)control bits.
Definition: qinterface.hpp:477
virtual void S(bitLenInt qubit)
S gate.
Definition: qinterface.hpp:1009
virtual void CT(bitLenInt control, bitLenInt target)
Controlled T gate.
Definition: qinterface.hpp:1279
virtual void UniformlyControlledSingleBit(const std::vector< bitLenInt > &controls, bitLenInt qubit, const complex *mtrxs)
Apply a "uniformly controlled" arbitrary single bit unitary transformation.
Definition: qinterface.hpp:609
virtual void Y(bitLenInt qubit)
Y gate.
Definition: qinterface.hpp:1083
virtual bool ForceM(bitLenInt qubit, bool result, bool doForce=true, bool doApply=true)=0
Act as if is a measurement was applied, except force the (usually random) result.
virtual void CY(bitLenInt control, bitLenInt target)
Controlled Y gate.
Definition: qinterface.hpp:714
virtual void AntiCIPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
(Anti-)controlled inverse "PhaseRootN" gate
Definition: qinterface.hpp:1351
virtual void CH(bitLenInt control, bitLenInt target)
Controlled H gate.
Definition: qinterface.hpp:1201
virtual void AntiCAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination)
(Anti-)Controlled "Azimuth, Inclination" (RY-RZ)
Definition: rotational.cpp:103
virtual void H(bitLenInt qubit)
Hadamard gate.
Definition: qinterface.hpp:895
virtual void CIAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination)
Controlled inverse "Azimuth, Inclination" (RY-RZ)
Definition: rotational.cpp:89
virtual void CSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary control bits.
Definition: gates.cpp:284
virtual void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: gates.cpp:272
virtual void AI(bitLenInt target, real1_f azimuth, real1_f inclination)
"Azimuth, Inclination" (RY-RZ)
Definition: rotational.cpp:53
virtual void AntiCPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)
(Anti-)controlled "PhaseRootN" gate
Definition: qinterface.hpp:1319
virtual void YMask(const bitCapInt &mask)
Masked Y gate.
Definition: gates.cpp:113
virtual void Mtrx(const complex *mtrx, bitLenInt qubit)=0
Apply an arbitrary single bit unitary transformation.
virtual 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: qinterface.hpp:561
virtual void UCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target, const bitCapInt &controlPerm)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits,...
Definition: gates.cpp:23
virtual void HIS(bitLenInt qubit)
Y-basis (inverse) transformation gate.
Definition: qinterface.hpp:939
virtual void Phase(const complex &topLeft, const complex &bottomRight, bitLenInt qubit)
Apply a single bit transformation that only effects phase.
Definition: qinterface.hpp:498
virtual void Invert(const complex &topRight, const complex &bottomLeft, bitLenInt qubit)
Apply a single bit transformation that reverses bit probability and might effect phase.
Definition: qinterface.hpp:511
virtual void CAI(bitLenInt control, bitLenInt target, real1_f azimuth, real1_f inclination)
Controlled "Azimuth, Inclination" (RY-RZ)
Definition: rotational.cpp:77
virtual void CCY(bitLenInt control1, bitLenInt control2, bitLenInt target)
Doubly-Controlled Y gate.
Definition: qinterface.hpp:737
virtual void AntiCZ(bitLenInt control, bitLenInt target)
Anti controlled Z gate.
Definition: qinterface.hpp:771
virtual void AntiCU(const std::vector< bitLenInt > &controls, bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
(Anti-)Controlled general unitary gate
Definition: rotational.cpp:41
virtual void CISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary control bits.
Definition: gates.cpp:334
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1066
virtual 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: qinterface.hpp:545
virtual void U2(bitLenInt target, real1_f phi, real1_f lambda)
2-parameter unitary gate
Definition: qinterface.hpp:813
virtual void Z(bitLenInt qubit)
Z gate.
Definition: qinterface.hpp:1099
virtual void AntiCNOT(bitLenInt control, bitLenInt target)
Anti controlled NOT gate.
Definition: qinterface.hpp:702
virtual void AntiCY(bitLenInt control, bitLenInt target)
Anti controlled Y gate.
Definition: qinterface.hpp:725
virtual void ISqrtW(bitLenInt qubit)
Inverse square root of W gate.
Definition: qinterface.hpp:1186
virtual void PhaseParity(real1_f radians, const bitCapInt &mask)
Parity phase gate.
Definition: gates.cpp:402
virtual void IAI(bitLenInt target, real1_f azimuth, real1_f inclination)
Invert "Azimuth, Inclination" (RY-RZ)
Definition: rotational.cpp:64
virtual void AntiCISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary (anti) control bits.
Definition: gates.cpp:390
virtual void PhaseRootN(bitLenInt n, bitLenInt qubit)
"PhaseRootN" gate
Definition: qinterface.hpp:1037
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual void AntiCIS(bitLenInt control, bitLenInt target)
(Anti-)controlled inverse S gate
Definition: qinterface.hpp:1267
virtual void SqrtX(bitLenInt qubit)
Square root of X gate.
Definition: qinterface.hpp:1115
virtual void IU2(bitLenInt target, real1_f phi, real1_f lambda)
Inverse 2-parameter unitary gate.
Definition: qinterface.hpp:820
virtual void AntiCCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target)
Anti doubly-controlled NOT gate.
Definition: qinterface.hpp:680
virtual void PhaseRootNMask(bitLenInt n, const bitCapInt &mask)
Masked PhaseRootN gate.
Definition: gates.cpp:156
virtual void SqrtH(bitLenInt qubit)
Square root of Hadamard gate.
Definition: qinterface.hpp:908
virtual 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: qinterface.hpp:520
virtual void AntiCCY(bitLenInt control1, bitLenInt control2, bitLenInt target)
Anti doubly-controlled Y gate.
Definition: qinterface.hpp:748
virtual bool M(bitLenInt qubit)
Measurement gate.
Definition: qinterface.hpp:995
virtual 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: qinterface.hpp:535
virtual void AntiCSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary (anti) control bits.
Definition: gates.cpp:378
virtual void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)=0
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
virtual void CIT(bitLenInt control, bitLenInt target)
Controlled inverse T gate.
Definition: qinterface.hpp:1291
virtual void IT(bitLenInt qubit)
Inverse T gate.
Definition: qinterface.hpp:1030
virtual void AntiCCZ(bitLenInt control1, bitLenInt control2, bitLenInt target)
Anti doubly-controlled Z gate.
Definition: qinterface.hpp:794
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: gates.cpp:248
virtual void T(bitLenInt qubit)
T gate.
Definition: qinterface.hpp:1023
virtual void CCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target)
Doubly-controlled NOT gate.
Definition: qinterface.hpp:669
virtual void XMask(const bitCapInt &mask)
Masked X gate.
Definition: gates.cpp:102
virtual void AntiCH(bitLenInt control, bitLenInt target)
(Anti-)controlled H gate
Definition: qinterface.hpp:1216
virtual void UCInvert(const std::vector< bitLenInt > &controls, const complex &topRight, const complex &bottomLeft, bitLenInt target, const bitCapInt &perm)
Apply a single bit transformation that reverses bit probability and might effect phase,...
Definition: qinterface.hpp:588
virtual void IQFTR(const std::vector< bitLenInt > &qubits, bool trySeparate=false)
Inverse Quantum Fourier Transform (random access) - Apply the inverse quantum Fourier transform to th...
Definition: qinterface.cpp:169
virtual void Reverse(bitLenInt first, bitLenInt last)
Reverse all of the bits in a sequence.
Definition: qinterface.hpp:2367
virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse square root of Swap gate.
Definition: gates.cpp:225
virtual bitCapInt ForceMReg(bitLenInt start, bitLenInt length, const bitCapInt &result, bool doForce=true, bool doApply=true)
Act as if is a measurement was applied, except force the (usually random) result.
Definition: qinterface.cpp:210
virtual void QFTR(const std::vector< bitLenInt > &qubits, bool trySeparate=false)
Quantum Fourier Transform (random access) - Apply the quantum Fourier transform to the register.
Definition: qinterface.cpp:149
virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)=0
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
virtual 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: gates.cpp:190
virtual void ISwap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register, and apply phase factor of i if bits are different.
Definition: gates.cpp:178
virtual bitCapInt MAll()
Measure permutation state of all coherent bits.
Definition: qinterface.hpp:2332
virtual void QFT(bitLenInt start, bitLenInt length, bool trySeparate=false)
Quantum Fourier Transform - Apply the quantum Fourier transform to the register.
Definition: qinterface.cpp:107
virtual void PhaseFlip()
Phase flip always - equivalent to Z X Z X on any bit in the QInterface.
Definition: qinterface.hpp:2323
virtual bitCapInt M(const std::vector< bitLenInt > &bits)
Measure bits with indices in array, and return a mask of the results.
Definition: qinterface.hpp:2343
virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Square root of Swap gate.
Definition: gates.cpp:202
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:167
virtual void ZeroPhaseFlip(bitLenInt start, bitLenInt length)
Reverse the phase of the state where the register equals zero.
Definition: gates.cpp:84
virtual void SetReg(bitLenInt start, bitLenInt length, const bitCapInt &value)
Set register bits to given permutation.
Definition: qinterface.cpp:188
virtual bitCapInt MReg(bitLenInt start, bitLenInt length)
Measure permutation state of a register.
Definition: qinterface.hpp:2329
virtual void IQFT(bitLenInt start, bitLenInt length, bool trySeparate=false)
Inverse Quantum Fourier Transform - Apply the inverse quantum Fourier transform to the register.
Definition: qinterface.cpp:129
virtual void XOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "XOR" gate.
Definition: logic.cpp:55
virtual void OR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "OR" gate.
Definition: logic.cpp:36
virtual void XNOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "XNOR" gate.
Definition: logic.cpp:84
virtual void CLXNOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "XNOR" gate.
Definition: logic.cpp:130
virtual void CLNAND(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "NAND" gate.
Definition: logic.cpp:118
virtual void AND(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "AND" gate.
Definition: logic.cpp:18
virtual void CLAND(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "AND" gate.
Definition: logic.cpp:90
virtual void CLOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "OR" gate.
Definition: logic.cpp:97
virtual void NAND(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "NAND" gate.
Definition: logic.cpp:72
virtual void CLNOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "NOR" gate.
Definition: logic.cpp:124
virtual void CLXOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)
Quantum analog of classical "XOR" gate.
Definition: logic.cpp:106
virtual void NOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)
Quantum analog of classical "NOR" gate.
Definition: logic.cpp:78
virtual void X(bitLenInt start, bitLenInt length)
Bitwise Pauli X (or logical "NOT") operator.
Definition: qinterface.hpp:1690
virtual void H(bitLenInt start, bitLenInt length)
Bitwise Hadamard.
virtual void ExpZDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction Pauli Z exponentiation gate.
Definition: qinterface.cpp:1178
virtual void RZDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction Z axis rotation gate.
Definition: qinterface.cpp:1190
virtual void ExpX(real1_f radians, bitLenInt qubit)
Pauli X exponentiation gate.
Definition: rotational.cpp:248
virtual void CRTDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction "phase shift gate".
Definition: qinterface.cpp:1194
virtual void ExpDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction (identity) exponentiation gate.
Definition: qinterface.cpp:1160
virtual void CRZDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction Z axis rotation gate.
Definition: qinterface.cpp:1212
virtual void RX(real1_f radians, bitLenInt qubit)
X axis rotation gate.
Definition: rotational.cpp:177
virtual void CRZ(real1_f radians, bitLenInt control, bitLenInt target)
Controlled Z axis rotation gate.
Definition: rotational.cpp:204
virtual void RYDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction Y axis rotation gate.
Definition: qinterface.cpp:1187
virtual void UniformlyControlledRZ(const std::vector< bitLenInt > &controls, bitLenInt qubit, real1 const *angles)
Apply a "uniformly controlled" rotation of a bit around the Pauli Z axis.
Definition: rotational.cpp:151
virtual void ExpY(real1_f radians, bitLenInt qubit)
Pauli Y exponentiation gate.
Definition: rotational.cpp:255
virtual void CRT(real1_f radians, bitLenInt control, bitLenInt target)
Controlled "phase shift gate".
Definition: rotational.cpp:269
virtual void CRY(real1_f radians, bitLenInt control, bitLenInt target)
Controlled Y axis rotation gate.
Definition: rotational.cpp:213
virtual void RY(real1_f radians, bitLenInt qubit)
Y axis rotation gate.
Definition: rotational.cpp:187
virtual void CRX(real1_f radians, bitLenInt control, bitLenInt target)
Controlled X axis rotation gate.
Definition: rotational.cpp:276
virtual void ExpYDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction Pauli Y exponentiation gate.
Definition: qinterface.cpp:1172
virtual void RTDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction phase shift gate.
Definition: qinterface.cpp:1157
virtual void RZ(real1_f radians, bitLenInt qubit)
Z axis rotation gate.
Definition: rotational.cpp:196
virtual void RT(real1_f radians, bitLenInt qubit)
Phase shift gate.
Definition: rotational.cpp:171
virtual void ExpZ(real1_f radians, bitLenInt qubit)
Pauli Z exponentiation gate.
Definition: rotational.cpp:262
virtual void CRYDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction y axis rotation gate.
Definition: qinterface.cpp:1206
virtual void RXDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction X axis rotation gate.
Definition: qinterface.cpp:1184
virtual void UniformlyControlledRY(const std::vector< bitLenInt > &controls, bitLenInt qubit, real1 const *angles)
Apply a "uniformly controlled" rotation of a bit around the Pauli Y axis.
Definition: rotational.cpp:130
virtual void ExpXDyad(int numerator, int denomPower, bitLenInt qubit)
Dyadic fraction Pauli X exponentiation gate.
Definition: qinterface.cpp:1166
virtual void Exp(real1_f radians, bitLenInt qubit)
(Identity) Exponentiation gate
Definition: rotational.cpp:225
virtual void CRXDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)
Controlled dyadic fraction X axis rotation gate.
Definition: qinterface.cpp:1200
virtual void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qinterface.hpp:2825
virtual bool isBinaryDecisionTree()
Returns "true" if current state representation is definitely a binary decision tree,...
Definition: qinterface.hpp:2831
virtual real1_f VarianceBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qinterface.cpp:573
virtual real1_f ProbAllRdm(bool roundRz, const bitCapInt &fullRegister)
Direct measure of full permutation probability, treating all ancillary qubits as post-selected T gate...
Definition: qinterface.hpp:2696
virtual 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: qinterface.hpp:2772
virtual 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: qinterface.hpp:2652
virtual bool isClifford(bitLenInt qubit)
Returns "true" if current qubit state is identifiably within the Clifford set, or "false" if it is no...
Definition: qinterface.hpp:2843
virtual real1_f VarianceUnitaryAll(const std::vector< bitLenInt > &bits, const std::vector< std::shared_ptr< complex >> &basisOps, std::vector< real1_f > eigenVals={})
Direct measure of variance of listed (2x2 operator) single-qubit tensor product probability.
Definition: qinterface.hpp:2524
virtual real1_f VarianceUnitaryAll(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &basisOps, std::vector< real1_f > eigenVals={})
Direct measure of variance of listed (3-parameter) single-qubit tensor product probability.
Definition: qinterface.hpp:2510
virtual real1_f FirstNonzeroPhase()
Get phase of lowest permutation nonzero amplitude.
Definition: qinterface.hpp:2962
virtual real1_f VarianceFloatsFactorized(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Direct measure of variance of listed bit string probability.
Definition: qinterface.cpp:613
virtual real1_f 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: qinterface.hpp:2575
virtual real1_f ExpectationUnitaryAll(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &basisOps, std::vector< real1_f > eigenVals={})
Get single-qubit (3-parameter) tensor product (arbitrary real) observable.
Definition: qinterface.hpp:2626
virtual real1_f CProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |1>.
Definition: qinterface.hpp:2395
virtual double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qinterface.hpp:2881
virtual void SetSdrp(real1_f sdrp)
Set the "Schmidt decomposition rounding parameter" value, (between 0 and 1)
Definition: qinterface.hpp:2889
virtual bool TrySeparate(bitLenInt qubit1, bitLenInt qubit2)
Two-qubit TrySeparate()
Definition: qinterface.hpp:2871
virtual bool isClifford()
Returns "true" if current state is identifiably within the Clifford set, or "false" if it is not or c...
Definition: qinterface.hpp:2837
virtual real1_f ProbAll(const bitCapInt &fullRegister)
Direct measure of full permutation probability.
Definition: qinterface.hpp:2422
virtual void ProbMaskAll(const bitCapInt &mask, real1 *probsArray)
Direct measure of masked permutation probability.
Definition: qinterface.cpp:416
virtual QInterfacePtr Clone()=0
Clone this QInterface.
virtual bitLenInt DepolarizingChannelStrong1Qb(bitLenInt qubit, real1_f lambda)
Simulate a local qubit depolarizing noise channel, under a "strong simulation condition....
Definition: gates.cpp:512
virtual real1_f ACProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |0>.
Definition: qinterface.hpp:2408
virtual real1_f VariancePauliAll(std::vector< bitLenInt > bits, std::vector< Pauli > paulis)
Direct measure of variance of listed Pauli tensor product probability.
Definition: qinterface.cpp:651
virtual void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qinterface.hpp:2813
virtual bool GetReactiveSeparate()
Get reactive separation option.
Definition: qinterface.hpp:2909
virtual real1_f ExpectationBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Get permutation expectation value of bits.
Definition: qinterface.hpp:2589
virtual real1_f Prob(bitLenInt qubit)=0
Direct measure of bit probability to be in |1> state.
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qinterface.cpp:798
virtual void SetTInjection(bool useGadget)
Set the option to use T-injection gadgets (off by default)
Definition: qinterface.hpp:2917
virtual 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: qinterface.hpp:2549
virtual void ResetUnitaryFidelity()
Reset the internal fidelity calculation tracker to 1.0.
Definition: qinterface.hpp:2885
virtual bool TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Attempt to Decompose() a bit range.
Definition: qinterface.cpp:827
virtual real1_f GetNoiseParameter()
Get the noise level option (only for a noisy interface)
Definition: qinterface.hpp:2937
virtual void ProbBitsAll(const std::vector< bitLenInt > &bits, real1 *probsArray)
Direct measure of listed permutation probability.
Definition: qinterface.cpp:439
virtual real1_f ProbRdm(bitLenInt qubit)
Direct measure of bit probability to be in |1> state, treating all ancillary qubits as post-selected ...
Definition: qinterface.hpp:2690
bitCapIntOcl GetMaxSize()
Get maximum number of amplitudes that can be allocated on current device.
Definition: qinterface.hpp:2957
virtual bool GetTInjection()
Get the option to use T-injection gadgets.
Definition: qinterface.hpp:2925
virtual real1_f ProbMask(const bitCapInt &mask, const bitCapInt &permutation)
Direct measure of masked permutation probability.
Definition: qinterface.cpp:273
virtual real1_f ExpectationPauliAll(std::vector< bitLenInt > bits, std::vector< Pauli > paulis)
Get Pauli tensor product observable.
Definition: qinterface.cpp:707
virtual void SetReactiveSeparate(bool isAggSep)
Set reactive separation option (on by default if available)
Definition: qinterface.hpp:2901
virtual void UpdateRunningNorm(real1_f norm_thresh=REAL1_DEFAULT_ARG)=0
Force a calculation of the norm of the state vector, in order to make it unit length before the next ...
virtual real1_f VarianceBitsAll(const std::vector< bitLenInt > &bits, const bitCapInt &offset=ZERO_BCI)
Direct measure of variance of listed permutation probability.
Definition: qinterface.hpp:2473
virtual real1_f ExpectationBitsFactorized(const std::vector< bitLenInt > &bits, const std::vector< bitCapInt > &perms, const bitCapInt &offset=ZERO_BCI)
Get expectation value of bits, given an array of qubit weights.
Definition: qinterface.cpp:536
virtual real1_f 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: qinterface.hpp:2706
virtual void SetNcrp(real1_f ncrp)
Set the "Near-clifford rounding parameter" value, (between 0 and 1)
Definition: qinterface.hpp:2893
virtual void DepolarizingChannelWeak1Qb(bitLenInt qubit, real1_f lambda)
Simulate a local qubit depolarizing noise channel, under a stochastic "weak simulation condition....
Definition: gates.cpp:490
virtual bool isOpenCL()
Returns "true" if current simulation is OpenCL-based.
Definition: qinterface.hpp:2848
virtual real1_f ExpectationFloatsFactorized(const std::vector< bitLenInt > &bits, const std::vector< real1_f > &weights)
Get expectation value of bits, given a (floating-point) array of qubit weights.
Definition: qinterface.cpp:763
virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt &permutation)
Direct measure of register permutation probability.
Definition: qinterface.cpp:257
virtual int64_t GetDevice()
Get the device index.
Definition: qinterface.hpp:2952
virtual bool TrySeparate(const std::vector< bitLenInt > &qubits, real1_f error_tol)
Qrack::QUnit types maintain explicit separation of representations of qubits, which reduces memory us...
Definition: qinterface.hpp:2863
virtual real1_f SumSqrDiff(QInterfacePtr toCompare)=0
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
virtual void SetBit(bitLenInt qubit, bool value)
Set individual bit to pure |0> (false) or |1> (true) state.
Definition: qinterface.hpp:2759
virtual 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: qinterface.hpp:2718
virtual void NormalizeState(real1_f nrm=REAL1_DEFAULT_ARG, real1_f norm_thresh=REAL1_DEFAULT_ARG, real1_f phaseArg=ZERO_R1_F)=0
Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate.
virtual 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: qinterface.hpp:2678
virtual 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: qinterface.hpp:2486
virtual real1_f ExpectationUnitaryAll(const std::vector< bitLenInt > &bits, const std::vector< std::shared_ptr< complex >> &basisOps, std::vector< real1_f > eigenVals={})
Get single-qubit tensor product (arbitrary real) observable.
Definition: qinterface.hpp:2612
virtual void SetDevice(int64_t dID)=0
Set the device index, if more than one device is available.
virtual bool TrySeparate(bitLenInt qubit)
Single-qubit TrySeparate()
Definition: qinterface.hpp:2867
virtual void SetNoiseParameter(real1_f lambda)
Set the noise level option (only for a noisy interface)
Definition: qinterface.hpp:2931
virtual bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qinterface.hpp:2819
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
bitCapInt bitRegMask(const bitLenInt &start, const bitLenInt &length)
Definition: qrack_functions.hpp:128
QRACK_CONST real1 SQRT1_2_R1
Definition: qrack_types.hpp:172
QInterfaceEngine
Enumerated list of supported engines.
Definition: qinterface.hpp:37
@ QINTERFACE_OPTIMAL_BASE
Definition: qinterface.hpp:121
@ QINTERFACE_QPAGER
Create a QPager, which breaks up the work of a QEngine into equally sized "pages.".
Definition: qinterface.hpp:82
@ QINTERFACE_OPTIMAL_SCHROEDINGER
Definition: qinterface.hpp:119
@ QINTERFACE_OPTIMAL_MULTI
Definition: qinterface.hpp:126
@ QINTERFACE_CUDA
Create a QEngineCUDA, leveraging CUDA hardware to increase the speed of certain calculations.
Definition: qinterface.hpp:52
@ QINTERFACE_STABILIZER_HYBRID
Create a QStabilizerHybrid, switching between a QStabilizer and a QHybrid as efficient.
Definition: qinterface.hpp:77
@ QINTERFACE_HYBRID
Create a QHybrid, switching between QEngineCPU and QEngineOCL as efficient.
Definition: qinterface.hpp:57
@ QINTERFACE_OPTIMAL
Definition: qinterface.hpp:124
@ QINTERFACE_BDT_HYBRID
Create a QBinaryDecisionTree, (CPU-based).
Definition: qinterface.hpp:67
@ QINTERFACE_BDT
Create a QBinaryDecisionTree, (CPU-based).
Definition: qinterface.hpp:62
@ QINTERFACE_TENSOR_NETWORK
Circuit-simplification layer.
Definition: qinterface.hpp:107
@ QINTERFACE_NOISY
Noisy wrapper layer.
Definition: qinterface.hpp:112
@ QINTERFACE_QUNIT_CLIFFORD
Clifford-specialized QUnit.
Definition: qinterface.hpp:102
@ QINTERFACE_OPENCL
Create a QEngineOCL, leveraging OpenCL hardware to increase the speed of certain calculations.
Definition: qinterface.hpp:47
@ QINTERFACE_STABILIZER
Create a QStabilizer, limited to Clifford/Pauli operations, but efficient.
Definition: qinterface.hpp:72
@ QINTERFACE_QUNIT
Create a QUnit, which utilizes other QInterface classes to minimize the amount of work that's needed ...
Definition: qinterface.hpp:91
@ QINTERFACE_QUNIT_MULTI
Create a QUnitMulti, which distributes the explicitly separated "shards" of a QUnit across available ...
Definition: qinterface.hpp:97
@ QINTERFACE_MAX
Definition: qinterface.hpp:128
@ QINTERFACE_CPU
Create a QEngineCPU leveraging only local CPU and memory resources.
Definition: qinterface.hpp:42
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
QRACK_CONST real1 SQRT2_R1
Definition: qrack_types.hpp:171
QRACK_CONST real1_f TRYDECOMPOSE_EPSILON
Definition: qrack_types.hpp:245
QRACK_CONST complex C_SQRT1_2_NEG
Definition: gates.cpp:21
void seed(quid sid, unsigned s)
"Seed" random number generator (if pseudo-random Mersenne twister is in use)
Definition: wasm_api.cpp:811
std::complex< real1 > complex
Definition: qrack_types.hpp:124
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:114
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:101
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:187
QRACK_CONST complex ONE_CMPLX
Definition: qrack_types.hpp:239
QRACK_CONST real1 ONE_R1
Definition: qrack_types.hpp:176
std::vector< HamiltonianOpPtr > Hamiltonian
Definition: hamiltonian.hpp:120
QRACK_CONST real1 ZERO_R1
Definition: qrack_types.hpp:175
float real1_f
Definition: qrack_types.hpp:91
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:242
QRACK_CONST complex I_CMPLX
Definition: qrack_types.hpp:241
QRACK_CONST complex C_SQRT1_2
Definition: gates.cpp:17
QRACK_CONST complex ZERO_CMPLX
Definition: qrack_types.hpp:240
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:170
const bitCapInt ONE_BCI
Definition: qrack_types.hpp:125
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:126
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:115
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
half pow(half x, half y)
Power function.
Definition: half.hpp:3738
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:169
#define QRACK_CONST
Definition: qrack_types.hpp:166
#define bitLenInt
Definition: qrack_types.hpp:38
#define ZERO_R1_F
Definition: qrack_types.hpp:156
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:152
#define bitCapInt
Definition: qrack_types.hpp:62
#define bitCapIntOcl
Definition: qrack_types.hpp:50
#define ONE_R1_F
Definition: qrack_types.hpp:157
#define IS_NORM_0(c)
Definition: qrack_types.hpp:25
#define C_I_SQRT1_2
Definition: qstabilizer.cpp:378