# Can I 'shuffle' the qubits in my circuit?

If I have such a quantum circuit:

quanc = QuantumCircuit(5)
quanc.crz(np.pi,1,0)
quanc.cx(1,[i for i in range(2,5)])


Can I 'shuffle' the quantum circuit, such that the qubits [0,1,2,3,4] are mapped to [4,2,3,0,1]? I know in principle I could directly define my circuit in that order, but I'm still wondering if I could first define it like the original code and then 'shuffle' the qubits with those mapping rules? Thanks a lot:)

On a simulator it doesn't matter since you would assume that all the qubits are connected. So I assuming you thinking of mapping this onto actual qubit on the hardware. If that is the case, then you can do it through the transpile function. For example:

quanc = QuantumCircuit(5)
print(quanc)

q_0:

q_1:

q_2:

q_3:

q_4:



Now, I can remap the qubit when I do my transpilation onto the qubit layout of Athens as follows:

qc_transpiled= transpile(quanc, backend = provider.get_backend('ibmq_athens') ,
optimization_level = 3, initial_layout = [4,2,3,0,1] )
qc_transpiled.draw( 'mpl',style={'name': 'bw'}, scale = 0.5)


Hopefully this is what you were thinking of...

• Thanks for the answer! Yes that's what I was looking for:)
– ZR-
Feb 15 at 6:24