-
Notifications
You must be signed in to change notification settings - Fork 1
Stim codegen with annotation #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
507d49b
add annotation codegen for stim
kaihsin 5126e6d
add tests
kaihsin 447126c
Merge branch 'main' into khwu/stim_annotate
kaihsin ac09434
add stim file
kaihsin ef83c65
Merge branch 'khwu/stim_annotate' of https://github.com/QuEraComputin…
kaihsin f7bdcf8
Merge branch 'main' into khwu/stim_annotate
kaihsin def9bc1
Merge branch 'main' into khwu/stim_annotate
kaihsin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 () | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
| # debug message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.