# Performing a homodyne measurement at x = 0

**URL:** <https://discuss.pennylane.ai/t/performing-a-homodyne-measurement-at-x-0/5119>\
**Category:** Strawberry Fields\
**Created:** [September 1, 2024, 11:26am UTC](https://discuss.pennylane.ai/t/performing-a-homodyne-measurement-at-x-0/5119 "2024-09-01T11:26:28Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![tenebr1s](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/tenebr1s/32/2842_2.png) [@tenebr1s](https://discuss.pennylane.ai/u/tenebr1s)\
**Post date:** [September 16, 2024, 2:30pm UTC](https://discuss.pennylane.ai/t/performing-a-homodyne-measurement-at-x-0/5119/3 "2024-09-16T14:30:01Z")

</div>

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:

```auto
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](https://discuss.pennylane.ai/t/homodyne-measurement/927) 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?

---

_[View the full topic](https://discuss.pennylane.ai/t/performing-a-homodyne-measurement-at-x-0/5119)._
