Coding Deutsch’s algorithm
Most of the code in this section uses Qiskit features from previous chapters.
First, we have our import declarations:
from qiskit import QuantumCircuit, executefrom qiskit_ibm_provider import IBMProvider from enum import Enum
To distinguish between the simple binary functions, we create a Python enumeration:
class SimpleBinary(Enum): ZERO = 0 ONE = 1 SAME_AS = 2 OPPOSITE_OF = 3
This chapter’s code makes little use of the SimpleBinary enumeration. But having an enumeration feels better than just assigning the numbers 0, 1, 2, and 3 to the four functions.
Our get_oracle code adds different gates to a circuit depending on which of the simple binary functions we want to implement:
def get_oracle(circ, function...