I am currently trying to code the Deutsch algorithm and struggling with how to measure the |x> qubit. Reading the example here has helped but doesn't solve my fundamental problem.
Using the following diagram as a basis for presenting my issue that I'm having, at the point that they propose the second Hadamard transformation, I still have my information encoded as a vector of probabilities corresponding to |00>, |01>, |10> and |11>.
Everything I've read suggests that all I do is take the top 2 values (as they correspond to the first qubit) and apply the Hadamard transform, and then see if it is a zero or one but that doesn't seem to work. Has anybody implemented this and have any advice for how to actually achieve this? I am currently coding in Python using Numpy and the following is what I have:
x = np.array([[1], [0]])
y = np.array([[0], [1]])
h = calc_hadamard(1)
phi2 = np.kron(h.dot(x), h.dot(y))
constantF = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]])
balancedF = np.array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0]])
print(constantF.dot(phi2))
print(balancedF.dot(phi2))
Where what is output by those print functions is
- (0.5, -0.5, 0.5, -0.5), and
- (0.5, -0.5, -0.5, 0.5)
As should hopefully be obvious, this is what is expected but performing a subsequent Hadamard transformation on the first two values gives the same answer. What am I missing here?