Qrack  10.0
General classical-emulating-quantum development framework
qtensornetwork.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano and the Qrack contributors 2017-2023. All rights reserved.
4 //
5 // QTensorNetwork is a gate-based QInterface descendant wrapping cuQuantum.
6 //
7 // Licensed under the GNU Lesser General Public License V3.
8 // See LICENSE.md in the project root or https://www.gnu.org/licenses/lgpl-3.0.en.html
9 // for details.
10 
11 #pragma once
12 
13 #include "qcircuit.hpp"
14 
15 namespace Qrack {
16 
17 class QTensorNetwork;
18 typedef std::shared_ptr<QTensorNetwork> QTensorNetworkPtr;
19 
20 // #if ENABLE_CUDA
21 // struct TensorMeta {
22 // std::vector<std::vector<int32_t>> modes;
23 // std::vector<std::vector<int64_t>> extents;
24 // };
25 // typedef std::vector<TensorMeta> TensorNetworkMeta;
26 // typedef std::shared_ptr<TensorNetworkMeta> TensorNetworkMetaPtr;
27 // #endif
28 
29 class QTensorNetwork : public QInterface {
30 protected:
31  bool useHostRam;
32  bool isSparse;
34  bool useTGadget;
36 #if ENABLE_OPENCL || ENABLE_CUDA
37  bool isCpu;
38 #endif
39 #if ENABLE_QBDT
40  bool isQBdt;
41 #endif
42  int64_t devID;
43  size_t aceMb;
49  std::vector<int64_t> deviceIDs;
50  std::vector<QInterfaceEngine> engines;
52 
54  {
55  if (target >= qubitCount) {
56  throw std::invalid_argument("QTensorNetwork qubit index values must be within allocated qubit bounds!");
57  }
58  }
59 
60  void CheckQubitCount(bitLenInt target, const std::vector<bitLenInt>& controls)
61  {
62  CheckQubitCount(target);
64  controls, qubitCount, "QTensorNetwork qubit index values must be within allocated qubit bounds!");
65  }
66 
68 
69  void MakeLayerStack();
70 
71  template <typename Fn> void RunAsAmplitudes(Fn fn, std::set<bitLenInt> qubits = std::set<bitLenInt>())
72  {
73  if (qubits.size()) {
74  circuit->RemovePastLightCone(qubits)->Run(layerStack);
75  } else {
76  circuit->Run(layerStack);
77  circuit = std::make_shared<QCircuit>(true, isNearClifford);
78  }
79 
80  return fn(layerStack);
81  }
82 
83 public:
84  QTensorNetwork(std::vector<QInterfaceEngine> eng, bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI,
85  qrack_rand_gen_ptr rgp = nullptr, const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false,
86  bool randomGlobalPhase = true, bool useHostMem = false, int64_t deviceId = -1, bool useHardwareRNG = true,
87  bool useSparseStateVec = false, real1_f norm_thresh = REAL1_EPSILON, std::vector<int64_t> ignored = {},
88  bitLenInt qubitThreshold = 0, real1_f separation_thresh = _qrack_qunit_sep_thresh);
89 
90  QTensorNetwork(bitLenInt qBitCount, const bitCapInt& initState = ZERO_BCI, qrack_rand_gen_ptr rgp = nullptr,
91  const complex& phaseFac = CMPLX_DEFAULT_ARG, bool doNorm = false, bool randomGlobalPhase = true,
92  bool useHostMem = false, int64_t deviceId = -1, bool useHardwareRNG = true, bool useSparseStateVec = false,
93  real1_f norm_thresh = REAL1_EPSILON, std::vector<int64_t> devList = {}, bitLenInt qubitThreshold = 0U,
94  real1_f separation_thresh = _qrack_qunit_sep_thresh)
95  : QTensorNetwork({}, qBitCount, initState, rgp, phaseFac, doNorm, randomGlobalPhase, useHostMem, deviceId,
96  useHardwareRNG, useSparseStateVec, norm_thresh, devList, qubitThreshold, separation_thresh)
97  {
98  }
99 
100  void SetSdrp(real1_f sdrp)
101  {
102  separabilityThreshold = sdrp;
104  layerStack->SetSdrp(sdrp);
105  }
106 
107  void SetReactiveSeparate(bool isAggSep) { isReactiveSeparate = isAggSep; }
108 
109  void SetTInjection(bool useGadget)
110  {
111  useTGadget = useGadget;
112  layerStack->SetTInjection(useTGadget);
113  }
114 
115  void SetNcrp(real1_f rp)
116  {
117  ncrp = rp;
118  layerStack->SetNcrp(ncrp);
119  }
120 
122  {
123  aceQubits = qb;
124  layerStack->SetAceMaxQubits(aceQubits);
125  }
126 
127  void SetSparseAceMaxMb(size_t mb)
128  {
129  aceMb = mb;
130  layerStack->SetSparseAceMaxMb(aceMb);
131  }
132 
134  {
135  double toRet;
136  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->GetUnitaryFidelity(); });
137  return toRet;
138  }
139 
141  {
142  bitCapInt toRet;
143  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->HighestProbAll(); });
144  return toRet;
145  }
146 
147  void SetDevice(int64_t dID) { devID = dID; }
148  void SetDeviceList(std::vector<int64_t> dIDs) { deviceIDs = dIDs; }
149  int64_t GetDevice() { return devID; }
150  std::vector<int64_t> GetDeviceList() { return deviceIDs; }
151 
152  void Finish() { layerStack->Finish(); };
153 
154  bool isFinished() { return layerStack->isFinished(); }
155 
156  void Dump() { layerStack->Dump(); }
157 
158  void UpdateRunningNorm(real1_f norm_thresh = REAL1_DEFAULT_ARG) { layerStack->UpdateRunningNorm(norm_thresh); }
159 
161  real1_f nrm = REAL1_DEFAULT_ARG, real1_f norm_thresh = REAL1_DEFAULT_ARG, real1_f phaseArg = ZERO_R1_F)
162  {
163  layerStack->NormalizeState(nrm, norm_thresh, phaseArg);
164  }
165 
167  {
168  return SumSqrDiff(std::dynamic_pointer_cast<QTensorNetwork>(toCompare));
169  }
171  {
172  real1_f toRet;
173  toCompare->RunAsAmplitudes([&](QInterfacePtr ls) {});
174  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->SumSqrDiff(toCompare->layerStack); });
175  return toRet;
176  }
177 
178  void SetPermutation(const bitCapInt& initState, const complex& phaseFac = CMPLX_DEFAULT_ARG)
179  {
180  circuit = std::make_shared<QCircuit>(true, isNearClifford);
181  MakeLayerStack();
182  layerStack->SetPermutation(initState, phaseFac);
183  }
184 
186 
188  {
189  RunAsAmplitudes([&](QInterfacePtr ls) { ls->GetQuantumState(state); });
190  }
191  void SetQuantumState(const complex* state)
192  {
193  RunAsAmplitudes([&](QInterfacePtr ls) { ls->SetQuantumState(state); });
194  }
196  {
197  const QTensorNetworkPtr tnEng = std::dynamic_pointer_cast<QTensorNetwork>(eng);
198 
199  if (tnEng->qubitCount != qubitCount) {
200  throw std::invalid_argument("QTensorNetwork::SetQuantumState() argument must match in qubit count!");
201  }
202 
203  layerStack = tnEng->layerStack->Clone();
204  circuit = tnEng->circuit->Clone();
205  }
206  void GetProbs(real1* outputProbs)
207  {
208  RunAsAmplitudes([&](QInterfacePtr ls) { ls->GetProbs(outputProbs); });
209  }
210 
212  {
213  complex toRet;
214  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->GetAmplitude(perm); });
215  return toRet;
216  }
217  void SetAmplitude(const bitCapInt& perm, const complex& amp)
218  {
219  RunAsAmplitudes([&](QInterfacePtr ls) { ls->SetAmplitude(perm, amp); });
220  }
221 
222  using QInterface::Compose;
224  {
225  bitLenInt toRet;
226  std::dynamic_pointer_cast<QTensorNetwork>(toCopy)->RunAsAmplitudes([&](QInterfacePtr ls) {});
228  toRet = ls->Compose(std::dynamic_pointer_cast<QTensorNetwork>(toCopy)->layerStack, start);
229  });
230  SetQubitCount(qubitCount + toCopy->GetQubitCount());
231  return toRet;
232  }
234  {
235  dest->SetPermutation(0U);
237  ls->Decompose(start, std::dynamic_pointer_cast<QTensorNetwork>(dest)->layerStack);
238  });
239  SetQubitCount(qubitCount - dest->GetQubitCount());
240  }
242  {
243  QInterfacePtr toRet;
244  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->Decompose(start, length); });
245  SetQubitCount(qubitCount - toRet->GetQubitCount());
246  return toRet;
247  }
248  void Dispose(bitLenInt start, bitLenInt length)
249  {
250  RunAsAmplitudes([&](QInterfacePtr ls) { ls->Dispose(start, length); });
251  SetQubitCount(qubitCount - length);
252  }
253  void Dispose(bitLenInt start, bitLenInt length, const bitCapInt& disposedPerm)
254  {
255  RunAsAmplitudes([&](QInterfacePtr ls) { ls->Dispose(start, length, disposedPerm); });
256  SetQubitCount(qubitCount - length);
257  }
259  {
260  bool toRet;
261  dest->SetPermutation(0U);
263  toRet = ls->TryDecompose(start, std::dynamic_pointer_cast<QTensorNetwork>(dest)->layerStack, error_tol);
264  });
265  SetQubitCount(qubitCount - dest->GetQubitCount());
266  return toRet;
267  }
268  bool TrySeparate(const std::vector<bitLenInt>& qubits, real1_f error_tol)
269  {
270  return layerStack->TrySeparate(qubits, error_tol);
271  }
272  bool TrySeparate(bitLenInt qubit) { return layerStack->TrySeparate(qubit); }
273  bool TrySeparate(bitLenInt qubit1, bitLenInt qubit2) { return layerStack->TrySeparate(qubit1, qubit2); }
274 
275  using QInterface::Allocate;
277  {
278  if (start > qubitCount) {
279  throw std::invalid_argument("QTensorNetwork::Allocate() 'start' argument is out-of-bounds!");
280  }
281 
282  if (!length) {
283  return start;
284  }
285 
286  layerStack->Allocate(length);
287  const bitLenInt movedQubits = qubitCount - start;
288  SetQubitCount(qubitCount + length);
289 
290  for (bitLenInt i = 0U; i < movedQubits; ++i) {
291  const bitLenInt q = start + movedQubits - (i + 1U);
292  Swap(q, q + length);
293  }
294 
295  return start;
296  }
297 
299  {
300  real1_f toRet;
301  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->Prob(qubit); }, { qubit });
302  return toRet;
303  }
304  real1_f ProbAll(const bitCapInt& fullRegister)
305  {
306  real1_f toRet;
307  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->ProbAll(fullRegister); });
308  return toRet;
309  }
310 
311  bool ForceM(bitLenInt qubit, bool result, bool doForce = true, bool doApply = true)
312  {
313  bool toRet;
314  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->ForceM(qubit, result, doForce, doApply); }, { qubit });
315  return toRet;
316  }
317 
318  std::map<bitCapInt, int> MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots)
319  {
320  std::map<bitCapInt, int> toRet;
321  std::set<bitLenInt> qubits;
322  for (const bitCapInt& qPow : qPowers) {
323  qubits.insert(log2(qPow));
324  }
325  RunAsAmplitudes([&](QInterfacePtr ls) { toRet = ls->MultiShotMeasureMask(qPowers, shots); }, qubits);
326  return toRet;
327  }
328  void MultiShotMeasureMask(const std::vector<bitCapInt>& qPowers, unsigned shots, unsigned long long* shotsArray)
329  {
330  std::map<bitCapInt, int> toRet;
331  std::set<bitLenInt> qubits;
332  for (const bitCapInt& qPow : qPowers) {
333  qubits.insert(log2(qPow));
334  }
335  RunAsAmplitudes([&](QInterfacePtr ls) { ls->MultiShotMeasureMask(qPowers, shots, shotsArray); }, qubits);
336  }
337 
338  void Mtrx(const complex* mtrx, bitLenInt target)
339  {
340  CheckQubitCount(target);
341  circuit->AppendGate(std::make_shared<QCircuitGate>(target, mtrx));
342  }
343  void MCMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
344  {
345  CheckQubitCount(target, controls);
346  bitCapInt m = pow2(controls.size());
347  bi_decrement(&m, 1U);
348  circuit->AppendGate(
349  std::make_shared<QCircuitGate>(target, mtrx, std::set<bitLenInt>{ controls.begin(), controls.end() }, m));
350  }
351  void MACMtrx(const std::vector<bitLenInt>& controls, const complex* mtrx, bitLenInt target)
352  {
353  CheckQubitCount(target, controls);
354  circuit->AppendGate(std::make_shared<QCircuitGate>(
355  target, mtrx, std::set<bitLenInt>{ controls.begin(), controls.end() }, ZERO_BCI));
356  }
357  void MCPhase(
358  const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight, bitLenInt target)
359  {
360  CheckQubitCount(target, controls);
361  std::shared_ptr<complex> lMtrx(new complex[4U], std::default_delete<complex[]>());
362  lMtrx.get()[0U] = topLeft;
363  lMtrx.get()[1U] = ZERO_CMPLX;
364  lMtrx.get()[2U] = ZERO_CMPLX;
365  lMtrx.get()[3U] = bottomRight;
366  bitCapInt m = pow2(controls.size());
367  bi_decrement(&m, 1U);
368  circuit->AppendGate(std::make_shared<QCircuitGate>(
369  target, lMtrx.get(), std::set<bitLenInt>{ controls.begin(), controls.end() }, m));
370  }
371  void MACPhase(
372  const std::vector<bitLenInt>& controls, const complex& topLeft, const complex& bottomRight, bitLenInt target)
373  {
374  CheckQubitCount(target, controls);
375  std::shared_ptr<complex> lMtrx(new complex[4U], std::default_delete<complex[]>());
376  lMtrx.get()[0U] = topLeft;
377  lMtrx.get()[1U] = ZERO_CMPLX;
378  lMtrx.get()[2U] = ZERO_CMPLX;
379  lMtrx.get()[3U] = bottomRight;
380  circuit->AppendGate(std::make_shared<QCircuitGate>(
381  target, lMtrx.get(), std::set<bitLenInt>{ controls.begin(), controls.end() }, ZERO_BCI));
382  }
383  void MCInvert(
384  const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft, bitLenInt target)
385  {
386  CheckQubitCount(target, controls);
387  std::shared_ptr<complex> lMtrx(new complex[4U], std::default_delete<complex[]>());
388  lMtrx.get()[0U] = ZERO_CMPLX;
389  lMtrx.get()[1U] = topRight;
390  lMtrx.get()[2U] = bottomLeft;
391  lMtrx.get()[3U] = ZERO_CMPLX;
392  bitCapInt m = pow2(controls.size());
393  bi_decrement(&m, 1U);
394  circuit->AppendGate(std::make_shared<QCircuitGate>(
395  target, lMtrx.get(), std::set<bitLenInt>{ controls.begin(), controls.end() }, m));
396  }
397  void MACInvert(
398  const std::vector<bitLenInt>& controls, const complex& topRight, const complex& bottomLeft, bitLenInt target)
399  {
400  CheckQubitCount(target, controls);
401  std::shared_ptr<complex> lMtrx(new complex[4U], std::default_delete<complex[]>());
402  lMtrx.get()[0U] = ZERO_CMPLX;
403  lMtrx.get()[1U] = topRight;
404  lMtrx.get()[2U] = bottomLeft;
405  lMtrx.get()[3U] = ZERO_CMPLX;
406  circuit->AppendGate(std::make_shared<QCircuitGate>(
407  target, lMtrx.get(), std::set<bitLenInt>{ controls.begin(), controls.end() }, ZERO_BCI));
408  }
409 };
410 } // namespace Qrack
void bi_decrement(BigInteger *pBigInt, const BIG_INTEGER_WORD &value)
Definition: big_integer.hpp:237
A "Qrack::QInterface" is an abstract interface exposing qubit permutation state vector with methods t...
Definition: qinterface.hpp:141
virtual bitLenInt Allocate(bitLenInt length)
Allocate new "length" count of |0> state qubits at end of qubit index position.
Definition: qinterface.hpp:477
virtual bitLenInt Compose(QInterfacePtr toCopy)
Combine another QInterface with this one, after the last bit index of this one.
Definition: qinterface.hpp:371
virtual void SetQubitCount(bitLenInt qb)
Definition: qinterface.hpp:268
bitLenInt qubitCount
Definition: qinterface.hpp:146
Definition: qtensornetwork.hpp:29
void GetProbs(real1 *outputProbs)
Get the pure quantum state representation.
Definition: qtensornetwork.hpp:206
bitLenInt GetThresholdQb()
Definition: qtensornetwork.cpp:115
QTensorNetwork(bitLenInt qBitCount, const bitCapInt &initState=ZERO_BCI, qrack_rand_gen_ptr rgp=nullptr, const complex &phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t deviceId=-1, bool useHardwareRNG=true, bool useSparseStateVec=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > devList={}, bitLenInt qubitThreshold=0U, real1_f separation_thresh=_qrack_qunit_sep_thresh)
Definition: qtensornetwork.hpp:90
bool useTGadget
Definition: qtensornetwork.hpp:34
void SetQuantumState(const complex *state)
Set an arbitrary pure quantum state representation.
Definition: qtensornetwork.hpp:191
void Decompose(bitLenInt start, QInterfacePtr dest)
Minimally decompose a set of contiguous bits from the separably composed unit, into "destination".
Definition: qtensornetwork.hpp:233
bool isSparse
Definition: qtensornetwork.hpp:32
void MCMtrx(const std::vector< bitLenInt > &controls, const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation, with arbitrary control bits.
Definition: qtensornetwork.hpp:343
bool TrySeparate(bitLenInt qubit)
Single-qubit TrySeparate()
Definition: qtensornetwork.hpp:272
bool useHostRam
Definition: qtensornetwork.hpp:31
void SetTInjection(bool useGadget)
Set the option to use T-injection gadgets (off by default)
Definition: qtensornetwork.hpp:109
void SetDeviceList(std::vector< int64_t > dIDs)
Set the device index list, if more than one device is available.
Definition: qtensornetwork.hpp:148
bool TrySeparate(bitLenInt qubit1, bitLenInt qubit2)
Two-qubit TrySeparate()
Definition: qtensornetwork.hpp:273
void CheckQubitCount(bitLenInt target)
Definition: qtensornetwork.hpp:53
real1_f Prob(bitLenInt qubit)
Direct measure of bit probability to be in |1> state.
Definition: qtensornetwork.hpp:298
real1_f ncrp
Definition: qtensornetwork.hpp:47
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: qtensornetwork.hpp:383
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: qtensornetwork.hpp:357
QInterfacePtr Clone()
Clone this QInterface.
Definition: qtensornetwork.cpp:179
void Mtrx(const complex *mtrx, bitLenInt target)
Apply an arbitrary single bit unitary transformation.
Definition: qtensornetwork.hpp:338
bool isReactiveSeparate
Definition: qtensornetwork.hpp:33
bitLenInt Allocate(bitLenInt start, bitLenInt length)
Allocate new "length" count of |0> state qubits at specified qubit index start position.
Definition: qtensornetwork.hpp:276
real1_f SumSqrDiff(QInterfacePtr toCompare)
Calculates (1 - <\psi_e|\psi_c>) between states |\psi_c> and |\psi_e>.
Definition: qtensornetwork.hpp:166
void SetNcrp(real1_f rp)
Set the "Near-clifford rounding parameter" value, (between 0 and 1)
Definition: qtensornetwork.hpp:115
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: qtensornetwork.hpp:371
bool isNearClifford
Definition: qtensornetwork.hpp:35
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: qtensornetwork.hpp:397
std::map< bitCapInt, int > MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots)
Statistical measure of masked permutation probability.
Definition: qtensornetwork.hpp:318
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: qtensornetwork.hpp:268
bitLenInt aceQubits
Definition: qtensornetwork.hpp:44
complex GetAmplitude(const bitCapInt &perm)
Get the representational amplitude of a full permutation.
Definition: qtensornetwork.hpp:211
real1_f ProbAll(const bitCapInt &fullRegister)
Direct measure of full permutation probability.
Definition: qtensornetwork.hpp:304
void GetQuantumState(complex *state)
Get the pure quantum state representation.
Definition: qtensornetwork.hpp:187
void SetPermutation(const bitCapInt &initState, const complex &phaseFac=CMPLX_DEFAULT_ARG)
Set to a specific permutation of all qubits.
Definition: qtensornetwork.hpp:178
void SetAmplitude(const bitCapInt &perm, const complex &amp)
Sets the representational amplitude of a full permutation.
Definition: qtensornetwork.hpp:217
bitLenInt qbThreshold
Definition: qtensornetwork.hpp:45
int64_t GetDevice()
Get the device index.
Definition: qtensornetwork.hpp:149
QCircuitPtr circuit
Definition: qtensornetwork.hpp:51
QInterfacePtr Decompose(bitLenInt start, bitLenInt length)
Schmidt decompose a length of qubits.
Definition: qtensornetwork.hpp:241
void SetSparseAceMaxMb(size_t mb)
Set the (sparse-simulation) "automatic circuit elision" (ACE) maximum memory megabytes.
Definition: qtensornetwork.hpp:127
int64_t devID
Definition: qtensornetwork.hpp:42
void NormalizeState(real1_f nrm=REAL1_DEFAULT_ARG, real1_f norm_thresh=REAL1_DEFAULT_ARG, real1_f phaseArg=ZERO_R1_F)
Apply the normalization factor found by UpdateRunningNorm() or on the fly by a single bit gate.
Definition: qtensornetwork.hpp:160
void SetDevice(int64_t dID)
Set the device index, if more than one device is available.
Definition: qtensornetwork.hpp:147
void CheckQubitCount(bitLenInt target, const std::vector< bitLenInt > &controls)
Definition: qtensornetwork.hpp:60
void RunAsAmplitudes(Fn fn, std::set< bitLenInt > qubits=std::set< bitLenInt >())
Definition: qtensornetwork.hpp:71
void SetQuantumState(QInterfacePtr eng)
Definition: qtensornetwork.hpp:195
void SetReactiveSeparate(bool isAggSep)
Set reactive separation option (on by default if available)
Definition: qtensornetwork.hpp:107
void SetSdrp(real1_f sdrp)
Set the "Schmidt decomposition rounding parameter" value, (between 0 and 1)
Definition: qtensornetwork.hpp:100
real1_f separabilityThreshold
Definition: qtensornetwork.hpp:46
double GetUnitaryFidelity()
When "Schmidt-decomposition rounding parameter" ("SDRP") is being used, starting from initial 1....
Definition: qtensornetwork.hpp:133
void MultiShotMeasureMask(const std::vector< bitCapInt > &qPowers, unsigned shots, unsigned long long *shotsArray)
Statistical measure of masked permutation probability (returned as array)
Definition: qtensornetwork.hpp:328
bitLenInt Compose(QInterfacePtr toCopy, bitLenInt start)
Compose() a QInterface peer, inserting its qubit into index order at start index.
Definition: qtensornetwork.hpp:223
std::vector< int64_t > deviceIDs
Definition: qtensornetwork.hpp:49
bitCapInt HighestProbAll()
Get highest probability permutation.
Definition: qtensornetwork.hpp:140
QTensorNetwork(std::vector< QInterfaceEngine > eng, bitLenInt qBitCount, const bitCapInt &initState=ZERO_BCI, qrack_rand_gen_ptr rgp=nullptr, const complex &phaseFac=CMPLX_DEFAULT_ARG, bool doNorm=false, bool randomGlobalPhase=true, bool useHostMem=false, int64_t deviceId=-1, bool useHardwareRNG=true, bool useSparseStateVec=false, real1_f norm_thresh=REAL1_EPSILON, std::vector< int64_t > ignored={}, bitLenInt qubitThreshold=0, real1_f separation_thresh=_qrack_qunit_sep_thresh)
Definition: qtensornetwork.cpp:35
bool TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol=TRYDECOMPOSE_EPSILON)
Attempt to Decompose() a bit range.
Definition: qtensornetwork.hpp:258
QInterfacePtr layerStack
Definition: qtensornetwork.hpp:48
real1_f SumSqrDiff(QTensorNetworkPtr toCompare)
Definition: qtensornetwork.hpp:170
void Finish()
If asynchronous work is still running, block until it finishes.
Definition: qtensornetwork.hpp:152
bool isFinished()
Returns "false" if asynchronous work is still running, and "true" if all previously dispatched asynch...
Definition: qtensornetwork.hpp:154
void Dispose(bitLenInt start, bitLenInt length)
Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separa...
Definition: qtensornetwork.hpp:248
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: qtensornetwork.hpp:351
bool ForceM(bitLenInt qubit, bool result, bool doForce=true, bool doApply=true)
Act as if is a measurement was applied, except force the (usually random) result.
Definition: qtensornetwork.hpp:311
std::vector< int64_t > GetDeviceList()
Get the device index.
Definition: qtensornetwork.hpp:150
void SetAceMaxQubits(bitLenInt qb)
Set the "automatic circuit elision" (ACE) maximum entangled subsystem qubit count.
Definition: qtensornetwork.hpp:121
void Dispose(bitLenInt start, bitLenInt length, const bitCapInt &disposedPerm)
Dispose a a contiguous set of qubits that are already in a permutation eigenstate.
Definition: qtensornetwork.hpp:253
size_t aceMb
Definition: qtensornetwork.hpp:43
std::vector< QInterfaceEngine > engines
Definition: qtensornetwork.hpp:50
void MakeLayerStack()
Definition: qtensornetwork.cpp:160
void Dump()
If asynchronous work is still running, let the simulator know that it can be aborted.
Definition: qtensornetwork.hpp:156
void UpdateRunningNorm(real1_f norm_thresh=REAL1_DEFAULT_ARG)
Force a calculation of the norm of the state vector, in order to make it unit length before the next ...
Definition: qtensornetwork.hpp:158
Half-precision floating-point type.
Definition: half.hpp:2222
virtual void U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)
General unitary gate.
Definition: rotational.cpp:18
virtual void Swap(bitLenInt qubit1, bitLenInt qubit2)
Swap values of two bits in register.
Definition: gates.cpp:166
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
void ThrowIfQbIdArrayIsBad(const std::vector< bitLenInt > &controls, const bitLenInt &qubitCount, std::string message)
Definition: qrack_functions.hpp:185
QRACK_CONST real1_f FP_NORM_EPSILON_F
Definition: qrack_types.hpp:269
std::shared_ptr< QInterface > QInterfacePtr
Definition: qinterface.hpp:29
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:249
QRACK_CONST real1_f TRYDECOMPOSE_EPSILON
Definition: qrack_types.hpp:270
std::complex< real1 > complex
Definition: qrack_types.hpp:136
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:143
std::shared_ptr< QTensorNetwork > QTensorNetworkPtr
Definition: qtensornetwork.hpp:17
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:208
float real1_f
Definition: qrack_types.hpp:103
QRACK_CONST complex CMPLX_DEFAULT_ARG
Definition: qrack_types.hpp:267
std::shared_ptr< QCircuit > QCircuitPtr
Definition: qcircuit.hpp:607
QRACK_CONST complex ZERO_CMPLX
Definition: qrack_types.hpp:263
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:138
bitLenInt log2(bitCapInt n)
Definition: qrack_functions.hpp:141
#define REAL1_DEFAULT_ARG
Definition: qrack_types.hpp:185
#define bitLenInt
Definition: qrack_types.hpp:42
#define ZERO_R1_F
Definition: qrack_types.hpp:168
#define qrack_rand_gen_ptr
Definition: qrack_types.hpp:164
#define bitCapInt
Definition: qrack_types.hpp:66