While computing the carry bit [C=0 XOR (AB)] I am unable to compute that AB in Qiskit. I don't whether Toffoli gate is available in Qiskit. So does anyone know how to perform AB, which is basically the AND gate without using the Toffoli gate if it isn't available?
The Toffoli gate is indeed available in qiskit. It goes by the name
ccx. Here's an example circuit where the Toffoli is used.
from qiskit import QuantumRegister, ClassicalRegister from qiskit import QuantumCircuit, BasicAer, execute q = QuantumRegister(3) c = ClassicalRegister(3) qc = QuantumCircuit(q, c) qc.h(q) qc.h(q) qc.ccx(q, q, q) qc.measure(q, c) backend = BasicAer.get_backend('qasm_simulator') job = execute(qc, backend) result = job.result() print(result.get_counts(qc))
The third qubit in the argument (
q here) acts as the target. The other two are the controls.
If you are still interested in how to make this gate from two qubit gates, you can check out the blog post here, which explains how the following gate sequence will give you the effect you need (though it isn't quite the same as a Toffoli).
qc.ch(q, q) qc.cz(q, q) qc.ch(q, q)