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 potential infinite loop in SabreSwap (backport #7970) #7971

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Apr 21, 2022

This is an automatic backport of pull request #7970 done by Mergify.


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

* Fix potential infinite loop in SabreSwap

This adds a "release valve" mechanism to `SabreSwap`, so that it will
always eventually make forwards progress and terminate the run.  Before
this commit, it was possible for certain pathological circuits
(see `looping_circuit` in `test/python/transpiler/test_sabre_swap.py`
for an example) to get stuck in a stable local minimum of the
'lookahead' or 'decay' heuristics (no matter the weightings).

The release mechanism is done with very small per-loop overhead for the
vastly more common good paths; we simply count how many iterations we
have been through since we made progress, and the minimum weight in the
coupling map to be overcome to make progress again.  Once the
number of iterations without progress exceeds some value, we backtrack
(inefficiently, because this is the bad path) to the last time we made
progress, and forcibly insert swaps to bring the nearest gate together.
We then continue like normal.

There are also a few minor optimisations in this commit that prevent
recalculating sets that we already know; `extended_set` is fixed by
knowledge of the `front_layer` if the DAG isn't (meaningfully) changed,
so there's no need to recalculate it on each loop.

* Reduce depth of greedy swap insertion

* Add link in release note

Co-authored-by: Matthew Treinish <[email protected]>

* Remove extra keyword argument in SabreSwap constructor

The `max_iterations_without_progress` value was originally exposed to
users via the constructor.  It was added because I thought I'd need a
way to force the backtracking algorithm to occur to test the behaviour.
When I wrote the tests, I ended up using Aer to find the keys, which is
sufficiently fast that we can verify validity using the regular infinite
loop circuit, and the argument is unnecessary.  It was highly unlikely
to actually be useful in real applications, so it does not need to be
added.

* Remove useless return from _add_greedy_swaps

Co-authored-by: Matthew Treinish <[email protected]>
(cherry picked from commit f414273)
@mergify mergify bot requested a review from a team as a code owner April 21, 2022 16:01
@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 this to the 0.20.1 milestone Apr 21, 2022
@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog automerge labels Apr 21, 2022
@mergify mergify bot merged commit a75c9a6 into stable/0.20 Apr 21, 2022
@mergify mergify bot deleted the mergify/bp/stable/0.20/pr-7970 branch April 21, 2022 17:14
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants