Qrack  10.0
General classical-emulating-quantum development framework
qengine.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano and the Qrack contributors 2017-2022. 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 "qinterface.hpp"
16 #include "qparity.hpp"
17 
18 #if ENABLE_ALU
19 #include "qalu.hpp"
20 #endif
21 
22 namespace Qrack {
23 
24 class QEngine;
25 typedef std::shared_ptr<QEngine> QEnginePtr;
26 
30 #if ENABLE_ALU
31 class QEngine : public QAlu, public QParity, public QInterface {
32 #else
33 class QEngine : public QParity, public QInterface {
34 #endif
35 protected:
36  bool useHostRam;
41  double fidelity;
42 
43  inline bool IsPhase(const complex mtrx[4U]) { return IS_NORM_0(mtrx[1]) && IS_NORM_0(mtrx[2]); }
44  inline bool IsInvert(const complex mtrx[4U]) { return IS_NORM_0(mtrx[0]) && IS_NORM_0(mtrx[3]); }
45 
46  bool IsIdentity(const complex mtrx[4U], bool isControlled)
47  {
48  // If the effect of applying the buffer would be (approximately or exactly) that of applying the identity
49  // operator, then we can discard this buffer without applying it.
50  if (!IS_NORM_0(mtrx[0U] - mtrx[3U]) || !IsPhase(mtrx)) {
51  return false;
52  }
53 
54  // Now, we know that mtrx[1] and mtrx[2] are 0 and mtrx[0]==mtrx[3].
55 
56  // If the global phase offset has been randomized, we assume that global phase offsets are inconsequential, for
57  // the user's purposes. If the global phase offset has not been randomized, user code might explicitly depend on
58  // the global phase offset.
59 
60  if ((isControlled || !randGlobalPhase) && !IS_SAME(ONE_CMPLX, mtrx[0U])) {
61  return false;
62  }
63 
64  // If we haven't returned false by now, we're buffering an identity operator (exactly or up to an arbitrary
65  // global phase factor).
66  return true;
67  }
68 
69  void EitherMtrx(const std::vector<bitLenInt>& controls, const complex mtrx[4U], bitLenInt target, bool isAnti);
70 
71  virtual void Copy(QInterfacePtr orig) { Copy(std::dynamic_pointer_cast<QEngine>(orig)); }
72  virtual void Copy(QEnginePtr orig)
73  {
74  QInterface::Copy(orig);
75  useHostRam = orig->useHostRam;
76  runningNorm = orig->runningNorm;
77  maxQPowerOcl = orig->maxQPowerOcl;
78  }
79 
80 public:
81  QEngine(bitLenInt qBitCount, qrack_rand_gen_ptr rgp = nullptr, bool doNorm = false, bool randomGlobalPhase = true,
82  bool useHostMem = false, bool useHardwareRNG = true, real1_f norm_thresh = REAL1_EPSILON)
83  : QInterface(qBitCount, rgp, doNorm, useHardwareRNG, randomGlobalPhase, norm_thresh)
84  , useHostRam(useHostMem)
86  , maxQPowerOcl(pow2Ocl(qBitCount))
87  , fidelity(1.0) {};
88 
91  : useHostRam(false)
93  , maxQPowerOcl(1U)
94  {
95  // Intentionally left blank
96  }
97 
98  virtual ~QEngine()
99  {
100  // Virtual destructor for inheritance
101  }
102 
103  using QInterface::Copy;
104 
105  virtual void SetQubitCount(bitLenInt qb)
106  {
109  }
110 
113  {
114  Finish();
115  return (real1_f)runningNorm;
116  }
117 
119  virtual void SwitchHostPtr(bool useHostMem) {};
121  virtual void ResetHostPtr() { SwitchHostPtr(useHostRam); }
123  virtual void SetDevice(int64_t dID) {}
125  virtual int64_t GetDevice() { return -1; }
126 
128  virtual void ZeroAmplitudes() = 0;
130  virtual void CopyStateVec(QEnginePtr src) = 0;
132  virtual bool IsZeroAmplitude() = 0;
134  virtual void GetAmplitudePage(complex* pagePtr, bitCapIntOcl offset, bitCapIntOcl length) = 0;
136  virtual void SetAmplitudePage(const complex* pagePtr, bitCapIntOcl offset, bitCapIntOcl length) = 0;
139  virtual void SetAmplitudePage(
140  QEnginePtr pageEnginePtr, bitCapIntOcl srcOffset, bitCapIntOcl dstOffset, bitCapIntOcl length) = 0;
143  virtual void ShuffleBuffers(QEnginePtr engine) = 0;
145  virtual QEnginePtr CloneEmpty() = 0;
146 
149  virtual void QueueSetDoNormalize(bool doNorm) = 0;
152  virtual void QueueSetRunningNorm(real1_f runningNrm) = 0;
153 
154  virtual void ZMask(const bitCapInt& mask) { PhaseParity((real1_f)PI_R1, mask); }
155 
156  virtual bool ForceM(bitLenInt qubitIndex, bool result, bool doForce = true, bool doApply = true);
157  virtual bitCapInt ForceM(const std::vector<bitLenInt>& bits, const std::vector<bool>& values, bool doApply = true);
158  virtual bitCapInt ForceMReg(
159  bitLenInt start, bitLenInt length, const bitCapInt& result, bool doForce = true, bool doApply = true);
160 
161  virtual void ApplyM(const bitCapInt& qPower, bool result, const complex& nrm)
162  {
163  const bitCapInt powerTest = result ? qPower : ZERO_BCI;
164  ApplyM(qPower, powerTest, nrm);
165  }
166  virtual void ApplyM(const bitCapInt& regMask, const bitCapInt& result, const complex& nrm) = 0;
167 
168  virtual void Mtrx(const complex* mtrx, bitLenInt qubit);
169  virtual void MCMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
170  {
171  EitherMtrx(controls, mtrx, target, false);
172  }
173  virtual void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
174  {
175  EitherMtrx(controls, mtrx, target, true);
176  }
177  virtual void UCMtrx(
178  const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target, const bitCapInt& controlPerm);
179  virtual void CSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
180  virtual void AntiCSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
181  virtual void CSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
182  virtual void AntiCSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
183  virtual void CISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
184  virtual void AntiCISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
185 
186 #if ENABLE_ALU
187  using QInterface::M;
188  virtual bool M(bitLenInt q) { return QInterface::M(q); }
189  using QInterface::X;
190  virtual void X(bitLenInt q) { QInterface::X(q); }
191  virtual void INC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length)
192  {
193  QInterface::INC(toAdd, start, length);
194  }
195  virtual void DEC(const bitCapInt& toSub, bitLenInt start, bitLenInt length)
196  {
197  QInterface::DEC(toSub, start, length);
198  }
199  virtual void INCC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
200  {
201  QInterface::INCC(toAdd, start, length, carryIndex);
202  }
203  virtual void DECC(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
204  {
205  QInterface::DECC(toSub, start, length, carryIndex);
206  }
207  virtual void INCS(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
208  {
209  QInterface::INCS(toAdd, start, length, overflowIndex);
210  }
211  virtual void DECS(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
212  {
213  QInterface::DECS(toSub, start, length, overflowIndex);
214  }
215  virtual void CINC(
216  const bitCapInt& toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls)
217  {
218  QInterface::CINC(toAdd, inOutStart, length, controls);
219  }
220  virtual void CDEC(
221  const bitCapInt& toSub, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls)
222  {
223  QInterface::CDEC(toSub, inOutStart, length, controls);
224  }
225  virtual void INCDECC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
226  {
227  QInterface::INCDECC(toAdd, start, length, carryIndex);
228  }
229  virtual void MULModNOut(
230  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
231  {
232  QInterface::MULModNOut(toMul, modN, inStart, outStart, length);
233  }
234  virtual void IMULModNOut(
235  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
236  {
237  QInterface::IMULModNOut(toMul, modN, inStart, outStart, length);
238  }
239  virtual void CMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
240  bitLenInt length, const std::vector<bitLenInt>& controls)
241  {
242  QInterface::CMULModNOut(toMul, modN, inStart, outStart, length, controls);
243  }
244  virtual void CIMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
245  bitLenInt length, const std::vector<bitLenInt>& controls)
246  {
247  QInterface::CIMULModNOut(toMul, modN, inStart, outStart, length, controls);
248  }
249 #endif
250 
251  using QInterface::Swap;
252  virtual void Swap(bitLenInt qubit1, bitLenInt qubit2);
253  using QInterface::ISwap;
254  virtual void ISwap(bitLenInt qubit1, bitLenInt qubit2);
255  using QInterface::IISwap;
256  virtual void IISwap(bitLenInt qubit1, bitLenInt qubit2);
257  using QInterface::SqrtSwap;
258  virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2);
259  using QInterface::ISqrtSwap;
260  virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2);
261  using QInterface::FSim;
262  virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2);
263 
264  virtual real1_f ProbAll(const bitCapInt& fullRegister)
265  {
266  if (doNormalize) {
267  NormalizeState();
268  }
269 
270  return clampProb((real1_f)norm(GetAmplitude(fullRegister)));
271  }
272  virtual real1_f CtrlOrAntiProb(bool controlState, bitLenInt control, bitLenInt target);
273  virtual real1_f CProb(bitLenInt control, bitLenInt target) { return CtrlOrAntiProb(true, control, target); }
274  virtual real1_f ACProb(bitLenInt control, bitLenInt target) { return CtrlOrAntiProb(false, control, target); }
275  virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt& permutation) = 0;
276  virtual void ProbRegAll(bitLenInt start, bitLenInt length, real1* probsArray);
277  virtual real1_f ProbMask(const bitCapInt& mask, const bitCapInt& permutation) = 0;
278 
279  virtual real1_f GetExpectation(bitLenInt valueStart, bitLenInt valueLength) = 0;
280 
281  virtual void Apply2x2(bitCapInt offset1, bitCapInt offset2, const complex* mtrx, bitLenInt bitCount,
282  bitCapInt const* qPowersSorted, bool doCalcNorm, real1_f norm_thresh = REAL1_DEFAULT_ARG) = 0;
283  virtual void ApplyControlled2x2(const std::vector<bitLenInt>& controls, bitLenInt target, const complex* mtrx);
284  virtual void ApplyAntiControlled2x2(const std::vector<bitLenInt>& controls, bitLenInt target, const complex* mtrx);
285 
286  using QInterface::Decompose;
288  {
289  QEnginePtr dest = CloneEmpty();
290  dest->SetQubitCount(length);
291  Decompose(start, dest);
292  return dest;
293  }
294 
295  virtual std::map<bitCapInt, int> MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots);
296  virtual void MultiShotMeasureMask(
297  const std::vector<bitCapInt>& qPowers, unsigned shots, unsigned long long* shotsArray);
298 };
299 } // namespace Qrack
Definition: qalu.hpp:22
Abstract QEngine implementation, for all "Schroedinger method" engines.
Definition: qengine.hpp:31
virtual void SetQubitCount(bitLenInt qb)
Definition: qengine.hpp:105
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: qengine.hpp:244
double fidelity
Definition: qengine.hpp:41
virtual void ApplyAntiControlled2x2(const std::vector< bitLenInt > &controls, bitLenInt target, const complex *mtrx)
Definition: qengine.cpp:387
virtual void Copy(QInterfacePtr orig)
Definition: qengine.hpp:71
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qengine.cpp:212
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qengine.cpp:542
virtual void ApplyControlled2x2(const std::vector< bitLenInt > &controls, bitLenInt target, const complex *mtrx)
Definition: qengine.cpp:371
virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt &permutation)=0
Direct measure of register permutation probability.
bool IsInvert(const complex mtrx[4U])
Definition: qengine.hpp:44
virtual void SwitchHostPtr(bool useHostMem)
Switch to/from host/device state vector bufffer.
Definition: qengine.hpp:119
virtual ~QEngine()
Definition: qengine.hpp:98
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC (without sign, with carry)
Definition: qengine.hpp:225
virtual void CISqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply an inverse square root of swap with arbitrary control bits.
Definition: qengine.cpp:317
virtual void ApplyM(const bitCapInt &regMask, const bitCapInt &result, const complex &nrm)=0
virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse square root of Swap gate.
Definition: gates.cpp:224
virtual void Apply2x2(bitCapInt offset1, bitCapInt offset2, const complex *mtrx, bitLenInt bitCount, bitCapInt const *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)=0
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qengine.hpp:199
virtual void SetDevice(int64_t dID)
Set GPU device ID.
Definition: qengine.hpp:123
virtual void Mtrx(const complex *mtrx, bitLenInt qubit)
Definition: qengine.cpp:19
virtual void CSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary control bits.
Definition: qengine.cpp:265
virtual void ApplyM(const bitCapInt &qPower, bool result, const complex &nrm)
Definition: qengine.hpp:161
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: qengine.cpp:50
real1 runningNorm
The value stored in runningNorm should always be the total probability implied by the norm of all amp...
Definition: qengine.hpp:39
virtual real1_f CProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |1>.
Definition: qengine.hpp:273
virtual void SetAmplitudePage(const complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from pagePtr into this QEngine's internal state.
void EitherMtrx(const std::vector< bitLenInt > &controls, const complex mtrx[4U], bitLenInt target, bool isAnti)
Definition: qengine.cpp:29
virtual real1_f ACProb(bitLenInt control, bitLenInt target)
Direct measure of bit probability to be in |1> state, if control bit is |0>.
Definition: qengine.hpp:274
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: qengine.cpp:345
bitCapIntOcl maxQPowerOcl
Definition: qengine.hpp:40
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual real1_f ProbMask(const bitCapInt &mask, const bitCapInt &permutation)=0
Direct measure of masked permutation probability.
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:189
virtual void ResetHostPtr()
Reset host/device state vector bufffer usage to default.
Definition: qengine.hpp:121
virtual bool ForceM(bitLenInt qubitIndex, bool result, bool doForce=true, bool doApply=true)
PSEUDO-QUANTUM - Acts like a measurement gate, except with a specified forced result.
Definition: qengine.cpp:78
virtual void MULModNOut(const bitCapInt &toMul, const bitCapInt &modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
Multiplication modulo N by integer, (out of place)
Definition: qengine.hpp:229
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qengine.hpp:195
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: qengine.hpp:234
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:177
virtual void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: qengine.hpp:154
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qengine.hpp:203
bool useHostRam
Definition: qengine.hpp:36
virtual void CopyStateVec(QEnginePtr src)=0
Exactly copy the state vector of a different QEngine instance.
virtual void AntiCSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary (anti) control bits.
Definition: qengine.cpp:240
virtual int64_t GetDevice()
Get GPU device ID.
Definition: qengine.hpp:125
virtual bool IsZeroAmplitude()=0
Returns "true" only if amplitudes are all totally 0.
virtual void Copy(QEnginePtr orig)
Definition: qengine.hpp:72
bool IsIdentity(const complex mtrx[4U], bool isControlled)
Definition: qengine.hpp:46
virtual QEnginePtr CloneEmpty()=0
Clone this QEngine's settings, with a zeroed state vector.
virtual void ZeroAmplitudes()=0
Set all amplitudes to 0, and optionally temporarily deallocate state vector RAM.
bool IsPhase(const complex mtrx[4U])
Definition: qengine.hpp:43
virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Square root of Swap gate.
Definition: gates.cpp:201
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qengine.hpp:287
virtual void QueueSetDoNormalize(bool doNorm)=0
Add an operation to the (OpenCL) queue, to set the value of doNormalize, which controls whether to au...
virtual bool M(bitLenInt q)
Definition: qengine.hpp:188
virtual real1_f GetRunningNorm()
Get in-flight renormalization factor.
Definition: qengine.hpp:112
virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
Definition: qinterface.hpp:2414
virtual void SetAmplitudePage(QEnginePtr pageEnginePtr, bitCapIntOcl srcOffset, bitCapIntOcl dstOffset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from another QEngine, pointed to by pageEnginePtr, into this QEngine's in...
virtual void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qengine.hpp:211
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: qengine.hpp:207
virtual real1_f CtrlOrAntiProb(bool controlState, bitLenInt control, bitLenInt target)
Definition: qengine.cpp:462
virtual void MACMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Definition: qengine.hpp:173
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qengine.hpp:215
virtual void ProbRegAll(bitLenInt start, bitLenInt length, real1 *probsArray)
Definition: qengine.cpp:478
QEngine(bitLenInt qBitCount, qrack_rand_gen_ptr rgp=nullptr, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, bool useHardwareRNG=true, real1_f norm_thresh=REAL1_EPSILON)
Definition: qengine.hpp:81
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:166
virtual void GetAmplitudePage(complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from this QEngine's internal state, into pagePtr.
virtual bitCapInt ForceMReg(bitLenInt start, bitLenInt length, const bitCapInt &result, bool doForce=true, bool doApply=true)
Measure permutation state of a register.
Definition: qengine.cpp:489
virtual void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Definition: qengine.hpp:169
virtual void QueueSetRunningNorm(real1_f runningNrm)=0
Add an operation to the (OpenCL) queue, to set the value of runningNorm, which is the normalization c...
virtual void ShuffleBuffers(QEnginePtr engine)=0
Swap the high half of this engine with the low half of another.
virtual void X(bitLenInt q)
Definition: qengine.hpp:190
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: qengine.hpp:239
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qengine.hpp:191
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract integer (without sign, with controls)
Definition: qengine.hpp:220
virtual real1_f GetExpectation(bitLenInt valueStart, bitLenInt valueLength)=0
QEngine()
Default constructor, primarily for protected internal use.
Definition: qengine.hpp:90
virtual real1_f ProbAll(const bitCapInt &fullRegister)
Direct measure of full permutation probability.
Definition: qengine.hpp:264
virtual void AntiCSqrtSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a square root of swap with arbitrary (anti) control bits.
Definition: qengine.cpp:292
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:141
bitCapInt maxQPower
Definition: qinterface.hpp:149
bool randGlobalPhase
Definition: qinterface.hpp:144
virtual void Decompose(bitLenInt start, QInterfacePtr dest)=0
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:268
static real1_f clampProb(real1_f toClamp)
Definition: qinterface.hpp:158
bool doNormalize
Definition: qinterface.hpp:143
virtual complex GetAmplitude(const bitCapInt &perm)=0
Get the representational amplitude of a full permutation.
Definition: qparity.hpp:22
Half-precision floating-point type.
Definition: half.hpp:2206
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:127
virtual void DECS(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Subtract a classical integer from the register, with sign and without carry.
Definition: qinterface.hpp:2225
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC.
Definition: arithmetic.cpp:53
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: arithmetic.cpp:79
virtual void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qinterface.hpp:2214
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qinterface.hpp:2188
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2166
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: arithmetic.cpp:20
virtual void 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:165
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:2206
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qinterface.hpp:2176
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:201
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:240
virtual void X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1116
virtual void PhaseParity(real1_f radians, const bitCapInt &mask)
Parity phase gate.
Definition: gates.cpp:399
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual bool M(bitLenInt qubit)
Measurement gate.
Definition: qinterface.hpp:1031
virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse square root of Swap gate.
Definition: gates.cpp:224
virtual void 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:189
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:177
virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Square root of Swap gate.
Definition: gates.cpp:201
virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubit1, bitLenInt qubit2)
The 2-qubit "fSim" gate, (useful in the simulation of particles with fermionic statistics)
Definition: qinterface.hpp:2414
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:166
virtual void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qinterface.hpp:2875
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qinterface.hpp:3058
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.
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
std::shared_ptr< QEngine > QEnginePtr
Definition: qrack_types.hpp:153
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
std::complex< real1 > complex
Definition: qrack_types.hpp:140
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:122
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:203
QRACK_CONST complex ONE_CMPLX
Definition: qrack_types.hpp:257
QRACK_CONST real1 ONE_R1
Definition: qrack_types.hpp:188
float real1_f
Definition: qrack_types.hpp:107
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:180
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:142
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:157
#define IS_SAME(c1, c2)
Definition: qrack_types.hpp:29
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:179
#define bitLenInt
Definition: qrack_types.hpp:41
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:158
#define bitCapInt
Definition: qrack_types.hpp:65
#define bitCapIntOcl
Definition: qrack_types.hpp:53
#define IS_NORM_0(c)
Definition: qrack_types.hpp:28