toffoli-gate-qiskit
Table of Contents
Toffoli gate (Qiskit)
Toffoli gate implementation using Qiskit. The example prepares $\lvert 110\rangle$ (both controls $\lvert 1\rangle$, target $\lvert 0\rangle$) and applies the Toffoli gate, flipping the target to produce $\lvert 111\rangle$.
from qiskit import QuantumCircuit from qiskit.quantum_info import Statevector qc = QuantumCircuit(3) qc.x(0) # q0 = |1> qc.x(1) # q1 = |1> => state is |110> qc.ccx(0, 1, 2) # Toffoli: both controls |1>, flip target -> |111> print(Statevector(qc)) # Statevector([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j], dims=(2, 2, 2))
toffoli-gate-qiskit.txt ยท Last modified: by 127.0.0.1
