-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
LookaheadSwap never swaps back #10145
Comments
The same thing happens with |
This is expected behaviour - if you look at We do this because the situation you're asking for is more computationally expensive and generally unnecessary for execution of a complete circuit on hardware; the compiler tracks the virtual->physical layout throughout the circuit execution (it changes over the course of a circuit, typically), and ensures that gates and measures are inserted on the correct physical qubits. The compiler is only designed to operate on complete circuits, not subcomponents of one, and the final qubit layout is unobservable - only measurement results are, and we ensure that we map measures into the correct bits. |
Makes sense, thanks for spelling that out. |
I did notice that In the case of c1 = QuantumCircuit(3)
c1.cnot(0, 2)
coupling_map = CouplingMap([[0, 1], [1, 2]])
c2 = transpile(c1, coupling_map=coupling_map)
print(c2.layout.final_layout is None) # True When I use coupling_map = CouplingMap([[0, 1], [1, 2]])
c2 = transpile(c1, coupling_map=coupling_map)
to_layout = Layout.generate_trivial_layout(*c2.qregs)
c3 = LayoutTransformation(coupling_map, c2.layout.final_layout, to_layout)(c2)
print(Operator(c1).equiv(Operator(c2))) # False
print(Operator(c1).equiv(Operator(c3))) # Depends on input so that takes care of that. But I might have expected |
Sorry for the very slow reply here. If you run a transpiler routing pass manually, then the final layout will be present in the |
For your second question about In your examples, the transpiler is also almost certainly not requiring any routing (hence |
Environment
What is happening?
The pass
qiskit.transpiler.passes.routing.lookahead_swap.LookaheadSwap
produces circuits that are not equivalent to the input circuit, since it never swaps back qubits. This becomes an issue if you want to compose multiple such circuits, if you don't want to keep track of the swaps yourself somehow, or just in general if you want to count the cost of swapping back.But maybe this is just working as intended; a note somewhere in the docs might be useful in that case. Moreover, if the intention is that one manually swaps back at the end, the final permutation should be available somehow (either through the pass itself, or when using it through, say,
qiskit.compiler.transpile
).How can we reproduce the issue?
What should happen?
It shouldn't be necessary to add the
c2.swap(0, 1)
by hand.Any suggestions?
No response
The text was updated successfully, but these errors were encountered: