Skip to content

Undoing swappers with LayoutTransformation#5280

Closed
1ucian0 wants to merge 24 commits intoQiskit:mainfrom
1ucian0:4911
Closed

Undoing swappers with LayoutTransformation#5280
1ucian0 wants to merge 24 commits intoQiskit:mainfrom
1ucian0:4911

Conversation

@1ucian0
Copy link
Copy Markdown
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
Copy Markdown

CLAassistant commented Feb 9, 2021

CLA assistant check
All committers have signed the CLA.

@jakelishman
Copy link
Copy Markdown
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