Using gates on more than 2 qubits
In addition to the single-qubit and two-qubit gates, Qiskit® also supports 3- and more qubit gates. We will use one of them, the Toffoli gate when we build the 3-qubit Grover search algorithm circuit in Chapter 9, Grover's Search Algorithm. We are including the Fredkin gate for completeness and will not be using it in any other examples; feel free to try it out.
The multi-qubit gates in this recipe use 2, more, and 1 controlling qubit respectively:
- Toffoli: Controlled-controlled NOT (CCX), which takes 2 qubits as input and flips the third if both controlling qubits are set.
- MCX: Multi-controlled NOT takes a number of qubits (controlling) as input and flips the controlled qubit if all are set.
There is (in principle) no limit to the number of controlling qubits that you can use with your gates. In the 4- and more qubit Grover search algorithm circuit in Chapter 9, Grover's Search Algorithm, we build a 4-qubit CCCX controlled...