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

Undoing swappers with LayoutTransformation #5280

Closed
wants to merge 24 commits into from
Closed

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented Oct 23, 2020

Fixes #4911
Fixes #4608

At the moment, only the combination BasicSwap and optimization_level=1 is supported.

Let's take this example:

from numpy import pi
from qiskit import QuantumCircuit
from qiskit.compiler import transpile
from qiskit.transpiler import CouplingMap

coupling_map = CouplingMap([[0,1], [1,2], [1,0], [2,1]])

circ_orig = QuantumCircuit(3)
circ_orig.u1(pi, 0)
circ_orig.cx(0,2)
circ_orig.draw()
     ┌───────┐     
q_0: ┤ U1(π) ├──■──
     └───────┘  │  
q_1: ───────────┼──
              ┌─┴─┐
q_2: ─────────┤ X ├
              └───┘

Because contains no measurement:

transpiled = transpile(circ_orig, coupling_map=coupling_map, routing_method='basic')
transpiled.draw()
                           ┌───┐      
q_0 -> 0 ─X────────X───────┤ X ├─X────
          │        │       └─┬─┘ │    
q_1 -> 1 ─X──X─────X─────X───■───X──X─
             │ ┌───────┐ │          │ 
q_2 -> 2 ────X─┤ U1(π) ├─X──────────X─
               └───────┘              

The unitary is preserved:

from numpy import array_equal
from qiskit import BasicAer, assemble
simulator = BasicAer.get_backend('unitary_simulator')

circ_orig_unitary = simulator.run(assemble(circ_orig)).result().get_unitary()
transpiled_unitary = simulator.run(assemble(transpiled.decompose())).result().get_unitary()

array_equal(circ_orig_unitary, transpiled_unitary)
True

@1ucian0 1ucian0 changed the title [WIP] Undoing swappers with LayoutTransformation Undoing swappers with LayoutTransformation Nov 3, 2020
@CLAassistant
Copy link

CLAassistant commented Feb 9, 2021

CLA assistant check
All committers have signed the CLA.

@jakelishman
Copy link
Member

I'll close this PR as stale now. The idea of a transpilation mode that preserves virtual -> hardware qubit mapping between the start and end of the circuit is still something we occasionally kick around (I'm not 100% convinced that it's entirely sensible within our current structures when there's coupling restrictions present), but I think this PR would need to be restarted if we did go that route.

Feel free to re-open if I'm wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants