Quantum Phase Estimation for T Gate Returning Varying Results

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]

Hey @Mushahid_Khan!

I can’t run your code because I’m missing several variable definitions. But, because you’re using qml.sample as the measurement, the outcome will be probabilistic in general.

If you provide the missing pieces of your code, I can try to help you further :slight_smile:.