10class DistributedGpuLibStateVectorSim
13 DistributedGpuLibStateVectorSim(std::shared_ptr<DistributedGpuLibrary> lib,
void *obj) : lib(std::move(lib)), obj(obj)
16 throw std::runtime_error(
"Null distributed GPU state");
19 virtual ~DistributedGpuLibStateVectorSim()
21 lib->DestroyNative(obj);
24 DistributedGpuLibStateVectorSim(
const DistributedGpuLibStateVectorSim &) =
delete;
25 DistributedGpuLibStateVectorSim &operator=(
const DistributedGpuLibStateVectorSim &) =
delete;
27 DistributedGpuLibStateVectorSim(DistributedGpuLibStateVectorSim &&other) noexcept : lib(other.lib), obj(std::exchange(other.obj,
nullptr))
31 DistributedGpuLibStateVectorSim &operator=(DistributedGpuLibStateVectorSim &&) =
delete;
33 std::unique_ptr<DistributedGpuLibStateVectorSim> Clone()
const
35 return std::make_unique<DistributedGpuLibStateVectorSim>(lib, lib->CloneNative(obj));
38 int GetBackend()
const
40 auto result = lib->GetBackend(obj);
42 lib->Fail(
"GetBackend");
43 const char *error = lib->GetLastError();
45 throw std::runtime_error(error);
49 int SetExExecutionConfig(
const DistributedGpuApi::MgdExExecutionConfig *config)
const
51 auto result = lib->SetExExecutionConfig(obj, config);
52 lib->Check(result,
"SetExExecutionConfig");
56 int SetDataType(
int useDoublePrecision)
const
58 auto result = lib->SetDataType(obj, useDoublePrecision);
59 lib->Check(result,
"SetDataType");
63 int SetSeed(
unsigned long long seed)
const
65 auto result = lib->SetSeed(obj, seed);
66 lib->Check(result,
"SetSeed");
70 int IsDoublePrecision()
const
72 auto result = lib->IsDoublePrecision(obj);
73 const char *error = lib->GetLastError();
75 throw std::runtime_error(error);
79 int GetNrQubits()
const
81 auto result = lib->GetNrQubits(obj);
83 lib->Fail(
"GetNrQubits");
84 const char *error = lib->GetLastError();
86 throw std::runtime_error(error);
90 int GetStateVectorGpuId()
const
92 auto result = lib->GetStateVectorGpuId(obj);
93 const char *error = lib->GetLastError();
95 throw std::runtime_error(error);
99 int Create(
unsigned int nrQubits)
const
101 auto result = lib->Create(obj, nrQubits);
102 lib->Check(result,
"Create");
106 int CreateWithState(
unsigned int nrQubits,
const double *state)
const
108 auto result = lib->CreateWithState(obj, nrQubits, state);
109 lib->Check(result,
"CreateWithState");
115 auto result = lib->Reset(obj);
116 lib->Check(result,
"Reset");
120 int MeasureQubitCollapse(
int qubitIndex)
const
122 auto result = lib->MeasureQubitCollapse(obj, qubitIndex);
123 if (result != 0 && result != 1)
124 lib->Fail(
"MeasureQubitCollapse");
128 int MeasureQubitNoCollapse(
int qubitIndex)
const
130 auto result = lib->MeasureQubitNoCollapse(obj, qubitIndex);
131 if (result != 0 && result != 1)
132 lib->Fail(
"MeasureQubitNoCollapse");
136 int MeasureQubitsCollapse(
int *qubits,
int *bitstring,
int bitstringLen)
const
138 auto result = lib->MeasureQubitsCollapse(obj, qubits, bitstring, bitstringLen);
139 lib->Check(result,
"MeasureQubitsCollapse");
143 int MeasureQubitsNoCollapse(
int *qubits,
int *bitstring,
int bitstringLen)
const
145 auto result = lib->MeasureQubitsNoCollapse(obj, qubits, bitstring, bitstringLen);
146 lib->Check(result,
"MeasureQubitsNoCollapse");
150 unsigned long long MeasureAllQubitsCollapse()
const
152 auto result = lib->MeasureAllQubitsCollapse(obj);
153 if (result == UINT64_MAX)
154 lib->Fail(
"MeasureAllQubitsCollapse");
158 unsigned long long MeasureAllQubitsNoCollapse()
const
160 auto result = lib->MeasureAllQubitsNoCollapse(obj);
161 if (result == UINT64_MAX)
162 lib->Fail(
"MeasureAllQubitsNoCollapse");
168 auto result = lib->SaveState(obj);
169 lib->Check(result,
"SaveState");
173 int SaveStateToHost()
const
175 auto result = lib->SaveStateToHost(obj);
176 lib->Check(result,
"SaveStateToHost");
180 int SaveStateDestructive()
const
182 auto result = lib->SaveStateDestructive(obj);
183 lib->Check(result,
"SaveStateDestructive");
187 int RestoreStateFreeSaved()
const
189 auto result = lib->RestoreStateFreeSaved(obj);
190 lib->Check(result,
"RestoreStateFreeSaved");
194 int RestoreStateNoFreeSaved()
const
196 auto result = lib->RestoreStateNoFreeSaved(obj);
197 lib->Check(result,
"RestoreStateNoFreeSaved");
201 void FreeSavedState()
const
203 lib->FreeSavedState(obj);
204 const char *error = lib->GetLastError();
206 throw std::runtime_error(error);
209 int Sample(
unsigned int nSamples,
long int *samples,
unsigned int nBits,
int *bitOrdering)
const
211 auto result = lib->Sample(obj, nSamples, samples, nBits, bitOrdering);
212 lib->Check(result,
"Sample");
216 int SampleAll(
unsigned int nSamples,
long int *samples)
const
218 auto result = lib->SampleAll(obj, nSamples, samples);
219 lib->Check(result,
"SampleAll");
223 int Amplitude(
long long int state,
double *real,
double *imaginary)
const
225 auto result = lib->Amplitude(obj, state, real, imaginary);
226 lib->Check(result,
"Amplitude");
230 double Probability(
int *qubits,
int *mask,
int len)
const
232 auto result = lib->Probability(obj, qubits, mask, len);
233 if (!std::isfinite(result))
234 lib->Fail(
"Probability");
238 double BasisStateProbability(
long long int state)
const
240 auto result = lib->BasisStateProbability(obj, state);
241 if (!std::isfinite(result))
242 lib->Fail(
"BasisStateProbability");
248 auto result = lib->AllProbabilities(obj, probabilities);
249 lib->Check(result,
"AllProbabilities");
253 double ExpectationValue(
const char *pauliString,
int len)
const
255 auto result = lib->ExpectationValue(obj, pauliString, len);
256 if (!std::isfinite(result))
257 lib->Fail(
"ExpectationValue");
261 int ApplyX(
int qubit)
const
263 auto result = lib->ApplyX(obj, qubit);
264 lib->Check(result,
"ApplyX");
268 int ApplyY(
int qubit)
const
270 auto result = lib->ApplyY(obj, qubit);
271 lib->Check(result,
"ApplyY");
275 int ApplyZ(
int qubit)
const
277 auto result = lib->ApplyZ(obj, qubit);
278 lib->Check(result,
"ApplyZ");
282 int ApplyH(
int qubit)
const
284 auto result = lib->ApplyH(obj, qubit);
285 lib->Check(result,
"ApplyH");
289 int ApplyS(
int qubit)
const
291 auto result = lib->ApplyS(obj, qubit);
292 lib->Check(result,
"ApplyS");
298 auto result = lib->ApplySDG(obj, qubit);
299 lib->Check(result,
"ApplySDG");
303 int ApplyT(
int qubit)
const
305 auto result = lib->ApplyT(obj, qubit);
306 lib->Check(result,
"ApplyT");
312 auto result = lib->ApplyTDG(obj, qubit);
313 lib->Check(result,
"ApplyTDG");
319 auto result = lib->ApplySX(obj, qubit);
320 lib->Check(result,
"ApplySX");
326 auto result = lib->ApplySXDG(obj, qubit);
327 lib->Check(result,
"ApplySXDG");
331 int ApplyK(
int qubit)
const
333 auto result = lib->ApplyK(obj, qubit);
334 lib->Check(result,
"ApplyK");
338 int ApplyP(
int qubit,
double theta)
const
340 auto result = lib->ApplyP(obj, qubit, theta);
341 lib->Check(result,
"ApplyP");
345 int ApplyRx(
int qubit,
double theta)
const
347 auto result = lib->ApplyRx(obj, qubit, theta);
348 lib->Check(result,
"ApplyRx");
352 int ApplyRy(
int qubit,
double theta)
const
354 auto result = lib->ApplyRy(obj, qubit, theta);
355 lib->Check(result,
"ApplyRy");
359 int ApplyRz(
int qubit,
double theta)
const
361 auto result = lib->ApplyRz(obj, qubit, theta);
362 lib->Check(result,
"ApplyRz");
366 int ApplyU(
int qubit,
double theta,
double phi,
double lambda,
double gamma)
const
368 auto result = lib->ApplyU(obj, qubit, theta, phi, lambda, gamma);
369 lib->Check(result,
"ApplyU");
373 int ApplyCX(
int controlQubit,
int targetQubit)
const
375 auto result = lib->ApplyCX(obj, controlQubit, targetQubit);
376 lib->Check(result,
"ApplyCX");
380 int ApplyCY(
int controlQubit,
int targetQubit)
const
382 auto result = lib->ApplyCY(obj, controlQubit, targetQubit);
383 lib->Check(result,
"ApplyCY");
387 int ApplyCZ(
int controlQubit,
int targetQubit)
const
389 auto result = lib->ApplyCZ(obj, controlQubit, targetQubit);
390 lib->Check(result,
"ApplyCZ");
394 int ApplyCH(
int controlQubit,
int targetQubit)
const
396 auto result = lib->ApplyCH(obj, controlQubit, targetQubit);
397 lib->Check(result,
"ApplyCH");
401 int ApplyCSX(
int controlQubit,
int targetQubit)
const
403 auto result = lib->ApplyCSX(obj, controlQubit, targetQubit);
404 lib->Check(result,
"ApplyCSX");
408 int ApplyCSXDG(
int controlQubit,
int targetQubit)
const
410 auto result = lib->ApplyCSXDG(obj, controlQubit, targetQubit);
411 lib->Check(result,
"ApplyCSXDG");
415 int ApplyCP(
int controlQubit,
int targetQubit,
double theta)
const
417 auto result = lib->ApplyCP(obj, controlQubit, targetQubit, theta);
418 lib->Check(result,
"ApplyCP");
422 int ApplyCRx(
int controlQubit,
int targetQubit,
double theta)
const
424 auto result = lib->ApplyCRx(obj, controlQubit, targetQubit, theta);
425 lib->Check(result,
"ApplyCRx");
429 int ApplyCRy(
int controlQubit,
int targetQubit,
double theta)
const
431 auto result = lib->ApplyCRy(obj, controlQubit, targetQubit, theta);
432 lib->Check(result,
"ApplyCRy");
436 int ApplyCRz(
int controlQubit,
int targetQubit,
double theta)
const
438 auto result = lib->ApplyCRz(obj, controlQubit, targetQubit, theta);
439 lib->Check(result,
"ApplyCRz");
443 int ApplyCCX(
int controlQubit1,
int controlQubit2,
int targetQubit)
const
445 auto result = lib->ApplyCCX(obj, controlQubit1, controlQubit2, targetQubit);
446 lib->Check(result,
"ApplyCCX");
450 int ApplySwap(
int qubit1,
int qubit2)
const
452 auto result = lib->ApplySwap(obj, qubit1, qubit2);
453 lib->Check(result,
"ApplySwap");
457 int ApplyCSwap(
int controlQubit,
int qubit1,
int qubit2)
const
459 auto result = lib->ApplyCSwap(obj, controlQubit, qubit1, qubit2);
460 lib->Check(result,
"ApplyCSwap");
464 int ApplyCU(
int controlQubit,
int targetQubit,
double theta,
double phi,
double lambda,
double gamma)
const
466 auto result = lib->ApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda, gamma);
467 lib->Check(result,
"ApplyCU");
471 int ConfigureDistribution(
const DistributedGpuApi::MgdDistributionConfig *config)
const
473 auto result = lib->ConfigureDistribution(obj, config);
474 lib->Check(result,
"ConfigureDistribution");
478 int GetShardDevices(int32_t *devices, uint32_t capacity)
const
480 auto result = lib->GetShardDevices(obj, devices, capacity);
482 lib->Fail(
"GetShardDevices");
483 const char *error = lib->GetLastError();
485 throw std::runtime_error(error);
489 int GetGlobalQubits(int32_t *qubits, uint32_t capacity)
const
491 auto result = lib->GetGlobalQubits(obj, qubits, capacity);
493 lib->Fail(
"GetGlobalQubits");
494 const char *error = lib->GetLastError();
496 throw std::runtime_error(error);
500 int GetQubitLayout(int32_t *wires, uint32_t capacity)
const
502 auto result = lib->GetQubitLayout(obj, wires, capacity);
504 lib->Fail(
"GetQubitLayout");
505 const char *error = lib->GetLastError();
507 throw std::runtime_error(error);
511 int Redistribute(
const int32_t *global_qubits, uint32_t count)
const
513 auto result = lib->Redistribute(obj, global_qubits, count);
514 lib->Check(result,
"Redistribute");
518 int SwapGlobalLocalQubits(
const int32_t *global_qubits,
const int32_t *local_qubits, uint32_t count)
const
520 auto result = lib->SwapGlobalLocalQubits(obj, global_qubits, local_qubits, count);
521 lib->Check(result,
"SwapGlobalLocalQubits");
525 int Synchronize()
const
527 auto result = lib->Synchronize(obj);
528 lib->Check(result,
"Synchronize");
532 int GetStateRange(uint64_t begin, uint64_t end,
double *output)
const
534 auto result = lib->GetStateRange(obj, begin, end, output);
535 lib->Check(result,
"GetStateRange");
539 int SetStateRange(uint64_t begin, uint64_t end,
const double *input)
const
541 auto result = lib->SetStateRange(obj, begin, end, input);
542 lib->Check(result,
"SetStateRange");
546 int GetLocalStateBounds(uint64_t *begin, uint64_t *end)
const
548 auto result = lib->GetLocalStateBounds(obj, begin, end);
549 lib->Check(result,
"GetLocalStateBounds");
553 int GetLocalStateRange(uint64_t begin, uint64_t end,
double *output)
const
555 auto result = lib->GetLocalStateRange(obj, begin, end, output);
556 lib->Check(result,
"GetLocalStateRange");
560 int SetLocalStateRange(uint64_t begin, uint64_t end,
const double *input)
const
562 auto result = lib->SetLocalStateRange(obj, begin, end, input);
563 lib->Check(result,
"SetLocalStateRange");
567 int CreateWithBasisState(uint32_t nrQubits, uint64_t basis)
const
569 auto result = lib->CreateWithBasisState(obj, nrQubits, basis);
570 lib->Check(result,
"CreateWithBasisState");
574 int ApplyOneQubitMatrix(
int qubit,
const double *matrix)
const
576 auto result = lib->ApplyOneQubitMatrix(obj, qubit, matrix);
577 lib->Check(result,
"ApplyOneQubitMatrix");
581 int ApplyOneQubitMatrixWithLayout(
int qubit,
const double *matrix,
int layout)
const
583 auto result = lib->ApplyOneQubitMatrixWithLayout(obj, qubit, matrix, layout);
584 lib->Check(result,
"ApplyOneQubitMatrixWithLayout");
588 int ApplyTwoQubitMatrix(
int qubit0,
int qubit1,
const double *matrix)
const
590 auto result = lib->ApplyTwoQubitMatrix(obj, qubit0, qubit1, matrix);
591 lib->Check(result,
"ApplyTwoQubitMatrix");
595 int ApplyTwoQubitMatrixWithLayout(
int qubit0,
int qubit1,
const double *matrix,
int layout)
const
597 auto result = lib->ApplyTwoQubitMatrixWithLayout(obj, qubit0, qubit1, matrix, layout);
598 lib->Check(result,
"ApplyTwoQubitMatrixWithLayout");
602 int ApplyThreeQubitMatrix(
int qubit0,
int qubit1,
int qubit2,
const double *matrix)
const
604 if (!lib->ApplyThreeQubitMatrix)
605 throw std::runtime_error(
"Update the distributed GPU plugin to apply three-qubit matrices");
606 auto result = lib->ApplyThreeQubitMatrix(obj, qubit0, qubit1, qubit2, matrix);
607 lib->Check(result,
"ApplyThreeQubitMatrix");
611 int ApplyThreeQubitMatrixWithLayout(
int qubit0,
int qubit1,
int qubit2,
const double *matrix,
int layout)
const
613 if (!lib->ApplyThreeQubitMatrixWithLayout)
614 throw std::runtime_error(
"Update the distributed GPU plugin to apply three-qubit matrices");
615 auto result = lib->ApplyThreeQubitMatrixWithLayout(obj, qubit0, qubit1, qubit2, matrix, layout);
616 lib->Check(result,
"ApplyThreeQubitMatrixWithLayout");
621 std::shared_ptr<DistributedGpuLibrary> lib;
int ApplyK(void *sim, int qubit)
double Probability(void *sim, unsigned long long int outcome)
int ApplyRx(void *sim, int qubit, double theta)
int ApplyX(void *sim, int qubit)
int ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
int ApplyCRy(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyTDG(void *sim, int qubit)
int ApplyCSXDG(void *sim, int controlQubit, int targetQubit)
int ApplyS(void *sim, int qubit)
int ApplyCX(void *sim, int controlQubit, int targetQubit)
int ApplyCRz(void *sim, int controlQubit, int targetQubit, double theta)
double * AllProbabilities(void *sim)
int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
int ApplySXDG(void *sim, int qubit)
int ApplySDG(void *sim, int qubit)
int ApplyCSwap(void *sim, int controlQubit, int qubit1, int qubit2)
int ApplyCCX(void *sim, int controlQubit1, int controlQubit2, int targetQubit)
int ApplyY(void *sim, int qubit)
double * Amplitude(void *sim, unsigned long long int outcome)
int ApplyZ(void *sim, int qubit)
int ApplyH(void *sim, int qubit)
int ApplyCY(void *sim, int controlQubit, int targetQubit)
int ApplyCU(void *sim, int controlQubit, int targetQubit, double theta, double phi, double lambda, double gamma)
int ApplySwap(void *sim, int qubit1, int qubit2)
int ApplyRy(void *sim, int qubit, double theta)
int ApplyP(void *sim, int qubit, double theta)
int ApplyCH(void *sim, int controlQubit, int targetQubit)
int ApplySX(void *sim, int qubit)
int ApplyCZ(void *sim, int controlQubit, int targetQubit)
int ApplyRz(void *sim, int qubit, double theta)
int ApplyT(void *sim, int qubit)
int ApplyCRx(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyCSX(void *sim, int controlQubit, int targetQubit)
Bounded online routing based on current physical bond dimensions.