-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
SabreSwap
can reorder operations that depend on the same classical bit
#7950
Comments
Previously, SabreSwap only checked that it was valid to add a gate back to the DAG by ensuring that all its qubit predecessors had already been added to the DAG. It did not check for clbit successors. This meant that measurements and (potentially, unverified) classically conditioned gates could be re-ordered out from the correct topological ordering. The most notable effect of this was that measurements writing to the same bit could be re-ordered, changing the output of the circuit. See Qiskitgh-7950 for more detail.
I think you're correct here. The other routing passes work over the dag in topological order directly (well typically they either use |
* Make SabreSwap account for clbits in predecessors Previously, SabreSwap only checked that it was valid to add a gate back to the DAG by ensuring that all its qubit predecessors had already been added to the DAG. It did not check for clbit successors. This meant that measurements and (potentially, unverified) classically conditioned gates could be re-ordered out from the correct topological ordering. The most notable effect of this was that measurements writing to the same bit could be re-ordered, changing the output of the circuit. See gh-7950 for more detail. * Add reno * Fix lint * Trim fat in SabreSwap._successors Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Fix _successors method Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Make SabreSwap account for clbits in predecessors Previously, SabreSwap only checked that it was valid to add a gate back to the DAG by ensuring that all its qubit predecessors had already been added to the DAG. It did not check for clbit successors. This meant that measurements and (potentially, unverified) classically conditioned gates could be re-ordered out from the correct topological ordering. The most notable effect of this was that measurements writing to the same bit could be re-ordered, changing the output of the circuit. See gh-7950 for more detail. * Add reno * Fix lint * Trim fat in SabreSwap._successors Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Fix _successors method Co-authored-by: Matthew Treinish <mtreinish@kortar.org> (cherry picked from commit 38f3705)
* Make SabreSwap account for clbits in predecessors Previously, SabreSwap only checked that it was valid to add a gate back to the DAG by ensuring that all its qubit predecessors had already been added to the DAG. It did not check for clbit successors. This meant that measurements and (potentially, unverified) classically conditioned gates could be re-ordered out from the correct topological ordering. The most notable effect of this was that measurements writing to the same bit could be re-ordered, changing the output of the circuit. See gh-7950 for more detail. * Add reno * Fix lint * Trim fat in SabreSwap._successors Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Fix _successors method Co-authored-by: Matthew Treinish <mtreinish@kortar.org> (cherry picked from commit 38f3705) Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Environment
What is happening?
SabreSwap
can re-order measurement operations (and probably classically conditioned gates) that write to the same classical bits. This affects optimisation level 3 by default, since it uses sabre to route if nothing else is provided.I am 95% sure this is the cause of the failures we're seeing in the randomised test suite currently.
Expand for logs of recent failed randomised run
Hypothesis failure at commit 618e0ea, in file `test/randomized/test_transpile_equivalence.py`How can we reproduce the issue?
Given a circuit:
which has a drawing
Clearly the output of the circuit should always be 0, because qubit 1 is never altered, and is measured second.
If we transpile it with a special coupling map that essentially only has one valid routing for the default decomposition of ccx, the orders of the measurements get flipped, which Aer confirms:
This produces, for example:
but the second dictionary should be the same as the first.
(It's too long to draw
transpiled
here, but if you do it locally, you can see the measurements are swapped.)What should happen?
Sabre should take into account the topological ordering of measurements (and other clbits). In the above examples, the counts should both be
{'0': 1024}
(which they are for any other routing method).Any suggestions?
In both
SabreSwap._successors
and._is_resolved
, only the quantum bits are accounted for. My very very rough intuition for what's going on makes it feel like it should account for all successors, not just qubits.The text was updated successfully, but these errors were encountered: