Skip to content

"swap followed by measure" optimization pass#1890

Merged
1ucian0 merged 61 commits into
Qiskit:masterfrom
1ucian0:swap_measure_simplification_pass
Apr 10, 2019
Merged

"swap followed by measure" optimization pass#1890
1ucian0 merged 61 commits into
Qiskit:masterfrom
1ucian0:swap_measure_simplification_pass

Conversation

@1ucian0
Copy link
Copy Markdown
Member

@1ucian0 1ucian0 commented Mar 4, 2019

This PR goes on top of #1889

Removes the swap before the measurement.

Copy link
Copy Markdown
Member

@ajavadia ajavadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some problems with this pass. It should only remove swap gates that are followed by measure on both wires. So this is a valid optimization (second test case):

            qr0:--X--m--         qr0:--m----
                  |  |                 |
            qr1:--X--|--m   ==>  qr1:--|--m-
                     |  |              |  |
            cr0:-----.--|--      cr0:--|--.-
            cr1:--------.--      cr1:--.----

However the 1st and 4th test cases are not valid transformations:

            qr0:--X--m--       qr0:----
                  |  |
            qr1:--X--|--  ==>  qr1:--m-
                     |               |
            cr0:-----.--       cr0:--.-
            qr0:--X--------       qr0:--m--
                  |                     |
            qr1:--X--X-----       qr1:--|--
                     |       ==>        |
            qr2:-----X--m--       qr2:--|--
                        |               |
            cr0:--------.--       cr0:--.--

Here the qubits that are not measured live on, and by removing the swap, you invalidate their permutation due to that swap. So this can only be done when we are left with classical bits, in which case we can retarget the measurements (modify their clbit target), and remove the swap.

Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py Outdated
Comment thread qiskit/transpiler/passes/optimize_swap_before_measure.py
Comment thread test/python/transpiler/test_optimize_swap_before_measure.py Outdated
@ajavadia ajavadia self-assigned this Mar 11, 2019
Co-Authored-By: 1ucian0 <luciano@debian.org>
@ajavadia
Copy link
Copy Markdown
Member

ajavadia commented Apr 8, 2019

two files must be removed from this PR:
qiskit/transpiler/passes/count_operations.py and its test

@1ucian0
Copy link
Copy Markdown
Member Author

1ucian0 commented Apr 8, 2019

Fixed. I also moved the fixed point to check the DAG instead of counting ops.

ajavadia
ajavadia previously approved these changes Apr 10, 2019
@ajavadia
Copy link
Copy Markdown
Member

Can you add a changelog line for this as well? Approved.

@1ucian0 1ucian0 merged commit fbcd1a8 into Qiskit:master Apr 10, 2019
@1ucian0 1ucian0 deleted the swap_measure_simplification_pass branch April 10, 2019 02:34
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants