forked from QuEST-Kit/QuEST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_multiswap.cpp
More file actions
38 lines (30 loc) · 1.01 KB
/
Copy pathtest_multiswap.cpp
File metadata and controls
38 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "quest/include/quest.h"
#include <stdio.h>
#include <vector>
#include <cmath>
int main() {
initQuESTEnv();
Qureg qureg = createQureg(4); // 16 amplitudes, indices 0-15
initZeroState(qureg); // |0000>, amp[0] = 1
// flip qubit 0 → |0001>, amp[1] = 1
applyPauliX(qureg, 0);
// SWAP qubit 0 ↔ qubit 3: |0001> → |1000>, amp[8] = 1
std::vector<int> a = {0};
std::vector<int> b = {3};
applyMultiSwap(qureg, a, b);
// print non-zero amps
printf("Statevector after SWAP(0,3) on |0001>:\n");
for (int i = 0; i < 16; i++) {
qcomp amp = getQuregAmp(qureg, i);
qreal re = std::real(amp);
qreal im = std::imag(amp);
if (re*re + im*im > 0.01)
printf(" amp[%d] = (%.3f, %.3f)\n", i, re, im);
}
printf("EXPECT: amp[8] = (1.000, 0.000)\n");
qcomp result = getQuregAmp(qureg, 8);
printf("%s\n", (std::real(result) > 0.99) ? "PASS" : "FAIL");
destroyQureg(qureg);
finalizeQuESTEnv();
return 0;
}