-
Notifications
You must be signed in to change notification settings - Fork 27
fix: record an external gate's own depth, not its skipped decomposition's #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryanhill1
wants to merge
3
commits into
main
Choose a base branch
from
fix-external-gate-depth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type: Implementation
Severity: Low
Rationale: This branching arm is reachable but has no observable effect today, and no test covers it.
Evidence: replacing the whole
elsebody withpassleaves the full PR suite green — 718 passed, 4 skipped, and only the two pre-existingtest_cli_commands.pyfailures that also fail on base. Depth was also unchanged across six conditional programs (external gate inif,ctrl @external inif, external plus a second gate inif, external on qubits idle outside the branch, external gate inside an external custom gate inif, and a nestedif) — every one reports2on base, on this PR, and with the arm deleted.The reason is that the arm duplicates marking the validation-only call already performs.
_recording_ext_gate_depthguards only_update_qubit_depth_for_gate(visitor.py:1098); it does not guard_mark_branch_qubit. So the suppressed_visit_basic_gate_operationcall still reaches the branch-marking block at visitor.py:1201-1208 and marks the same qubits.This is worth keeping rather than deleting. The arm becomes load-bearing the moment the suppression is extended to cover branch marking too — which is the natural reading of "suppress depth recording" and a plausible future refactor. Right now nothing pins that behaviour, so a later change could silently regress conditional depth with no test failing.
Change Requested: Add a test that fixes the conditional contract, so the arm is covered and a future change to the guard cannot regress it silently. For example, in
tests/qasm3/test_depth.py, assert that acrzinside anifblock reports the same depth whether or notcrzis external (both are2today), and ideally one case where the external gate acts on qubits untouched outside the branch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in ecd3cf5 — two parametrized cases in
test_depth.py, one with the conditional gate on qubits also used outside the branch and one where it is the only thing touching them. Both assert depth 2 external and non-external.Worth being precise about what they buy, though: I reproduced your
passexperiment and the new tests also pass with the arm neutered, for exactly the reason you gave — the validation-only call still reaches_mark_branch_qubit. So these pin the conditional contract, not the arm's current effect. That is what you asked for and it is the useful half: if someone extends_recording_ext_gate_depthto cover branch marking, the arm becomes load-bearing and these tests start failing if it is wrong. But nothing here would catch the arm being deleted today, and I would rather that be on the record than imply more coverage than exists.