-
Notifications
You must be signed in to change notification settings - Fork 1
squin to stim rewrite #148
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
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
|
Hi @Roger-luo , I believe what you see here should be a decent first pass with me trying to work with a bit of a mismatch in terms of how squin can be mapped to the existing stim dialect. Feel free to let me know what you think would be acceptable additions to either dialect based on my observations below, I can gladly spin that out as a separate PR/RFC. I haven't taken advantage of the site analysis results just yet but it should be very easy for me to implement, I just wanted to make sure the analyses and overall rewrite behavior were (mostly) correct.
|
Yeah, can you start an RFC issue for reset? I think reset needs some more thoughts. I think for the first pass, we can just skip those doesn't match well - squin is more expressive so not everything can be compiled into stim. |
|
xref #25 I realize we need a codegen for stim instead of a rewrite. And to make the UX better, we need a separate analysis pass to validate all possible incompatibility of stim when compiling from squin. |
I think this partly resolves the ongoing thread between myself, @ChenZhao44 and @weinbe58 over handling the friction from the fact that I know @ChenZhao44 was advocating for just throwing an exception and killing the rewrite if it detected any form of squin measurement being depended on while @weinbe58 pointed out it would be more proper to just "let it slide" and say no rewrite happened but let emission choke on it instead. @weinbe58 also suggested potentially "manipulating" the squin measurement result if it's being returned to something like "None" @Roger-luo has pointed out this easily violates the original intent of the function (and I'm sure causes even more problems downstream). I support @Roger-luo 's direction here as well as the result of @kaihsin 's and @weinbe58 's conversations that codegen seems more sensible here. |
|
so rewrites technically are no-raise because the rewrite rules happens only when we are sure about the equivalence. If it cannot perform the rewrite, it will not be applied to the code instead of throwing an exception. So does codegen - we want to be able to catch as many issues as we can before running any codegen or rewrite so we can have a nice error message. This is kinda true for all the possible codegen/rewrite because you rely on compile-time info to do these codegen/rewrite. I think it's always good practice to do around of validation to be certain on the entire program before mutating/generating the code that one intends to do. |
|
I mean we could raise within a rewrite rule, I kinda understand that is convenience to work with, but on the other hand, it will be nasty for a user because now validation is coupled with rewrite, and this would terminate rewrite process - meaning if there are multiple errors, one have to keep trying and failing until all errors are being address-ed, when all errors are technically possible to be addressed in one-go with an analysis. |
|
Got it 👍 I'll open up an issue to sketch out/track progress on the analysis passes to catch Stim-incompatible squin programs |
|
I believe this rewrite now accepts Broadcast as well as changes from #158. This will probably have to change once #265 goes through but I don't think it will be too drastic a change. There are a couple things (ordered in what I believe is the correct priority) I think need to be done as well from my notes in talking with @ChenZhao44
|
…without blind deletion
|
The stim codegen keeps complaining about duplicate registered methods for lowering constants? I also realize I could definitely split out more of the rewrite logic into their own rules considering how much duplicate logic there is (with just a small variation required to handle address type extraction and wire routing). Probably worth a separate PR but in the interest of time I won't do it here (unless indicated otherwise!) |
kaihsin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave some comments. The question I have is which dialect that attribute should go to, but I don't think its a blocker.
| from bloqade.squin.analysis.nsites import Sites | ||
|
|
||
|
|
||
| @wire.dialect.register |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this only register to wire? or qubit dialect also need this? @Roger-luo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me considering wire's Apply, Broadcast, and MeasureAndReset will return things whereas qubit doesn't. I haven't run into a case where the analysis fails on the qubit dialect.
No description provided.