Which oberservable to measure?

There are a lot of options of what to measure with Pennylane but I am not sure which observable to measure. Does it make sense to measure the mean position quadrature operator \langle \hat X \rangle, mean momentum quadrature opertator \langle \hat P \rangle or the mean photonic number \langle \hat n \rangle with a photonic computer when making a measurement for machine learning needs?

An example of a layer I am referring to:

wires = 2
n_quantum_layers = 1

dev = qml.device("strawberryfields.fock", wires=wires, cutoff_dim=15)

def layer(inputs, w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10):
    qml.templates.DisplacementEmbedding(inputs, wires=range(wires))
    qml.templates.CVNeuralNetLayers(w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, wires=range(wires))
    return [qml.expval(qml.X(wires=i)) for i in range(wires)]

Since the fock states are a natural encoding strategy, wouldn’t it be better to measure the \langle \hat n \rangle here? On the other hand, the \langle \hat n \rangle is limited in possible values. So perhaps that is why \langle \hat X \rangle or \langle \hat P \rangle is better to use?

Hi — Different measurement simply give you more freedom. Note however that both X and P are similar in that both are implemented using homodyne measurement and will give samples with support in the real numbers. On the other hand the photon number samples have support over the non-negative integers.
Deciding which one to use will largely depend on the specifics of what you are doing and you can think of this choice as an hyperparameter that can also be optimized.

Interesting. Thanks for the info