7.4 Deutsch’s algorithm
For our implementation of Deutsch’s algorithm in Qiskit, we will start by creating a sort of “circuit template”. If you remember our discussion of this algorithm in Section 6.3, every application of Deutsch’s algorithm follows the same structure: it starts with two qubits in states
and
; Hadamard gates are applied to both; then, the oracle for the Boolean function that we want to test is applied; finally, a Hadamard gate is applied to the top qubit, which is subsequently measured.
We can implement that shared structure with the following instructions:
circuit = QuantumCircuit (2,1)
circuit . h (0)
circuit . x (1)
circuit . h (1)
circuit . barrier ()
# PLACE YOUR ORACLE HERE
circuit . barrier ()
circuit . h (0)
circuit . measure ([0],[0])
You may have noticed something different in the way we have defined our quantum circuit here. In addition to the the number of qubits (2) in the call to the QuantumCircuit...