The search algorithm

Thanks to our preparation, our main algorithm is relatively small. We define a QuantumCircuit with two QuantumRegisters in line 1. We apply Hadamard gates on all qubits inside the q_pass register in line 4. Then, we apply the oracle in line 7 and the amplifier in line 10 by appending them to our main circuit. The append function takes two parameters. The first is the gate that we create in our convenience functions. The second is a list of qubits that we want to apply to this gate to. The oracle uses all qubits. The amplifier only uses the passenger qubits.

Get hands-on with 1400+ tech skills courses.