Having read the Qiskit demonstration in the Qiskit textbook on how to implement Quantum Phase Estimation, I tried to do so on PennyLane's framework. My code pretty well follows what was done in Qiskit, with a few nuances according to PennyLane, but when I run it over many shots, I get varying answers. For reference, I was implementing the T-Gate (exactly what is done in Qiskit textbook). While my code yields varying possibilities, Qiskit's strictly obtains 001 (which, through post-processing, shows that the applied phase was 1/8). Perhaps there is something wrong with the program I wrote? Is the code supposed to always yield 001?
dev = qml.device('default.qubit', wires = 4, shots=1)
@qml.qnode(dev)
def circuit():
qml.PauliX(wires = 3)
for qubit in range(3):
qml.Hadamard(qubit)
def t_gate(j):
qml.T(wires = j)
repetitions = 1
n = len(dev.wires) - 1
for x in range(n-1, -1, -1):
for i in range(repetitions):
qml.ctrl(t_gate, control = x)(3)
repetitions *= 2
def ops1(wires = [0, 2]):
qml.templates.QFT(wires = [0, 2])
qml.adjoint(ops1)(wires = [0, 2])
return qml.sample()
fig, ax = qml.draw_mpl(circuit)()
fig.show()
for i in range(0, 10):
print(circuit())
Results:
[0 0 1 1]
[0 1 1 1]
[1 1 1 1]
[0 1 1 1]
[1 1 1 1]
[0 0 1 1]
[1 0 1 1]
[0 0 1 1]
[0 0 1 1]
[0 0 1 1]
code
rather than giving us a screenshot? Having actual text instead of an image, makes the text more searchable and friendly to blind people, people with screen readers, or people with images blocked to speed up loading on their slow mobile phones. $\endgroup$