-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in OptimizeSwapBeforeMeasure (#11413)
* fixed bug in OptimizeSwapBeforeMeasure #11195 * fix lint issue (cherry picked from commit 3551c7c)
- Loading branch information
1 parent
ef21b50
commit 8428277
Showing
3 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
44 changes: 44 additions & 0 deletions
44
releasenotes/notes/fix-optimize-swap-before-measure-67e8896da2215d49.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed an issue with the :class:`~.OptimizeSwapBeforeMeasure` pass where | ||
it would incorrectly optimize circuits involving swap and measure | ||
instructions. This commit fixes the bug by changing `DAGCircuit.successors` | ||
to `DAGCircuit.descendants`. Also, added a couple of extra tests to ensure | ||
that the bug is fixed. For example:: | ||
from qiskit import QuantumCircuit | ||
from qiskit.transpiler.passes import OptimizeSwapBeforeMeasure | ||
pass_ = OptimizeSwapBeforeMeasure() | ||
qc = QuantumCircuit(2, 1) | ||
qc.swap(0, 1) | ||
qc.measure(0, 0) | ||
qc.measure(0, 0) | ||
print(qc.draw()) | ||
print(pass_(qc).draw()) | ||
would previously print:: | ||
┌─┐┌─┐ | ||
q_0: ─X─┤M├┤M├ | ||
│ └╥┘└╥┘ | ||
q_1: ─X──╫──╫─ | ||
║ ║ | ||
c: 1/════╩══╩═ | ||
0 0 | ||
┌─┐ | ||
q_0: ┤M├─── | ||
└╥┘┌─┐ | ||
q_1: ─╫─┤M├ | ||
║ └╥┘ | ||
c: 1/═╩══╩═ | ||
0 0 | ||
and now the second ciruit is correctly optimized to:: | ||
q_0: ────── | ||
┌─┐┌─┐ | ||
q_1: ┤M├┤M├ | ||
└╥┘└╥┘ | ||
c: 1/═╩══╩═ | ||
0 0 |
This file contains 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