Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bloqade/stim/emit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import impls as impls
from .stim_str import FuncEmit as FuncEmit, EmitStimMain as EmitStimMain
17 changes: 17 additions & 0 deletions src/bloqade/stim/emit/impls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from kirin.emit import EmitStrFrame
from kirin.interp import MethodTable, impl
from kirin.dialects.debug import Info, dialect

from bloqade.stim.emit.stim_str import EmitStimMain


@dialect.register(key="emit.stim")
class EmitStimDebugMethods(MethodTable):

@impl(Info)
def info(self, emit: EmitStimMain, frame: EmitStrFrame, stmt: Info):

msg: str = frame.get(stmt.msg)
emit.writeln(frame, f"# {msg}")

return ()
16 changes: 16 additions & 0 deletions test/stim/dialects/stim/emit/test_stim_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from kirin.dialects import debug

from bloqade import stim

from .base import codegen


def test_debug():

@stim.main
def test_debug_main():
debug.info("debug message")

test_debug_main.print()
out = codegen(test_debug_main)
assert out.strip() == "# debug message"
2 changes: 2 additions & 0 deletions test/stim/passes/stim_reference_programs/debug/debug.stim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

# debug message
44 changes: 44 additions & 0 deletions test/stim/passes/test_squin_debug_to_stim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os

from kirin import ir
from kirin.dialects import py, debug

from bloqade.squin import kernel
from bloqade.stim.emit import EmitStimMain
from bloqade.stim.passes import SquinToStimPass


# Taken gratuitously from Kai's unit test
def codegen(mt: ir.Method):
# method should not have any arguments!
emit = EmitStimMain()
emit.initialize()
emit.run(mt=mt, args=())
return emit.get_output()


def as_int(value: int):
return py.constant.Constant(value=value)


def as_float(value: float):
return py.constant.Constant(value=value)


def load_reference_program(filename):
path = os.path.join(
os.path.dirname(__file__), "stim_reference_programs", "debug", filename
)
with open(path, "r") as f:
return f.read()


def test_info():
@kernel
def test():
debug.info("debug message")
return

SquinToStimPass(test.dialects)(test)
base_stim_prog = load_reference_program("debug.stim")
assert codegen(test) == base_stim_prog.rstrip()