Hello,
I am trying to do Quantum Phase Estimation with qml.T gate. However I keep getting varying results when i call the qnode multiple times. I should be getting the same results. What could be causing this? Here is my code:
import pennylane as qml
from pennylane import numpy as np
U = qml.T.compute_matrix()
eigvals, eigvecs = np.linalg.eig(U)
target_eigvec = eigvecs[:, 0]
target_eigval = eigvals[0]
@qml.qnode(dev)
def quantum_phase_estimation():
for wire in estimation_wires:
qml.Hadamard(wires=wire)
qml.MottonenStatePreparation(target_eigvec, wires=target_wires)
for power_of_two, control_wire in enumerate(estimation_wires[::-1]):
qml.ControlledQubitUnitary(
np.linalg.matrix_power(U, 2 ** power_of_two),
control_wires=control_wire,
wires=target_wires
)
qml.adjoint(qml.QFT)(wires=estimation_wires)
return qml.sample(wires=estimation_wires)
When I run the qnode for multiple iterations i get the following results:
[1 1 1]
[1 1 1]
[0 0 0]
[0 0 0]
[1 1 1]
[1 1 1]
[0 0 0]
[0 0 0]
[1 1 1]
[0 0 1]
[1 1 1]
[0 0 0]
[1 1 1]
[1 1 1]
[1 1 1]
[0 0 1]
[1 1 1]
[1 1 1]
[1 1 1]
[1 1 1]