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 control-flow routing in StochasticSwap (backport #8880) #8888

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Oct 12, 2022

This is an automatic backport of pull request #8880 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

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
* Fix control-flow routing in StochasticSwap

The `StochasticSwap` pass has some fairly complex hand-offs between
different parts of its API, including in recursive calls and the regular
hand-off between Python and Rust.  In the course of adding the
control-flow support, some of these became muddled, and the mapping
between different virtual/physical/integer representations got mixed up,
resulting in invalid swaps being output in the final circuit.

This commit simplifies much of the internal mapping, removing many
superfluous `DAGCircuit` creations and compositions.  This also removes
instances where two layouts were "chained"; this was not well typed (the
output of a "virtual -> physical" mapping can't be the input for another
"virtual -> physical" mapping), and in general was being used to "undo"
some of compositions that were about to be applied.

This fixes a tacit assumption in the original code that the initial
layout was a trivial layout in the hand-off between Rust and Python.
This worked until the recursive call added the `initial_layout` option,
making this assumption invalid. Previously, virtual qubit bit instances
were converted to integers (to allow them to be passed to Rust) using
their indices into the original DAG, but the integer outputs were then
converted _back_ using the `initial_layout`.  In the old form, this
worked anyway, but wasn't logically correct and consequently broke when
the assumptions about `initial_layout` changed.

For the recursive calls, we now ensure that the inner passes are
essentially created with the same internal structure as the outer pass;
the passed in `DAGCircuit` uses the same bit instances and same meaning
of the virtual qubits as the outer circuit, and the `initial_layout`
ensures that the inner passes start with at the same layout as the outer
pass.  This makes the inner passes more like a logical continuation of
the current operation, rather than a completely separate entity that
needs to have its virtual qubits remapped.

The changes to the tests are twofold:

- move the `CheckMap` calls earlier and apply them directly to the
  `StochasticSwap` output rather than the expected circuit, to improve
  the quality of failure error messages

- use the same physical qubits inside the expected control-flow blocks;
  the new simpler form of doing the circuit rewriting internally in the
  pass ensures that the same bit objects are used all the way through
  the control-flow stack now, rather than creating new instances.

* Add tests for stochastic swap valid output

This commit adds full path transpile() tests for running with stochastic
swap that validates a full path transpilation outputs a valid physical
circuit. These tests are purposefully high level to provide some
validation that stochastic swap is not creating invalid output by
inserting incorrect swaps. It's not meant as a test of valid unitary
equivalent output of the full transpilation.

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit b3cf64f)
@mergify mergify bot requested a review from a team as a code owner October 12, 2022 21:15
@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

@mtreinish mtreinish added automerge Changelog: None Do not include in changelog labels Oct 12, 2022
@mtreinish mtreinish added this to the 0.22 milestone Oct 12, 2022
@jakelishman jakelishman mentioned this pull request Oct 12, 2022
5 tasks

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@mergify mergify bot merged commit aca6d67 into stable/0.22 Oct 13, 2022
@mergify mergify bot deleted the mergify/bp/stable/0.22/pr-8880 branch October 13, 2022 00:45
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants