Repository navigation
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.
Fixes #978.
Problem
The SLR Stim backend compiled
Ifby emitting the then-body (and the else-body) unconditionally, discarding the condition. A measurement-conditioned correction was applied on every shot. The deprecatedStimGeneratorhad the same behavior.Fix
Stim applies Pauli gates classically controlled by a measurement record (
CX rec[-k] qapplies X to q exactly when that measurement was 1), so the dominant case compiles faithfully:X/Y/Zgates (optionally insideParallel, with comments) conditioned on one measured bit --c[i],c[i] == 0/1, orc[i] != 0/1-- lowers toCX/CY/CZ rec[-k] q. A condition that selects bit value 0 applies the Pauli unconditionally and then again under the record control, which cancels it when the bit is 1.k, the backend tracks which measurement record each classical bit holds. AREPEATbody is its own record frame: a condition inside it can only read a bit measured earlier in the same iteration (an outer record's offset changes every iteration), and after the block a bit written in the body refers to the last iteration's measurement.NotImplementedError: an else-body, a non-Pauli body, a register-level or compound condition, a bit with no measurement in scope, and a bit whose value no longer comes from a measurement (classical assignment, or any register named by aPermute, since Permute refs carry no qubit/classical kind and SLR allows a qubit and a classical register to share a name).Qubit
Permutehandling is unchanged. The deprecatedStimGeneratornow raises onIfand points topecos.slr.generate(prog, "stim").Tests
TestAstToStimConditionalsuses Stim's own sampler as the oracle: each program measures a random bit and conditionally corrects another qubit, and the test checks the correction fires on exactly the selected shots. Coverage includes every supported condition form for X and Y, Z observed in the X basis, re-measured bits, lookbacks pastrec[-1]at top level and insideREPEAT, conditions after aREPEAT, and each rejection path including invalidation carried out of aREPEATbody. A regression test checks that a qubitPermutestill applies when a classical register shares its name.Every new test fails against the previous implementation, and targeted mutations of the lookback arithmetic, last-iteration offset, frame reset, and each invalidation path are each caught.
tests/pecos/slr,tests/slr_tests,tests/selene/test_hugr_to_ast.py: 1241 passed, 4 skippedOut of scope
A qubit
Permuteinside aRepeatbody is compiled for a single iteration (pre-existing ondev, independent ofIf); tracked in #992.