You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix control-flow routing in StochasticSwap (#8880) (#8888)
* 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)
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
0 commit comments