forked from openqasm/openqasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipe.qasm
38 lines (32 loc) · 948 Bytes
/
ipe.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
/*
* Iterative phase estimation
*/
OPENQASM 3;
include "stdgates.inc";
const int[32] n = 10; // number of iterations
const float[32] theta = 3 * pi / 8; // phase angle on target qubit
qubit q; // phase estimation qubit
qubit r; // target qubit for the controlled-unitary gate
angle[n] c; // phase estimation bits
// initialize
reset q;
reset r;
// prepare uniform superposition of eigenvectors of phase
h r;
// iterative phase estimation loop
uint[n] power = 1;
for i in [0: n - 1] { // implicitly cast val to int
reset q;
h q;
ctrl @ pow(power) @ phase(theta) q, r;
inv @ phase(c) q;
h q;
measure q -> c[0];
// newest measurement outcome is associated to a pi/2 phase shift
// in the next iteration, so shift all bits of c left
c <<= 1;
power <<= 1;
}
// Now c contains the n-bit estimate of phi in the
// eigenvalue e^{i*phi} and qreg r is projected to an
// approximate eigenstate of the phase gate.