# Qiskit logical to physical qubit mapping

I want to run a simulation using qasm with a realistic noise model from a backend, specifying a coupling_map as well as an initial_layout. I do that via a QuantumInstance which in turn is passed to an algorithm. Now, two questions regarding that qubit layout:

1. I know that the transpiler may change the mapping of logical to physical qubits. Furthermore, I pass a circuit to the algorithm as an argument and the algorithm then adds an ancilla qubit to the circuit. Is there a way for me to verify the final logical to physical qubit mapping after transpiling?

2. Could that automatic adding of an ancilla cause problems when using QuantumInstance with a specific initial_layout?

If you want to get the final qubit layout (regarding to your first question), you can look at the circuit data. Here is an example:

circuit = QuantumCircuit(4, 4)

for i in range(4):
circuit.x(i)
circuit.measure([0,1,2,3], [0,1,2,3])

Circuit_Transpile = transpile(circuit, provider.get_backend('ibmq_16_melbourne') ,
initial_layout =None, optimization_level=3)

for quantum_register in Circuit_Transpile.data[:circuit.num_qubits]:
print(quantum_register[1])



What you will see as output is something like:

[[Qubit(QuantumRegister(15, 'q'), 0)],
[Qubit(QuantumRegister(15, 'q'), 9)],
[Qubit(QuantumRegister(15, 'q'), 13)],
[Qubit(QuantumRegister(15, 'q'), 14)]]


The number on the right correspond to the qubit number on the device of your interest. There are other ways to do this as well.

• Thanks for your answer. Could you elaborate on the alternatives for doing this? The above has two caveats; It does not show the ordering of logical qubits (e.g. [Qubit(QuantumRegister(15, 'q1'), 9)]) and, furthermore. gives one such line for every gate in the circuit, making it highly repetitive for longer circuits. I am looking for something like a dictionary logical --> physical qubits, e.g., {'q0': 0, 'q1': 9, 'q2': 13, 'q3': 14}. – Durd3nT May 8 at 10:09
• The other answer I was thinking of is extracting the qasm code... print(Circuit_Transpile.qasm()) but that does not give you what you want... – KAJ226 May 8 at 15:51