In Qiskit, I am trying to perform controlled-Swap (cswap) of two registers, but an error occurs:

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute, IBMQ, Aer

c = ClassicalRegister(1)
ancilla = QuantumRegister( 1 )
phi = QuantumRegister(4, 'phi')
psi = QuantumRegister(4, 'psi')
qc = QuantumCircuit(ancilla, phi, psi, c)
qc.swap(phi, psi)
qc.cswap(ancilla[0], phi, psi)

The swap works, exchanging each qubit of the first register (phi) with each qubit of the second register (psi), I expected that the cswap would work in the same way but the following error occurs:

qiskit.qiskiterror.QiskitError: "QuantumRegister(4, 'phi') is not a tuple.A qubit should be formated as a tuple."

I have read this answer but it didn't help

  • 1
    $\begingroup$ What version of qiskit are you running? I tested your code out in qiskit v0.11.1, and it did not give me that error. It did what was expected. $\endgroup$ Commented Aug 6, 2019 at 13:59
  • 1
    $\begingroup$ The version I am using is the same, what can be the reason? $\endgroup$
    – Macalcubo
    Commented Aug 6, 2019 at 14:01
  • 1
    $\begingroup$ Are all of your other qiskit versions the same? This is my list of versions: {'qiskit': '0.11.1', 'qiskit-terra': '0.8.2', 'qiskit-ignis': '0.1.1', 'qiskit-aer': '0.2.3', 'qiskit-ibmq-provider': '0.3.1', 'qiskit-aqua': '0.5.3'} you can get this by running qiskit.__qiskit_version__ $\endgroup$ Commented Aug 6, 2019 at 14:11
  • 3
    $\begingroup$ I created a new environment with just qiskit 0.11.1 and now it is working ... $\endgroup$
    – Macalcubo
    Commented Aug 6, 2019 at 14:20

1 Answer 1


I don't know if this is what y'd like to do. But I think it's because ancilia does not correspond to the quantum bits that follow

qc.cswap(ancilla, phi, psi)

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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