Repository navigation
Add measurements without discard and index classical bits by measurement - #644
Open
thierry-martinez wants to merge 5 commits into
Open
thierry-martinez wants to merge 5 commits into
thierry-martinez wants to merge 5 commits into
Conversation
`Instruction.M` gets a keyword-only attribute `discard` (default `True`), exposed by `Circuit.m(..., discard=...)`. With `discard=False`, the measured qubit stays active, in the eigenstate corresponding to the outcome. Since a qubit can now be measured several times, the domains of `CONDINSTR` refer to classical bits instead of measured qubits: bit `i` is the outcome of the `i`-th measurement (`Circuit.measurement_count`). This also fixes TeamGraphix#640: `transpile_swaps` renames qubits, but domains no longer refer to qubits. - `transpile_discard` replaces measurements without discard with measurements with discard followed by the preparation of a fresh ancilla in the corresponding eigenstate; `Circuit.transpile` applies it automatically. - `Circuit.simulate` and `transpile_to_qasm_gates` support measurements without discard. - QASM export of instructions becomes a method of `ToQASM3`, which keeps track of the next classical bit; measurement statements are now terminated by a semicolon. - `Circuit.visit(copy=True)`, `transpile_ancilla_state` and `transpile_swaps(copy=False)` keep the validator state in sync. - `DataclassReprMixin` always names keyword-only fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #644 +/- ##
==========================================
+ Coverage 89.98% 90.05% +0.06%
==========================================
Files 49 49
Lines 8447 8524 +77
==========================================
+ Hits 7601 7676 +75
- Misses 846 848 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
To explore further: reset instructions |
matulni
self-requested a review
November 4, 2026 08:29
Collaborator
Author
|
I opened the issue #648 for reset instructions. |
matulni
reviewed
Nov 5, 2026
matulni
left a comment
Contributor
There was a problem hiding this comment.
Thanks for this addition!
- `transpile_discard` becomes a method of `Circuit`, like the other `transpile_*` methods. It appends SWAP gates that restore the order of the output qubits, so the result has the same semantics as the original circuit, and `TranspileDiscardResult` is removed. - The method always returns a new circuit, even when there is no measurement without discard. - The new method `Circuit.reorder_active_qubits_with_swaps` appends these SWAP gates. `Pattern.to_circuit` uses it too. - Ancillas are transpiled to |+> only if they are in another state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matulni
approved these changes
Nov 9, 2026
matulni
left a comment
Contributor
There was a problem hiding this comment.
Thank you for the mods. LGTM!
Co-authored-by: Mateo Uldemolins <m.uldemolins@gmail.com>
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.
Instruction.Mgets a keyword-only attributediscard(defaultTrue), exposed byCircuit.m(..., discard=...). Withdiscard=False, the measured qubit stays active, in the eigenstate corresponding to the outcome.Since a qubit can now be measured several times, the domains of
CONDINSTRrefer to classical bits instead of measured qubits: bitiis the outcome of thei-th measurement (Circuit.measurement_count). This also fixes #640:transpile_swapsrenames qubits, but domains no longer refer to qubits.transpile_discardreplaces measurements without discard with measurements with discard followed by the preparation of a fresh ancilla in the corresponding eigenstate;Circuit.transpileapplies it automatically.Circuit.simulateandtranspile_to_qasm_gatessupport measurements without discard.ToQASM3, which keeps track of the next classical bit; measurement statements are now terminated by a semicolon.Circuit.visit(copy=True),transpile_ancilla_stateandtranspile_swaps(copy=False)keep the validator state in sync.DataclassReprMixinalways names keyword-only fields.