Skip to content

Commit 5126e6d

Browse files
committed
add tests
1 parent 507d49b commit 5126e6d

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/bloqade/stim/emit/impls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class EmitStimDebugMethods(MethodTable):
1212
def info(self, emit: EmitStimMain, frame: EmitStrFrame, stmt: Info):
1313

1414
msg: str = frame.get(stmt.msg)
15-
emit.writeln(frame, f"#{msg}")
15+
emit.writeln(frame, f"# {msg}")
1616

1717
return ()

test/stim/dialects/stim/emit/test_stim_debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def test_debug_main():
1313

1414
test_debug_main.print()
1515
out = codegen(test_debug_main)
16-
assert out.strip() == "#debug message"
16+
assert out.strip() == "# debug message"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
3+
from kirin import ir
4+
from kirin.dialects import py, debug
5+
6+
from bloqade.squin import kernel
7+
from bloqade.stim.emit import EmitStimMain
8+
from bloqade.stim.passes import SquinToStimPass
9+
10+
11+
# Taken gratuitously from Kai's unit test
12+
def codegen(mt: ir.Method):
13+
# method should not have any arguments!
14+
emit = EmitStimMain()
15+
emit.initialize()
16+
emit.run(mt=mt, args=())
17+
return emit.get_output()
18+
19+
20+
def as_int(value: int):
21+
return py.constant.Constant(value=value)
22+
23+
24+
def as_float(value: float):
25+
return py.constant.Constant(value=value)
26+
27+
28+
def load_reference_program(filename):
29+
path = os.path.join(
30+
os.path.dirname(__file__), "stim_reference_programs", "debug", filename
31+
)
32+
with open(path, "r") as f:
33+
return f.read()
34+
35+
36+
def test_info():
37+
@kernel
38+
def test():
39+
debug.info("debug message")
40+
return
41+
42+
SquinToStimPass(test.dialects)(test)
43+
base_stim_prog = load_reference_program("debug.stim")
44+
assert codegen(test) == base_stim_prog.rstrip()

0 commit comments

Comments
 (0)