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 StochasticSwap routing for if blocks with no else #8891

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

jakelishman
Copy link
Member

@jakelishman jakelishman commented Oct 13, 2022

Summary

If a control-flow block is not required to be entered (such as an "if" with no "else"), then it can't affect the layout in case the branch isn't taken. This failure would have been clearer in a more control-flow-graph view of the circuit, but we don't yet have that, which is how this bug snuck through. The case of "exit layout need not match entry layout" is really the special case for routing, which this commit makes a bit clearer.

Details and comments

This should also go into 0.22.

The diff looks funkier than it actually is - in reality, the old _route_control_flow_looping got removed, and _route_control_flow_multiblock (with the addition of a maintain_layout switch) got inlined into _control_flow_layer_update, since the split no longer made sense.

If a control-flow block is not required to be entered (such as an "if"
with no "else"), then it can't affect the layout in case the branch
isn't taken.  This failure would have been clearer in a more
control-flow-graph view of the circuit, but we don't yet have that,
which is how this bug snuck through.  The case of "exit layout need not
match entry layout" is really the special case for routing, which this
commit makes a bit clearer.
@jakelishman jakelishman added the Changelog: None Do not include in changelog label Oct 13, 2022
@jakelishman jakelishman added this to the 0.22 milestone Oct 13, 2022
@jakelishman jakelishman requested a review from a team as a code owner October 13, 2022 10:36
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

@jakelishman jakelishman added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Oct 13, 2022
@jakelishman jakelishman mentioned this pull request Oct 13, 2022
5 tasks
@coveralls
Copy link

Pull Request Test Coverage Report for Build 3241648236

  • 18 of 20 (90.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 84.753%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/routing/stochastic_swap.py 18 20 90.0%
Totals Coverage Status
Change from base Build 3238371939: 0.1%
Covered Lines: 61902
Relevant Lines: 73038

💛 - Coveralls

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, I think the diff was hard to follow, which just looks like it's caused by things moving around. But the key change seemed to be fairly straightforward as this just combines _route_control_flow_looping and _route_control_flow_multiblock into a single method and does the multiblock handling/optimization inline iff we're evaluating an if/else op with an else block populated (instead of unconditionally for all if/else blocks). This makes sense to me and I didn't catch anything weird looking that I could see in the diff. Plus all the existing tests still pass and we've ramped up the testing quite a bit in recent PRs, so I think this is good to go.

@mergify mergify bot merged commit 35c4b00 into Qiskit:main Oct 13, 2022
mergify bot pushed a commit that referenced this pull request Oct 13, 2022
If a control-flow block is not required to be entered (such as an "if"
with no "else"), then it can't affect the layout in case the branch
isn't taken.  This failure would have been clearer in a more
control-flow-graph view of the circuit, but we don't yet have that,
which is how this bug snuck through.  The case of "exit layout need not
match entry layout" is really the special case for routing, which this
commit makes a bit clearer.

(cherry picked from commit 35c4b00)
@jakelishman jakelishman deleted the fix-routing-if-no-else branch October 13, 2022 13:33
mergify bot added a commit that referenced this pull request Oct 13, 2022
If a control-flow block is not required to be entered (such as an "if"
with no "else"), then it can't affect the layout in case the branch
isn't taken.  This failure would have been clearer in a more
control-flow-graph view of the circuit, but we don't yet have that,
which is how this bug snuck through.  The case of "exit layout need not
match entry layout" is really the special case for routing, which this
commit makes a bit clearer.

(cherry picked from commit 35c4b00)

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in 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.

4 participants