-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Option for skipping OptimizeSwapBeforeMeasure when not all the wires are measured. #5890
Conversation
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.
Code changes look good. One question generally. Would it be more inline with the direction of #4608 to have this pass switch the order of the swap
and measure
instructions, instead of removing the swap
? That would preserve the the layout in all cases and still allow the optimization in cases where only some of the qubits are measured.
For example:
Does this make sense? |
I had been thinking something even simpler, I think. For the circuit above, I'd expect an output (after one iteration) like
But looking at the behavior from master, I wonder if there isn't already a bug here with mid-circuit measurements.
doesn't look right to me. I'd expect (regardless of how the optimization is done) for there to be at least one measurement between the first H-X and second H-X. |
qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py
Outdated
Show resolved
Hide resolved
I don't understand what |
…sure.py Co-authored-by: Ali Javadi-Abhari <[email protected]>
This appears stale to me now with all its conflicts, and no longer really as in line with how we treat layouts, routings, and the responsibilities of the preset pass managers. I'll close it as staled, but feel free to re-open if there's more to do here. |
Summary
This PR extends
OptimizeSwapBeforeMeasure
to only remove swaps when both wires are measured. Instead of changing the default behaviour, I added a parameter for backwards compatibility (and in case we want to change it back for some transpilation cases). WhenOptimizeSwapBeforeMeasure
is used in level 3, the option is activated. This fixes #4911Details and comments
When the SWAP should not be remove
When the SWAP can be removed: