Add support for PREPARE block in stim#3409
Open
joao-boechat wants to merge 9 commits into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add support for
PREPAREblocks in StimSummary
Adds a
PREPARE { ... }block to the Stim front end: a repeat-until-success region used to deterministically prepare a state that otherwise only occurs probabilistically. This replaces the previous#!preselect_*comment-annotation mechanism.How it works
PREPAREblock runs its body, then re-runs the entire block until everyREQUIREinside it is satisfied.REQUIRE rec[-1] rec[-2] ...reads measurement records (indexed backwards from the most recent measurement) and combines them by XOR (parity). If the parity is1the block restarts; if0execution continues.REQUIRE !rec[-1]), which flips that record's contribution to the parity — i.e. it requires the record to be1instead of0.prepare_N) plus a conditional branch back to it.REQUIREmay only reference records produced inside its own enclosing block; nested blocks are supported.Modifications
qir.rs— lowering forPREPARE/REQUIRE: prepare/continue labels, measurement-record resolution with scope tracking, XOR parity fold, negation (xor … , true), and new diagnostics (RequireOutsidePrepareBlock,MeasurementRecordOutOfBounds,MeasurementRecordOutOfScope).parser.rs— parsePREPAREblocks andREQUIRE; allow negation on measurement-record targets.lex.rs— drop the old#!preselect-annotation lexing.qir/tests/prepare_block.rsand parser target tests; removed the obsoleteqir/tests/preselect.rs.samples/notebooks/stim_prepare.ipynbdemonstrating preselection, negated requirements, multiple/parity requirements, and nested blocks.