Not getting expected results for qml.state()

Hi,

I am trying to simulate a simple Feynman quantum computer that executes the NOT logical function:

a = np.array([[0,0],[1,0]]) #matrix for annihilation operator
c=np.array([[0,1],[0,0]]) #matrix for creation operator
h=qml.QubitUnitary(a,wires=2)@qml.QubitUnitary(c,wires=1)@qml.PauliX(0)
Ht=qml.op_sum(h,qml.adjoint(h))
@qml.qnode(qml.device(‘default.qubit’, wires=3))
def FNOT(t): # t is time
qml.BasisState(np.array([1,0,0]), wires=range(3))
qml.exp(Ht,-1j*t)
return qml.state()
t
However, when executing FNOT(1) the output is:
tensor([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], requires_grad=True)

This is NOT RIGHT!

The answer should be:
he=qml.exp(Ht,-1j*1).matrix()
v=np.array([0,0,0,0,1,0,0,0])
he.dot(v)=array([0. +0.j , 0. +0.j ,
0. +0.j , 0. -0.84147098j,
0.54030231+0.j , 0. +0.j ,
0. +0.j , 0. +0.j ])

So it would seem that Pennylane is correctly calculating the exponential operator outside the function using the defined Hamiltonian, but the qml.state() is not correctly reporting the result.

Any ideas on what could be going wrong here?

Thanks!

Hi @JulesA thank you for posting this here. We will look deeper into this issue.

Hey, very good question :smile: The problem here is in your way of validating the solution. What happens is that the matrix associated to Ht is different with different wires order. In this case, by your definition, the order wire is [2,1,0], while the device takes [0,1,2]. In order to check it you could run this code:

he=qml.exp(Ht,-1j*1).matrix(wire_order = [0,1,2])
v=np.array([0,0,0,0,1,0,0,0])
he.dot(v)