The way you’re using it will have several problems because effectively MeasureThreshold doesn’t take wires as an argument, but also expval can only take an input that inherits from the PennyLane class Obervable, meaning you can’t use MeasureThreshold.
If you try this code you will see that MeasureThreshold is the wrong type.
import pennylane as qml
import strawberryfields as sf`
dev = qml.device("strawberryfields.fock", wires=2, cutoff_dim=10)
@qml.qnode(dev)
def single_layer_receiver(beta=0):
qml.Beamsplitter(0, 0, wires=[0, 1])
qml.Displacement(beta, 0, wires=0)
print("MT type: ",type(sf.ops.MeasureThreshold(select=[1])))
return qml.expval(qml.X(wires=0))
res=single_layer_receiver()
print(res)
In case it is useful, here is a minimum working example of using sf.ops.MeasureThreshold() in StrawberryFields.
import numpy as np
import strawberryfields as sf
prog = sf.Program(1)
with prog.context as q:
sf.ops.Sgate(0.7) | q[0]
sf.ops.MeasureThreshold() | q[0]
eng = sf.Engine('gaussian')
result = eng.run(prog)
print(result.samples)