# Why after transpiling a Qiskit circuit we obtain a different result?

I am trying to obtain the correct circuit transpiled for the ibmq_london device, as I want to know what the real gates applied in the quantum computer are. I am implementing the QFT circuit for 5 qubits. My code is the following one (DAQC and qnoise are modules that I have created but they do not affect the transpilation, they are used to show the pictures or to create initial states):


import numpy as np
from qiskit import QuantumRegister, QuantumCircuit, ClassicalRegister, IBMQ, execute
from qiskit.providers.aer import QasmSimulator
from qiskit.visualization import plot_histogram
from qiskit.compiler import transpile
import DAQC

# Get properties and coupling map of the desired device
device = provider.get_backend('ibmq_london')
properties = device.properties()
coupling_map = device.configuration().coupling_map
basis_gates=device.configuration().basis_gates

# Circuit
n=5
beta=0
state=DAQC.initial_state_QFT(n,beta)
qr=QuantumRegister(n)
cr=ClassicalRegister(n)
qc=QuantumCircuit(qr,cr)

qc.initialize(state,qr)
qft(qc,n)
qc.measure(qr,cr)
backend = QasmSimulator()
job = execute(qc, backend=backend,shots=100000)
result_ideal = job.result()
qiskit_counts=result_ideal.get_counts()
qnoise.show_figure(plot_histogram(qiskit_counts, title='Results for qiskit ideal simulator'))

# Transpiled circuit
qr2=QuantumRegister(n)
cr2=ClassicalRegister(n)
qc2=QuantumCircuit(qr2,cr2)

qc2.initialize(state,qr2)
qft(qc2,n)
qc2=transpile(qc2,basis_gates=basis_gates,coupling_map=coupling_map)
qc2.measure(0,0)
qc2.measure(1,1)
qc2.measure(2,2)
qc2.measure(3,3)
qc2.measure(4,4)
job = execute(qc2, backend=backend,shots=100000)
result_ideal = job.result()
qiskit_counts=result_ideal.get_counts()
qnoise.show_figure(plot_histogram(qiskit_counts, title='Results for qiskit ideal simulator (transpiled)'))



The problem is that when I obtain the results, although they should be the same because the circuit is just transpiled, I obtain completely different outcomes:

I think that the problem is with the initialize command, as when I remove it I obtain the same result for both cases. Is it possible to use the initialize command with the transpile one? Is there any other option to obtain the transpiled circuit when it is initialized in a concrete state?

Thank you

• It looks like you're transpiling with the coupling_map and basis gates, but when you run the circuit without transpiling, you are not using these. This will most likely cause a large difference between your 2 circuits which might also be contributing to the difference in results Jul 9, 2020 at 15:10
• But the results must be the same if we transpile the circuit than the ones before doing that, as both circuits must be equivalent, otherwise transpiling the circuit makes no sense. The gates applied after the transpilation must lead to the same result, they are just a decompostion of the other gates so the effect is the same and hence, the ideal result. Jul 9, 2020 at 17:36
• Hi! What version of qiskit you are currently running your code with? I have heard several times that previous versions may create bugs like the one you have. If you don't have the latest version I suggest you to install it and re-run your code. Hope this works! Also could you look at the two circuits and tell me what are the biggest differences between the two? Adding the basis_gates and coupling_map should add some changes but not that much to have the result you have.
– Lena
Jul 10, 2020 at 9:21
• I do not know how to check my qiskit version but it is from 2019. I cannot update it because I have written a code based on that version and the possible changes in the new version could break my code. The circuits are completely different. Moreover, when I compare the ibmq_london results with the ideal for this algorithm (about 40-50 gates) I obtain a very low fidelity, about 0.3 or so. Jul 10, 2020 at 13:18
• I have tried a new qiskit version and I still have the same result :( Jul 10, 2020 at 14:41