Skip to content

Commit e484faa

Browse files
authored
Fix QASM2.loads without return value (#246)
1 parent 3ba7336 commit e484faa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/bloqade/qasm2/parse/lowering.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def loads(
5656
raise lowering.BuildError(f"Cannot find return value {returns}")
5757
else:
5858
return_value = func.ConstantNone()
59+
frame.push(return_value)
5960

6061
return_node = frame.push(func.Return(value_or_stmt=return_value))
6162

test/pyqrack/test_target.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import math
2+
import textwrap
23

34
import pytest
45
from kirin import ir
56
from kirin.dialects import ilist
67

78
from bloqade import qasm2
89
from bloqade.pyqrack import PyQrack, PyQrackQubit, StackMemorySimulator, reg
10+
from bloqade.qasm2.parse.lowering import QASM2
911

1012

1113
def test_target():
@@ -171,3 +173,21 @@ def parallel():
171173
result = target.run(parallel)
172174

173175
assert result == [reg.Measurement.One] * 4
176+
177+
178+
def test_loads_without_return():
179+
qasm2_str = textwrap.dedent(
180+
"""
181+
OPENQASM 2.0;
182+
183+
qreg q[1];
184+
x q[0];
185+
"""
186+
)
187+
188+
main = QASM2(qasm2.main).loads(qasm2_str, "main")
189+
190+
sim = StackMemorySimulator(min_qubits=2)
191+
ket = sim.state_vector(main)
192+
193+
assert ket[0] == 0

0 commit comments

Comments
 (0)