@@ -106,6 +106,7 @@ def main():
106106
107107 return
108108
109+ SquinToStimPass (main .dialects )(main )
109110 assert any (isinstance (stmt , scf .IfElse ) for stmt in main .code .regions [0 ].stmts ())
110111
111112
@@ -125,6 +126,49 @@ def main():
125126
126127 return
127128
129+ SquinToStimPass (main .dialects )(main )
130+ assert any (isinstance (stmt , scf .IfElse ) for stmt in main .code .regions [0 ].stmts ())
131+
132+
133+ def test_missing_predicate ():
134+
135+ # No rewrite should occur because even though there is an scf.IfElse,
136+ # it does not have the proper predicate to be rewritten.
137+ @squin .kernel
138+ def main ():
139+ n_qubits = 4
140+ q = squin .qalloc (n_qubits )
141+
142+ ms = squin .broadcast .measure (q )
143+
144+ if ms [0 ]:
145+ squin .z (q [0 ])
146+
147+ return
148+
149+ SquinToStimPass (main .dialects , no_raise = True )(main )
150+ assert any (isinstance (stmt , scf .IfElse ) for stmt in main .code .regions [0 ].stmts ())
151+
152+
153+ def test_incorrect_predicate ():
154+
155+ # You can only rewrite squin.is_one(...) predicates to
156+ # stim equivalent feedforward statements. Anything else
157+ # is invalid.
158+
159+ @squin .kernel
160+ def main ():
161+ n_qubits = 4
162+ q = squin .qalloc (n_qubits )
163+
164+ ms = squin .broadcast .measure (q )
165+
166+ if squin .is_lost (ms [0 ]):
167+ squin .z (q [0 ])
168+
169+ return
170+
171+ SquinToStimPass (main .dialects , no_raise = True )(main )
128172 assert any (isinstance (stmt , scf .IfElse ) for stmt in main .code .regions [0 ].stmts ())
129173
130174
0 commit comments