forked from openqasm/openqasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rus.qasm
40 lines (36 loc) · 841 Bytes
/
rus.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
/*
* Repeat-until-success circuit for Rz(theta),
* cos(theta-pi)=3/5, from Nielsen and Chuang, Chapter 4.
*/
OPENQASM 3;
include "stdgates.inc";
/*
* Applies identity if out is 01, 10, or 11 and a Z-rotation by
* theta + pi where cos(theta)=3/5 if out is 00.
* The 00 outcome occurs with probability 5/8.
*/
def segment(qubit[2] anc, qubit psi) -> bit[2] {
bit[2] b;
reset anc;
h anc;
ccx anc[0], anc[1], psi;
s psi;
ccx anc[0], anc[1], psi;
z psi;
h anc;
measure anc -> b;
return b;
}
qubit input_qubit;
qubit[2] ancilla;
bit[2] flags = "11";
bit output_qubit;
reset input_qubit;
h input_qubit;
// braces are optional in this case
while(int[2](flags) != 0) {
flags = segment(ancilla, input_qubit);
}
rz(pi - arccos(3 / 5)) input_qubit;
h input_qubit;
output_qubit = measure input_qubit; // should get zero