File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments