|
1 | | -from kirin import ir as _ir |
2 | | -from kirin.prelude import structural_no_opt as _structural_no_opt |
3 | | -from kirin.lowering import wraps as _wraps |
4 | | - |
5 | 1 | from . import stmts as stmts, types as types, rewrite as rewrite |
| 2 | +from .stdlib import ( |
| 3 | + ch as ch, |
| 4 | + cx as cx, |
| 5 | + cy as cy, |
| 6 | + cz as cz, |
| 7 | + rx as rx, |
| 8 | + ry as ry, |
| 9 | + rz as rz, |
| 10 | + cphase as cphase, |
| 11 | +) |
6 | 12 | from .traits import Unitary as Unitary, MaybeUnitary as MaybeUnitary |
7 | 13 | from ._dialect import dialect as dialect |
8 | | - |
9 | | - |
10 | | -@_wraps(stmts.Kron) |
11 | | -def kron(lhs: types.Op, rhs: types.Op) -> types.Op: ... |
12 | | - |
13 | | - |
14 | | -@_wraps(stmts.Mult) |
15 | | -def mult(lhs: types.Op, rhs: types.Op) -> types.Op: ... |
16 | | - |
17 | | - |
18 | | -@_wraps(stmts.Scale) |
19 | | -def scale(op: types.Op, factor: complex) -> types.Op: ... |
20 | | - |
21 | | - |
22 | | -@_wraps(stmts.Adjoint) |
23 | | -def adjoint(op: types.Op) -> types.Op: ... |
24 | | - |
25 | | - |
26 | | -@_wraps(stmts.Control) |
27 | | -def control(op: types.Op, *, n_controls: int) -> types.Op: |
28 | | - """ |
29 | | - Create a controlled operator. |
30 | | -
|
31 | | - Note, that when considering atom loss, the operator will not be applied if |
32 | | - any of the controls has been lost. |
33 | | -
|
34 | | - Args: |
35 | | - operator: The operator to apply under the control. |
36 | | - n_controls: The number qubits to be used as control. |
37 | | -
|
38 | | - Returns: |
39 | | - Operator |
40 | | - """ |
41 | | - ... |
42 | | - |
43 | | - |
44 | | -@_wraps(stmts.Identity) |
45 | | -def identity(*, sites: int) -> types.Op: ... |
46 | | - |
47 | | - |
48 | | -@_wraps(stmts.Rot) |
49 | | -def rot(axis: types.Op, angle: float) -> types.Op: ... |
50 | | - |
51 | | - |
52 | | -@_wraps(stmts.ShiftOp) |
53 | | -def shift(theta: float) -> types.Op: ... |
54 | | - |
55 | | - |
56 | | -@_wraps(stmts.PhaseOp) |
57 | | -def phase(theta: float) -> types.Op: ... |
58 | | - |
59 | | - |
60 | | -@_wraps(stmts.X) |
61 | | -def x() -> types.Op: ... |
62 | | - |
63 | | - |
64 | | -@_wraps(stmts.Y) |
65 | | -def y() -> types.Op: ... |
66 | | - |
67 | | - |
68 | | -@_wraps(stmts.Z) |
69 | | -def z() -> types.Op: ... |
70 | | - |
71 | | - |
72 | | -@_wraps(stmts.H) |
73 | | -def h() -> types.Op: ... |
74 | | - |
75 | | - |
76 | | -@_wraps(stmts.S) |
77 | | -def s() -> types.Op: ... |
78 | | - |
79 | | - |
80 | | -@_wraps(stmts.T) |
81 | | -def t() -> types.Op: ... |
82 | | - |
83 | | - |
84 | | -@_wraps(stmts.P0) |
85 | | -def p0() -> types.Op: ... |
86 | | - |
87 | | - |
88 | | -@_wraps(stmts.P1) |
89 | | -def p1() -> types.Op: ... |
90 | | - |
91 | | - |
92 | | -@_wraps(stmts.Sn) |
93 | | -def spin_n() -> types.Op: ... |
94 | | - |
95 | | - |
96 | | -@_wraps(stmts.Sp) |
97 | | -def spin_p() -> types.Op: ... |
98 | | - |
99 | | - |
100 | | -@_wraps(stmts.U3) |
101 | | -def u(theta: float, phi: float, lam: float) -> types.Op: ... |
102 | | - |
103 | | - |
104 | | -@_wraps(stmts.PauliString) |
105 | | -def pauli_string(*, string: str) -> types.Op: ... |
106 | | - |
107 | | - |
108 | | -# stdlibs |
109 | | -@_ir.dialect_group(_structural_no_opt.add(dialect)) |
110 | | -def op(self): |
111 | | - def run_pass(method): |
112 | | - pass |
113 | | - |
114 | | - return run_pass |
115 | | - |
116 | | - |
117 | | -@op |
118 | | -def rx(theta: float) -> types.Op: |
119 | | - """Rotation X gate.""" |
120 | | - return rot(x(), theta) |
121 | | - |
122 | | - |
123 | | -@op |
124 | | -def ry(theta: float) -> types.Op: |
125 | | - """Rotation Y gate.""" |
126 | | - return rot(y(), theta) |
127 | | - |
128 | | - |
129 | | -@op |
130 | | -def rz(theta: float) -> types.Op: |
131 | | - """Rotation Z gate.""" |
132 | | - return rot(z(), theta) |
133 | | - |
134 | | - |
135 | | -@op |
136 | | -def cx() -> types.Op: |
137 | | - """Controlled X gate.""" |
138 | | - return control(x(), n_controls=1) |
139 | | - |
140 | | - |
141 | | -@op |
142 | | -def cy() -> types.Op: |
143 | | - """Controlled Y gate.""" |
144 | | - return control(y(), n_controls=1) |
145 | | - |
146 | | - |
147 | | -@op |
148 | | -def cz() -> types.Op: |
149 | | - """Control Z gate.""" |
150 | | - return control(z(), n_controls=1) |
151 | | - |
152 | | - |
153 | | -@op |
154 | | -def ch() -> types.Op: |
155 | | - """Control H gate.""" |
156 | | - return control(h(), n_controls=1) |
157 | | - |
158 | | - |
159 | | -@op |
160 | | -def cphase(theta: float) -> types.Op: |
161 | | - """Control Phase gate.""" |
162 | | - return control(phase(theta), n_controls=1) |
| 14 | +from ._wrapper import ( |
| 15 | + h as h, |
| 16 | + s as s, |
| 17 | + t as t, |
| 18 | + u as u, |
| 19 | + x as x, |
| 20 | + y as y, |
| 21 | + z as z, |
| 22 | + p0 as p0, |
| 23 | + p1 as p1, |
| 24 | + rot as rot, |
| 25 | + kron as kron, |
| 26 | + mult as mult, |
| 27 | + phase as phase, |
| 28 | + scale as scale, |
| 29 | + shift as shift, |
| 30 | + spin_n as spin_n, |
| 31 | + spin_p as spin_p, |
| 32 | + adjoint as adjoint, |
| 33 | + control as control, |
| 34 | + identity as identity, |
| 35 | + pauli_string as pauli_string, |
| 36 | +) |
0 commit comments