Skip to content
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

Fix final_layout when VF2PostLayout finds a better layout #10466

Merged
merged 7 commits into from
Jul 24, 2023

Conversation

mtreinish
Copy link
Member

Summary

This commit fixes a bug in the preset pass managers when VF2PostLayout is run and finds a better layout to use. In these cases the ApplyLayout was updating the layout but we never updated the final layout to reflect these changes. This would result in an incorrect final layout because the input positions of the qubits were incorrect after re-applying the layout. This commit fixes this by adding code to ApplyLayout to also update final_layout, if one is set, to reflect the new initial layout found by VF2PostLayout.

Details and comments

Fixes #10457

This commit fixes a bug in the preset pass managers when VF2PostLayout
is run and finds a better layout to use. In these cases the ApplyLayout
was updating the layout but we never updated the final layout to reflect
these changes. This would result in an incorrect final layout because
the input positions of the qubits were incorrect after re-applying the
layout. This commit fixes this by adding code to ApplyLayout to also
update final_layout, if one is set, to reflect the new initial layout
found by VF2PostLayout.

Fixes Qiskit#10457
@mtreinish mtreinish requested a review from a team as a code owner July 21, 2023 17:58
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Deprecation Include in "Deprecated" section of changelog labels Jul 21, 2023
@mtreinish mtreinish added this to the 0.25.0 milestone Jul 21, 2023
@coveralls
Copy link

coveralls commented Jul 21, 2023

Pull Request Test Coverage Report for Build 5648970491

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 20 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.007%) to 85.926%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
qiskit/pulse/library/waveform.py 3 93.75%
crates/qasm2/src/lex.rs 4 90.89%
crates/qasm2/src/parse.rs 12 97.11%
Totals Coverage Status
Change from base Build 5646134740: -0.007%
Covered Lines: 73030
Relevant Lines: 84992

💛 - Coveralls

@mtreinish mtreinish added Changelog: Bugfix Include in the "Fixed" section of the changelog and removed Changelog: Deprecation Include in "Deprecated" section of changelog labels Jul 21, 2023
qiskit/transpiler/passes/layout/apply_layout.py Outdated Show resolved Hide resolved
test/python/compiler/test_transpiler.py Outdated Show resolved Hide resolved
test/python/transpiler/test_apply_layout.py Outdated Show resolved Hide resolved
test/python/transpiler/test_apply_layout.py Show resolved Hide resolved
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -94,6 +96,13 @@ def run(self, dag):
qargs = [q[new_virtual_to_physical[qarg]] for qarg in node.qargs]
new_dag.apply_operation_back(node.op, qargs, node.cargs)
self.property_set["layout"] = full_layout
if (final_layout := self.property_set["final_layout"]) is not None:
Copy link
Member

Choose a reason for hiding this comment

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

et tu?

Pacific_Walrus_-Bull(8247646168)

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh, I was wondering if you'd notice, figured I'd give it a try :D

Copy link
Member

Choose a reason for hiding this comment

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

I apparently didn't notice it the first time I read it, but saw it when I was checking the changes haha.

@jakelishman jakelishman added this pull request to the merge queue Jul 24, 2023
Merged via the queue into Qiskit:main with commit 42a0ee8 Jul 24, 2023
mergify bot pushed a commit that referenced this pull request Jul 24, 2023
* Fix final_layout when VF2PostLayout finds a better layout

This commit fixes a bug in the preset pass managers when VF2PostLayout
is run and finds a better layout to use. In these cases the ApplyLayout
was updating the layout but we never updated the final layout to reflect
these changes. This would result in an incorrect final layout because
the input positions of the qubits were incorrect after re-applying the
layout. This commit fixes this by adding code to ApplyLayout to also
update final_layout, if one is set, to reflect the new initial layout
found by VF2PostLayout.

Fixes #10457

* Remove stray debug print

* Use a list instead of a dict

* Add assertion on vf2postlayout being used in compiler.transpile tests

* Actually assert a post layout is set

(cherry picked from commit 42a0ee8)
@mtreinish mtreinish deleted the fix-final-layout-with-vf2-post branch July 25, 2023 00:49
github-merge-queue bot pushed a commit that referenced this pull request Jul 25, 2023
…10493)

* Fix final_layout when VF2PostLayout finds a better layout

This commit fixes a bug in the preset pass managers when VF2PostLayout
is run and finds a better layout to use. In these cases the ApplyLayout
was updating the layout but we never updated the final layout to reflect
these changes. This would result in an incorrect final layout because
the input positions of the qubits were incorrect after re-applying the
layout. This commit fixes this by adding code to ApplyLayout to also
update final_layout, if one is set, to reflect the new initial layout
found by VF2PostLayout.

Fixes #10457

* Remove stray debug print

* Use a list instead of a dict

* Add assertion on vf2postlayout being used in compiler.transpile tests

* Actually assert a post layout is set

(cherry picked from commit 42a0ee8)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
to24toro pushed a commit to to24toro/qiskit-terra that referenced this pull request Aug 3, 2023
* Fix final_layout when VF2PostLayout finds a better layout

This commit fixes a bug in the preset pass managers when VF2PostLayout
is run and finds a better layout to use. In these cases the ApplyLayout
was updating the layout but we never updated the final layout to reflect
these changes. This would result in an incorrect final layout because
the input positions of the qubits were incorrect after re-applying the
layout. This commit fixes this by adding code to ApplyLayout to also
update final_layout, if one is set, to reflect the new initial layout
found by VF2PostLayout.

Fixes Qiskit#10457

* Remove stray debug print

* Use a list instead of a dict

* Add assertion on vf2postlayout being used in compiler.transpile tests

* Actually assert a post layout is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VF2PostLayout corrupts final_layout output
4 participants