-
Notifications
You must be signed in to change notification settings - Fork 0
/
qpe.qasm
56 lines (52 loc) · 1.3 KB
/
qpe.qasm
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
OPENQASM 2.0;
include "qelib1.inc";
qreg q[9];
creg c[6];
//This initializes 9 quantum and 6 classical registers.
// initialize ancilla qubits
h q[0];
h q[1];
h q[2];
h q[3];
h q[4];
h q[5];
// eigenstates of the unitary operator
x q[6];
x q[7];
x q[8];
//I extended the pattern formed by the 3-qubit and 6-qubit implementations.
barrier q; // unitary operator
ccx q[5], q[6], q[7];
cz q[7], q[8];
ccx q[5], q[6], q[7];
//This 4-qubit controlled-Z gate is from this webpage.
barrier q; // inverse Quantum Fourier Transform (QFT)
cu1(-pi/32) q[5], q[0];
cu1(-pi/16) q[5], q[1];
cu1(-pi/8) q[5], q[2];
cu1(-pi/4) q[5], q[3];
cu1(-pi/2) q[5], q[4];
cu1(-pi/16) q[4], q[0];
cu1(-pi/8) q[4], q[1];
cu1(-pi/4) q[4], q[2];
cu1(-pi/2) q[4], q[3];
cu1(-pi/8) q[3], q[0];
cu1(-pi/4) q[3], q[1];
cu1(-pi/2) q[3], q[2];
cu1(-pi/4) q[2], q[0];
cu1(-pi/2) q[2], q[1];
cu1(-pi/2) q[1], q[0];
//This would obviously be more efficient using Python FOR loops, but you can copy-and-paste that from IBM Q Experience and there’s no fun in that. If I eventually implement this in Shor’s algorithm, I’ll use Python.
barrier q; // output should be 32 (binary 100000)
h q[0];
measure q[0] -> c[0];
h q[1];
measure q[1] -> c[1];
h q[2];
measure q[2] -> c[2];
h q[3];
measure q[3] -> c[3];
h q[4];
measure q[4] -> c[4];
h q[5];
measure q[5] -> c[5];