Skip to content

Commit d3e4d86

Browse files
committed
Check callee code for GateFunction
1 parent 5272a91 commit d3e4d86

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/bloqade/qasm2/emit/main.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,19 @@ def emit_if_else(
9898
cond = emit.assert_node(ast.Cmp, frame.get(stmt.cond))
9999

100100
# NOTE: we need exactly one of those in the then body in order to emit valid QASM2
101-
AllowedThenType = (
102-
SingleQubitGate | TwoQubitCtrlGate | Measure | GateFunction | Reset
103-
)
101+
AllowedThenType = SingleQubitGate | TwoQubitCtrlGate | Measure | Reset
104102

105103
then_stmts = stmt.then_body.blocks[0].stmts
106-
is_uop_stmt = map(lambda s: isinstance(s, AllowedThenType), then_stmts)
107-
if sum(is_uop_stmt) != 1:
104+
uop_stmts = 0
105+
for s in then_stmts:
106+
if isinstance(s, AllowedThenType):
107+
uop_stmts += 1
108+
continue
109+
110+
if isinstance(s, func.Invoke):
111+
uop_stmts += isinstance(s.callee.code, GateFunction)
112+
113+
if uop_stmts != 1:
108114
raise interp.InterpreterError(
109115
"Cannot lower if-statement: QASM2 only allows exactly one quantum operation in the body."
110116
)

0 commit comments

Comments
 (0)