Qrack  9.13
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 
42  inline bool IsPhase(const complex* mtrx) { return IS_NORM_0(mtrx[1]) && IS_NORM_0(mtrx[2]); }
43  inline bool IsInvert(const complex* mtrx) { return IS_NORM_0(mtrx[0]) && IS_NORM_0(mtrx[3]); }
44 
45  bool IsIdentity(const complex* mtrx, bool isControlled)
46  {
47  // If the effect of applying the buffer would be (approximately or exactly) that of applying the identity
48  // operator, then we can discard this buffer without applying it.
49  if (!IS_NORM_0(mtrx[0U] - mtrx[3U]) || !IsPhase(mtrx)) {
50  return false;
51  }
52 
53  // Now, we know that mtrx[1] and mtrx[2] are 0 and mtrx[0]==mtrx[3].
54 
55  // If the global phase offset has been randomized, we assume that global phase offsets are inconsequential, for
56  // the user's purposes. If the global phase offset has not been randomized, user code might explicitly depend on
57  // the global phase offset.
58 
59  if ((isControlled || !randGlobalPhase) && !IS_SAME(ONE_CMPLX, mtrx[0U])) {
60  return false;
61  }
62 
63  // If we haven't returned false by now, we're buffering an identity operator (exactly or up to an arbitrary
64  // global phase factor).
65  return true;
66  }
67 
68  void EitherMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target, bool isAnti);
69 
70  virtual void Copy(QInterfacePtr orig) { Copy(std::dynamic_pointer_cast<QEngine>(orig)); }
71  virtual void Copy(QEnginePtr orig)
72  {
73  QInterface::Copy(orig);
74  useHostRam = orig->useHostRam;
75  runningNorm = orig->runningNorm;
76  maxQPowerOcl = orig->maxQPowerOcl;
77  }
78 
79 public:
80  QEngine(bitLenInt qBitCount, qrack_rand_gen_ptr rgp = nullptr, bool doNorm = false, bool randomGlobalPhase = true,
81  bool useHostMem = false, bool useHardwareRNG = true, real1_f norm_thresh = REAL1_EPSILON)
82  : QInterface(qBitCount, rgp, doNorm, useHardwareRNG, randomGlobalPhase, norm_thresh)
83  , useHostRam(useHostMem)
85  , maxQPowerOcl(pow2Ocl(qBitCount))
86  {
87  if (qBitCount > (sizeof(bitCapIntOcl) * bitsInByte)) {
88  throw std::invalid_argument(
89  "Cannot instantiate a register with greater capacity than native types on emulating system.");
90  }
91  };
92 
95  : useHostRam(false)
97  , maxQPowerOcl(1U)
98  {
99  // Intentionally left blank
100  }
101 
102  virtual ~QEngine()
103  {
104  // Virtual destructor for inheritance
105  }
106 
107  using QInterface::Copy;
108 
109  virtual void SetQubitCount(bitLenInt qb)
110  {
113  }
114 
117  {
118  Finish();
119  return (real1_f)runningNorm;
120  }
121 
123  virtual void SwitchHostPtr(bool useHostMem){};
125  virtual void ResetHostPtr() { SwitchHostPtr(useHostRam); }
127  virtual void SetDevice(int64_t dID) {}
129  virtual int64_t GetDevice() { return -1; }
130 
132  virtual void ZeroAmplitudes() = 0;
134  virtual void CopyStateVec(QEnginePtr src) = 0;
136  virtual bool IsZeroAmplitude() = 0;
138  virtual void GetAmplitudePage(complex* pagePtr, bitCapIntOcl offset, bitCapIntOcl length) = 0;
140  virtual void SetAmplitudePage(const complex* pagePtr, bitCapIntOcl offset, bitCapIntOcl length) = 0;
143  virtual void SetAmplitudePage(
144  QEnginePtr pageEnginePtr, bitCapIntOcl srcOffset, bitCapIntOcl dstOffset, bitCapIntOcl length) = 0;
147  virtual void ShuffleBuffers(QEnginePtr engine) = 0;
149  virtual QEnginePtr CloneEmpty() = 0;
150 
153  virtual void QueueSetDoNormalize(bool doNorm) = 0;
156  virtual void QueueSetRunningNorm(real1_f runningNrm) = 0;
157 
158  virtual void ZMask(const bitCapInt& mask) { PhaseParity((real1_f)PI_R1, mask); }
159 
160  virtual bool ForceM(bitLenInt qubitIndex, bool result, bool doForce = true, bool doApply = true);
161  virtual bitCapInt ForceM(const std::vector<bitLenInt>& bits, const std::vector<bool>& values, bool doApply = true);
162  virtual bitCapInt ForceMReg(
163  bitLenInt start, bitLenInt length, const bitCapInt& result, bool doForce = true, bool doApply = true);
164 
165  virtual void ApplyM(const bitCapInt& qPower, bool result, const complex& nrm)
166  {
167  const bitCapInt powerTest = result ? qPower : ZERO_BCI;
168  ApplyM(qPower, powerTest, nrm);
169  }
170  virtual void ApplyM(const bitCapInt& regMask, const bitCapInt& result, const complex& nrm) = 0;
171 
172  virtual void Mtrx(const complex* mtrx, bitLenInt qubit);
173  virtual void MCMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
174  {
175  EitherMtrx(controls, mtrx, target, false);
176  }
177  virtual void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
178  {
179  EitherMtrx(controls, mtrx, target, true);
180  }
181  virtual void UCMtrx(
182  const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target, const bitCapInt& controlPerm);
183  virtual void CSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
184  virtual void AntiCSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
185  virtual void CSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
186  virtual void AntiCSqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
187  virtual void CISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
188  virtual void AntiCISqrtSwap(const std::vector<bitLenInt>& controls, bitLenInt qubit1, bitLenInt qubit2);
189 
190 #if ENABLE_ALU
191  using QInterface::M;
192  virtual bool M(bitLenInt q) { return QInterface::M(q); }
193  using QInterface::X;
194  virtual void X(bitLenInt q) { QInterface::X(q); }
195  virtual void INC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length)
196  {
197  QInterface::INC(toAdd, start, length);
198  }
199  virtual void DEC(const bitCapInt& toSub, bitLenInt start, bitLenInt length)
200  {
201  QInterface::DEC(toSub, start, length);
202  }
203  virtual void INCC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
204  {
205  QInterface::INCC(toAdd, start, length, carryIndex);
206  }
207  virtual void DECC(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
208  {
209  QInterface::DECC(toSub, start, length, carryIndex);
210  }
211  virtual void INCS(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
212  {
213  QInterface::INCS(toAdd, start, length, overflowIndex);
214  }
215  virtual void DECS(const bitCapInt& toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
216  {
217  QInterface::DECS(toSub, start, length, overflowIndex);
218  }
219  virtual void CINC(
220  const bitCapInt& toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls)
221  {
222  QInterface::CINC(toAdd, inOutStart, length, controls);
223  }
224  virtual void CDEC(
225  const bitCapInt& toSub, bitLenInt inOutStart, bitLenInt length, const std::vector<bitLenInt>& controls)
226  {
227  QInterface::CDEC(toSub, inOutStart, length, controls);
228  }
229  virtual void INCDECC(const bitCapInt& toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
230  {
231  QInterface::INCDECC(toAdd, start, length, carryIndex);
232  }
233  virtual void MULModNOut(
234  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
235  {
236  QInterface::MULModNOut(toMul, modN, inStart, outStart, length);
237  }
238  virtual void IMULModNOut(
239  const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)
240  {
241  QInterface::IMULModNOut(toMul, modN, inStart, outStart, length);
242  }
243  virtual void CMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
244  bitLenInt length, const std::vector<bitLenInt>& controls)
245  {
246  QInterface::CMULModNOut(toMul, modN, inStart, outStart, length, controls);
247  }
248  virtual void CIMULModNOut(const bitCapInt& toMul, const bitCapInt& modN, bitLenInt inStart, bitLenInt outStart,
249  bitLenInt length, const std::vector<bitLenInt>& controls)
250  {
251  QInterface::CIMULModNOut(toMul, modN, inStart, outStart, length, controls);
252  }
253 #endif
254 
255  using QInterface::Swap;
256  virtual void Swap(bitLenInt qubit1, bitLenInt qubit2);
257  using QInterface::ISwap;
258  virtual void ISwap(bitLenInt qubit1, bitLenInt qubit2);
259  using QInterface::IISwap;
260  virtual void IISwap(bitLenInt qubit1, bitLenInt qubit2);
261  using QInterface::SqrtSwap;
262  virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2);
263  using QInterface::ISqrtSwap;
264  virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2);
265  using QInterface::FSim;
266  virtual void FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2);
267 
268  virtual real1_f ProbAll(const bitCapInt& fullRegister)
269  {
270  if (doNormalize) {
271  NormalizeState();
272  }
273 
274  return clampProb((real1_f)norm(GetAmplitude(fullRegister)));
275  }
276  virtual real1_f CtrlOrAntiProb(bool controlState, bitLenInt control, bitLenInt target);
277  virtual real1_f CProb(bitLenInt control, bitLenInt target) { return CtrlOrAntiProb(true, control, target); }
278  virtual real1_f ACProb(bitLenInt control, bitLenInt target) { return CtrlOrAntiProb(false, control, target); }
279  virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt& permutation) = 0;
280  virtual void ProbRegAll(bitLenInt start, bitLenInt length, real1* probsArray);
281  virtual real1_f ProbMask(const bitCapInt& mask, const bitCapInt& permutation) = 0;
282 
283  virtual real1_f GetExpectation(bitLenInt valueStart, bitLenInt valueLength) = 0;
284 
285  virtual void Apply2x2(bitCapIntOcl offset1, bitCapIntOcl offset2, const complex* mtrx, bitLenInt bitCount,
286  bitCapIntOcl const* qPowersSorted, bool doCalcNorm, real1_f norm_thresh = REAL1_DEFAULT_ARG) = 0;
287  virtual void ApplyControlled2x2(const std::vector<bitLenInt>& controls, bitLenInt target, const complex* mtrx);
288  virtual void ApplyAntiControlled2x2(const std::vector<bitLenInt>& controls, bitLenInt target, const complex* mtrx);
289 
290  using QInterface::Decompose;
292  {
293  QEnginePtr dest = CloneEmpty();
294  dest->SetQubitCount(length);
295  Decompose(start, dest);
296 
297  return dest;
298  }
299 
300  virtual std::map<bitCapInt, int> MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots);
301  virtual void MultiShotMeasureMask(
302  const std::vector<bitCapInt>& qPowers, unsigned shots, unsigned long long* shotsArray);
303 };
304 } // 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:109
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:248
virtual void ApplyAntiControlled2x2(const std::vector< bitLenInt > &controls, bitLenInt target, const complex *mtrx)
Definition: qengine.cpp:396
virtual void Copy(QInterfacePtr orig)
Definition: qengine.hpp:70
virtual void CSwap(const std::vector< bitLenInt > &controls, bitLenInt qubit1, bitLenInt qubit2)
Apply a swap with arbitrary control bits.
Definition: qengine.cpp:214
virtual std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qengine.cpp:552
virtual void ApplyControlled2x2(const std::vector< bitLenInt > &controls, bitLenInt target, const complex *mtrx)
Definition: qengine.cpp:380
virtual real1_f ProbReg(bitLenInt start, bitLenInt length, const bitCapInt &permutation)=0
Direct measure of register permutation probability.
virtual void SwitchHostPtr(bool useHostMem)
Switch to/from host/device state vector bufffer.
Definition: qengine.hpp:123
virtual ~QEngine()
Definition: qengine.hpp:102
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:229
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:324
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:225
void EitherMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target, bool isAnti)
Definition: qengine.cpp:29
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qengine.hpp:203
virtual void SetDevice(int64_t dID)
Set GPU device ID.
Definition: qengine.hpp:127
virtual void Mtrx(const complex *mtrx, bitLenInt qubit)
Apply an arbitrary single bit unitary transformation.
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:269
virtual void ApplyM(const bitCapInt &qPower, bool result, const complex &nrm)
Definition: qengine.hpp:165
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:51
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:277
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)
bool IsInvert(const complex *mtrx)
Definition: qengine.hpp:43
virtual void SetAmplitudePage(const complex *pagePtr, bitCapIntOcl offset, bitCapIntOcl length)=0
Copy a "page" of amplitudes from pagePtr into this QEngine's internal state.
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:278
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:353
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:190
virtual void ResetHostPtr()
Reset host/device state vector bufffer usage to default.
Definition: qengine.hpp:125
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:80
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:233
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qengine.hpp:199
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:238
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 void ZMask(const bitCapInt &mask)
Masked Z gate.
Definition: qengine.hpp:158
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qengine.hpp:207
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:243
virtual int64_t GetDevice()
Get GPU device ID.
Definition: qengine.hpp:129
virtual bool IsZeroAmplitude()=0
Returns "true" only if amplitudes are all totally 0.
virtual void Apply2x2(bitCapIntOcl offset1, bitCapIntOcl offset2, const complex *mtrx, bitLenInt bitCount, bitCapIntOcl const *qPowersSorted, bool doCalcNorm, real1_f norm_thresh=REAL1_DEFAULT_ARG)=0
virtual void Copy(QEnginePtr orig)
Definition: qengine.hpp:71
bool IsIdentity(const complex *mtrx, bool isControlled)
Definition: qengine.hpp:45
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.
virtual void SqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Square root of Swap gate.
Definition: gates.cpp:202
virtual QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qengine.hpp:291
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:192
virtual real1_f GetRunningNorm()
Get in-flight renormalization factor.
Definition: qengine.hpp:116
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:215
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:211
virtual real1_f CtrlOrAntiProb(bool controlState, bitLenInt control, bitLenInt target)
Definition: qengine.cpp:471
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: qengine.hpp:177
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: qengine.hpp:219
virtual void ProbRegAll(bitLenInt start, bitLenInt length, real1 *probsArray)
Definition: qengine.cpp:488
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:80
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:167
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:499
virtual void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
Definition: qengine.hpp:173
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...
bool IsPhase(const complex *mtrx)
Definition: qengine.hpp:42
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:194
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:243
virtual void INC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length)
Add integer (without sign)
Definition: qengine.hpp:195
virtual void CDEC(const bitCapInt &toSub, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Subtract integer (without sign, with controls)
Definition: qengine.hpp:224
virtual real1_f GetExpectation(bitLenInt valueStart, bitLenInt valueLength)=0
QEngine()
Default constructor, primarily for protected internal use.
Definition: qengine.hpp:94
virtual real1_f ProbAll(const bitCapInt &fullRegister)
Direct measure of full permutation probability.
Definition: qengine.hpp:268
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:298
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: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:2193
virtual void INCDECC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Common driver method behind INCC and DECC.
Definition: arithmetic.cpp:52
virtual void CINC(const bitCapInt &toAdd, bitLenInt inOutStart, bitLenInt length, const std::vector< bitLenInt > &controls)
Add integer (without sign, with controls)
Definition: arithmetic.cpp:78
virtual void INCS(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)
Add a classical integer to the register, with sign and without carry.
Definition: qinterface.hpp:2182
virtual void DECC(const bitCapInt &toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qinterface.hpp:2156
virtual void DEC(const bitCapInt &toSub, bitLenInt start, bitLenInt length)
Subtract classical integer (without sign)
Definition: qinterface.hpp:2134
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:164
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:2174
virtual void INCC(const bitCapInt &toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qinterface.hpp:2144
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 X(bitLenInt qubit)
X gate.
Definition: qinterface.hpp:1084
virtual void PhaseParity(real1_f radians, const bitCapInt &mask)
Parity phase gate.
Definition: gates.cpp:402
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:1013
virtual void ISqrtSwap(bitLenInt qubit1, bitLenInt qubit2)
Inverse square root of Swap gate.
Definition: gates.cpp:225
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 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 Finish()
If asynchronous work is still running, block until it finishes.
Definition: qinterface.hpp:2831
virtual QInterfacePtr Copy()
Copy this QInterface.
Definition: qinterface.hpp:2965
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:151
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
std::complex< real1 > complex
Definition: qrack_types.hpp:128
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:101
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:200
QRACK_CONST complex ONE_CMPLX
Definition: qrack_types.hpp:252
QRACK_CONST real1 ONE_R1
Definition: qrack_types.hpp:185
float real1_f
Definition: qrack_types.hpp:95
QRACK_CONST real1 PI_R1
Definition: qrack_types.hpp:178
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:130
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:137
#define IS_SAME(c1, c2)
Definition: qrack_types.hpp:26
#define bitsInByte
Definition: qrack_types.hpp:154
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:177
#define bitLenInt
Definition: qrack_types.hpp:38
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:156
#define bitCapInt
Definition: qrack_types.hpp:62
#define bitCapIntOcl
Definition: qrack_types.hpp:50
#define IS_NORM_0(c)
Definition: qrack_types.hpp:25