In Qiskit, they have the concept of a Toffoli gate (ccx
). However, the following code throws an error:
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute, Aer
q1 = QuantumRegister(2)
qctrl = QuantumRegister(1)
c = ClassicalRegister(2)
qc = QuantumCircuit(q1, qctrl, c)
qc.x(q1)
qc.ccx(q1[0], q1[1], qctrl)
qc.measure(q1, c)
backend_sim = Aer.get_backend('qasm_simulator')
job_sim = execute(qc, backend_sim)
result_sim = job_sim.result()
print(result_sim.get_counts(qc))
According to my knowledge and research, this should produce the output 111
but instead I get an error message:
qiskit.qiskiterror.QiskitError: "QuantumRegister(1, 'q0') is not a tuple. A qubit should be formated as a tuple."
This seems like a bug with Qiskit to me. Am I wrong? And if so, how can I fix my code?