Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…tart porting things to MeasureIDAnalysis
… keep some parity with the Bloqade version of Fold et al.
…sis data just not being wrapped properly. Opted for passing dictionary around instead
… the PredicatedID type
| new_block = ir.Block() | ||
| for stmt in node.body.blocks[0].stmts: | ||
| if isinstance(stmt, scf.stmts.Yield): | ||
| continue | ||
| stmt.detach() | ||
| new_block.stmts.append(stmt) | ||
|
|
||
| new_region = ir.Region(new_block) | ||
|
|
||
| # Create the REPEAT statement | ||
| repeat_stmt = cf.stmts.REPEAT( | ||
| count=const_repeat_num.result, | ||
| body=new_region, | ||
| ) | ||
| node.replace_by(repeat_stmt) |
There was a problem hiding this comment.
you should not need to copy the statements over you can first check that all uses of the body's block arguments are the Yield statement, if not you can give up on the rewrite, otherwise you can delete the yield statement then delete the block arguments in-place safely after.
There was a problem hiding this comment.
Wait, I don't think this can be the case though there's definitely uses of the block args beyond just the resulting yield.
The simplest counter example I can give is the repetition code structure test in test_scf_for_to_repeat.py, your block args get touched by other statements in the body (such as measure) and THEN get yielded.
| # coordinates can be a py.Constant with an ilist or a raw ilist | ||
| if not isinstance(node.coordinates.owner, (ilist.New, py.Constant)): |
There was a problem hiding this comment.
This is OK for now but I think it would make sense to add more to the MeasureIDAnalysis to capture coordinates as well. That way we can just pull all this data from the analysis results instead of going through the IR and capturing the values manually from the IR which is more error prone.
This PR enables scf.For statements with the proper format to be represented as a Stim REPEAT statement. There can be no dependence on the iterator variable and the number of iterations must be known at the time of the rewrite.
Per feedback I received from the team presentation and some additional help from Phillip I’ve been able to eliminate the dependency on CSE ordering. CSE can now be invoked at any time in the pass with no impact on the correctness of the resulting program.
That being said, there are definitely areas I’d like to work on to expand the the supported semantics for QEC researchers.
I imagine if the number of iterations is propagated and perhaps some mechanism to accumulate measurements (say, py.binop.add with ilists) is carefully relaxed on invariance checking this could be supportable.
GetItemnaturally complicates things but it would encourage a “lazier” growth of the GlobalRecordState than the current structure.