3
$\begingroup$

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.h(ancilla)
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

$\endgroup$
4
  • 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$ Aug 6, 2019 at 13:59
  • 1
    $\begingroup$ The version I am using is the same, what can be the reason? $\endgroup$
    – Macalcubo
    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$ 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
    Aug 6, 2019 at 14:20

1 Answer 1

1
$\begingroup$

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)
qc.draw()

enter image description here

$\endgroup$

Your Answer

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

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