Repository navigation
Validate Heisenberg programs at construction and index outcomes by symbol - #1028
Merged
Merged
Conversation
6 tasks done
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.
Summary
This prepares
HeisenbergProgram(from #954) for reordering passes. It does not reorder anything itself.A rewrite pass needs to change the order of operations without changing what the program computes. Two things in the phase-1 executor depended on operations staying in compiled order:
AffineSign::evaluatereads them by measurement symbol. Once a measurement moves, later signs read the wrong outcome. Example: inX q0; PZ q0; MZ q1; MZ q0, movingMZ q1ahead of the hidden reset measurement is legal. The finalMZ q0then returned 1 instead of 0.Changes
HeisenbergProgram::with_operations(self, operations) -> Result<Self, ProgramError>is the only way to obtain a program.compilegoes through it, and future rewrite passes will too.ProgramErrorvariant, naming the operation, channel or index involved.compilepanics if its own output fails the check, since that can only be a builder bug.executetrusts a valid program. It stores outcomes atmeasurements[symbol]and records atrecords[ordinal]in plainVec<bool>s, and does no per-shot checks.AffineSign::evaluatekeeps its signature. Its slice is documented as indexed by symbol, which equals execution position in compiled order.compile.Results for compiled programs are unchanged. An independent comparison against the previous executor gave identical
ShotResults, including peak width, on 8,000 shots over random circuits with resets, rotations and noise.Test plan
sin^2(theta/2)readouts and a correlated two-qubit Pauli channel with hand-computed weights.ProgramErrorassertions for every validation rule, distinct messages for every variant, and a check thatcompileoutput validates across 240 random circuits.compile, which no test can expose while the builder is correct; the random-circuit validity test is the guard there.cargo test -p pecos-stab-activedebug and release (64 passed);cargo clippy -p pecos-stab-active --all-targets --all-features -- -D warnings;cargo fmt --check;just lint