Performing a homodyne measurement at x = 0

Hi @CatalinaAlbornoz Glad to be here! Thanks for replying. So after post-selecting y = 0, how does one get |\psi(x)|^2? The way that I am attempting to do is use \texttt{MeasureX} on the other qumode. This returns a value of x. Repeating this for a number of times and then plotting a histogram of the obtained values in theory does give me the modulus of the wavefunction squared, but I am not sure if this is the best/only way to do it. Sorry, I’m new to SF and unfamiliar with the syntax.

Here is an example snippet of what I am trying to do:

num_samples = 1000
samples = []

for _ in range(num_samples):
    prog = sf.Program(2)
    with prog.context as q:
        Ket(aux_ket) | q[0] #auxillary qumode set up
        Fock(0) | q[1] #state of the system
        #gates implementing the circuit go here
        MeasureHomodyne(phi=0,select=0) | q[0]
        MeasureX | q[1]

    eng = sf.Engine("fock", backend_options={"cutoff_dim":some_cutoff})
    result = eng.run(prog)
    state = result.samples[0][1]
    samples.append(state)

Making a histogram (see for eg. this post) out of this should give me the PMF which is |\langle x|\psi\rangle|^2 in theory. This gets better as I increase \texttt{num_samples} in the above code. But is this the only way to do it?