4

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
provider = IBMQ.load_account() 
# 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:

enter image description here

enter image description here

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

glS
  • 27,670
  • 7
  • 39
  • 126
Paula G
  • 419
  • 2
  • 9

1 Answers1

5

I have found the solution! The problem is that each time you use the transpile function, it generates a different transpiled circuit and the order of the outcome is not necessary the same as the order of the input, so you have to use swap gates to obtain the correct one. In order to always obtain the same circuit you have to fit the seed_transpiler (as with any random seed).

Paula G
  • 419
  • 2
  • 9