forked from openqasm/openqasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdgates.inc
98 lines (97 loc) · 1.96 KB
/
stdgates.inc
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Standard gate library
// phase gate (Z-rotation by lambda)
gate phase(angle[32]:lambda) q { U(0, 0, lambda) q; }
// controlled-NOT
gate CX c, t { ctrl @ U(pi, 0, pi) c, t; }
gate cx c, t { CX c, t; }
// idle gate (identity)
gate id a { U(0, 0, 0) a; }
// Pauli gate: bit-flip
gate x a { U(pi, 0, pi) a; }
// Pauli gate: bit and phase flip
gate y a { U(pi, pi / 2, pi / 2) a; }
// Pauli gate: phase flip
gate z a { phase(pi) a; }
// Clifford gate: Hadamard
gate h a { U(pi / 2, 0, pi) a; }
// Clifford gate: sqrt(Z) phase gate
gate s a { phase(pi / 2) a; }
// Clifford gate: conjugate of sqrt(Z)
gate sdg a { phase(-pi / 2) a; }
// C3 gate: sqrt(S) phase gate
gate t a { phase(pi/4) a; }
// C3 gate: conjugate of sqrt(S)
gate tdg a { phase(-pi/4) a; }
// Rotation around X-axis
gate rx(angle[32]:theta) a { U(theta, -pi / 2, pi / 2) a; }
// rotation around Y-axis
gate ry(angle[32]:theta) a { U(theta, 0, 0) a; }
// rotation around Z axis
gate rz(angle[32]:phi) a { phase(phi) a; }
// controlled-Phase
gate cz a, b { h b; cx a, b; h b; }
// controlled-Y
gate cy a, b { sdg b; cx a, b; s b; }
// controlled-H
gate ch a, b {
h b;
sdg b;
cx a, b;
h b;
t b;
cx a, b;
t b; s a;
h b;
s b;
x b;
}
// Toffoli
gate ccx a, b, c
{
h c;
cx b, c;
tdg c;
cx a, c;
t c;
cx b, c;
tdg c;
cx a, c;
t b; t c; h c;
cx a, b;
t a; tdg b;
cx a, b;
}
// controlled-swap
gate cswap a, b, c
{
cx c, b;
ccx a, b, c;
cx c, b;
}
// controlled-rz
gate crz(angle[32]:lambda) a, b
{
phase(lambda / 2) b;
cx a, b;
phase(-lambda / 2) b;
cx a, b;
}
// controlled-phase
gate cphase(angle[32]:lambda) a, b
{
phase(lambda / 2) a;
cx a, b;
phase(-lambda / 2) b;
cx a, b;
phase(lambda / 2) b;
}
// controlled-U
gate cu(angle[32]:theta,angle[32]:phi,angle[32]:lambda) c, t
{
// implements controlled-U(theta,phi,lambda) with target t and control c
phase((lambda - phi)/2) t;
cx c,t;
U(-theta / 2, 0, -(phi + lambda) / 2) t;
cx c, t;
U(theta / 2, phi, 0) t;
}