If I have such a quantum circuit:

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

enter image description here

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)


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)

enter image description here

Hopefully this is what you were thinking of...

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.