fix: don't overwrite unrelated CAPTURE memory reference when expanding measure calibrations - #531
Open
0xhokugava wants to merge 2 commits into
Open
0xhokugava wants to merge 2 commits into
0xhokugava wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
Body
Fixes #499
Problem
When expanding a
DEFCAL MEASUREcalibration,Calibrations::expand_innerunconditionallyrewrote the
memory_referenceof everyCAPTUREinstruction in the calibration body tothe target of the
MEASUREbeing expanded even when thatCAPTUREhad nothing to do withthe calibration's declared target parameter.
The sibling
PRAGMA LOAD-MEMORYbranch right above it already guards this substitution withpragma.data == calibration.identifier.target; theCAPTUREbranch was missing the same check.In realistic calibrations (see this repo's own
benches/sample-calibrations.quil),CAPTUREwrites raw IQ data to an intermediate/unclassified memory region, and the actual routing to the
calibration's target happens later via a
PRAGMA FILTER-NODE/PRAGMA LOAD-MEMORYclassifierpipeline. The bug redirected that raw capture straight into the final (classified) register, e.g.:
Fix
Add the same target-name guard to the
Capturearm that thePragmaarm already has: only rewritecapture.memory_referencewhen it equalscalibration.identifier.target.Testing
measure_calibration_does_not_overwrite_unrelated_capture_memory_reference, reproducing the bug against a realistic calibration shape (asserts theCAPTUREkeeps its own memory region after expansion).test_expansionsnapshot caseMeasure-Calibration-Capture-Memory-Referencecovering both branches in one calibration: aCAPTUREtargeting an unrelated region is left untouched, while aCAPTUREthat does target the declared parameter is correctly substituted.cargo fmt --all -- --checkandcargo clippy --workspace --all-targets --all-features -- -D warnings: clean.cargo test(workspace): all 2977 tests + doctests green, no snapshot regressions.cargo make test-quil(quil-pypytest+stubtest): green. The fix touches nopub/pyclass/pymethodssurface, so no Python-facing behavior or types change beyond the corrected runtime output.Known limitations / open questions for reviewers
CAPTUREoverwrite. It does not address a related gap also visible in the issue's own repro: a calibration that routes its result via e.g.MOVE addr[0] ...(rather than throughPRAGMA LOAD-MEMORYor a directly-matchingCAPTURE) still won't have that reference substituted at all. That seems like a broader question - should target substitution walk every instruction/operand referencing the formal target parameter, not just these two special-cased instruction kinds and felt out of scope for this fix. Happy to open a follow-up issue if that's worth tracking separately.scripts/check-quil-api.shto completion locally (missing theknopebinary), so I couldn't fully reproduce the CIcheck-apigate. The diff here touches no public API surface, so I don't expect it to flag anything, but wanted to call this out rather than claim a check I couldn't actually finish running.This is my first contribution to
quil-rsso feedback very welcome, especially on whether the target-matching approach here is the right mental model for howDEFCAL MEASUREsubstitution is supposed to work.