# How to transpile a circuit using Qiskit as done in IBMQ experience

When I create a circuit using Qiskit and then transpile it using transpiled_circuit = transpile(circuit, ibm_backend, optimization_level=1) then I open my IBMQ account and go to circuit composer to draw the circuit and run it on the same backend, the transpiled circuit I got from the circuit composer is different from that from my qiskit code.

For example, I have the following circuit :

when I transpile it in my qiskit code transpiled_circuit = transpile(circuit, provider.get_backend('ibmq_athens'), optimization_level=1) I got the following circuit :

Using the IBMQ experience circuit composer I got the following transpiled circuit when I run using ibmq_athens

I tried different optimization levels in qiskit and the transpiled circuit is also different.

My question is how I can get a transpiled circuit in qiskit to be the same as the one returned from IBMQ experience circuit composer.

I was able to obtain similar results to your IQX output using the routing_method='sabre' and layout_method='sabre' options.

Consider that the transpilation process is not deterministic and the output might vary in every run (seed_transpiler sets the PRNG seed).

from qiskit import *

circuit = QuantumCircuit(5, 5)
circuit.ccx(1,2,4)
circuit.ccx(2,3,4)
circuit.measure(4, 4)
circuit.draw('mpl')


transpile(circuit, provider.get_backend('ibmq_athens'), seed_transpiler=13).draw('mpl', fold=0)


The reason why your transpiled circuit you got from the circuit composer is different from that from your qiskit code is because the native gates on IBM's quantum hardware only consists of CNOT, and single qubit gates ($$U_1, U_2, U_3$$ ); and furthermore NOT all the qubits are connected to one another.

For Athen, you have:

And so when you execute your CCNOT gate, you must decompose it to the hardware native set of gates. This can be done as:

So here when you have a CNOT between two qubits that are not connected, you have to do some overhead swapping which resulted in a much longer circuit than what you orginally have.

This is why part of the Quantum Volume metric is also influenced by the qubits connectivity. Less connectivity implies you have to do more overhead gate execution resulting in longer circuit depth which in turns require longer qubit coherence...

• I consider that the transpile function in qiskit do the required decompositions according to the backend I pass to it as an attribute and so I should get the same transpiled circuit I got from IBMQ @KAJ226 – Monica Magdy Dec 4 '20 at 18:26
• @MonicaMagdy The two bottom circuits are the same aren't they? – KAJ226 Dec 4 '20 at 18:31
• The 2 bottom circuits -> you mean the transpiled cirquit from qiskit and the transpiled circuit from IBM . – Monica Magdy Dec 4 '20 at 18:37
• @MonicaMagdy Yes. The two longer circuits. – KAJ226 Dec 4 '20 at 18:38
• To be honest, I haven't tried them. But they should give the same outputs – Monica Magdy Dec 4 '20 at 18:39

transpiled_circuit = transpile(circuit, ibm_backend, seed_transpiler=13) gave me the circuit returned from IBMQ. Also I discovered that even on IBMQ, transpilation is random in most of the backends, in other words, when you run the same circuit many times on the same backend, you get different transpiled circuits.