# Homodyne measurement

**URL:** <https://discuss.pennylane.ai/t/homodyne-measurement/927>\
**Category:** Strawberry Fields\
**Created:** [March 17, 2021, 11:25am UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927 "2021-03-17T11:25:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ljubomir\_Budinski](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ljubomir_budinski/32/491_2.png) [@Ljubomir\_Budinski](https://discuss.pennylane.ai/u/Ljubomir_Budinski)\
**Post date:** [March 17, 2021, 11:25am UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927/1 "2021-03-17T11:25:31Z")

</div>

Hi all,

I have a question regarding the Homodyne measurement, particularly measurement of the X quadrature. What exactly I get as an output when I perform `MeasureX`? When we measure some operator using one shot, the current state collapses to one of the eigenstates giving as the output eigenvalue corresponding to that eigenstate. Using many shots entire spectrum of the eigenstates is probed, giving as the output probability distribution of each of the eigenstates. So, what exactly is the meaning of the real number that is produced as the output when `MeasureX` is performed. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Nicolas\_Quesada](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/nicolas_quesada/32/118_2.png) [@Nicolas\_Quesada](https://discuss.pennylane.ai/u/Nicolas_Quesada)\
**Post date:** [March 17, 2021, 1:16pm UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927/2 "2021-03-17T13:16:46Z")

</div>

hi @Ljubomir_Budinski — Welcome to the forum! When you use `MeasureX`, you measure a quadrature of the field. So if you write the eigenvalue relation

\hat{x} |x \rangle = x |x \rangle

for the (continous-spectrum) position operator \hat{x}, then when you `MeasureX` on some quantum state | \psi \rangle you sample a random variable with probability mass function

\text{pmf}(x) = |\langle x| \psi\rangle|^2

This can be interpreted as, "the probability of obtaining a value between x and x+dx is \Pr(x,x+dx) = \text{pmf}(x) dx, "

Keep in mind that as it is common in quantum optics, when one measures a mode of light this mode is traced out. Thus after you measure a mode (in the quadrature or in the Fock basis) the mode that was measured simply ceases to exist.

Hope this helps,

Nicolas

---

<div class="post-metadata">

**Author:** ![Ljubomir\_Budinski](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ljubomir_budinski/32/491_2.png) [@Ljubomir\_Budinski](https://discuss.pennylane.ai/u/Ljubomir_Budinski)\
**Post date:** [March 17, 2021, 3:03pm UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927/3 "2021-03-17T15:03:07Z")

</div>

Hi @Nicolas_Quesada

Thank you for the explanation. This is exactly what I have expecting. Thanκ you for the elaboration and confirmation that I’m on the right track. If upon measuring `measureX` quadrature of some state | \psi \rangle some random variable is obtained, what exactly means the output of 3.04173042 that I’m constantly getting from this piece of code

```auto
prog = sf.Program(1)
eng = sf.Engine("fock", backend_options={"cutoff_dim": 20})

with prog.context as q:
    Fock(0) | (q[0])
    Dgate(1.0) | q[0]
    MeasureX | q[0]

results = eng.run(prog)
print(results.samples)

```

If the random value should be obtained, why I’m getting the same value for each try. Thank you in advance.

Best regards.

---

<div class="post-metadata">

**Author:** ![Nicolas\_Quesada](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/nicolas_quesada/32/118_2.png) [@Nicolas\_Quesada](https://discuss.pennylane.ai/u/Nicolas_Quesada)\
**Post date:** [March 17, 2021, 4:38pm UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927/4 "2021-03-17T16:38:11Z")

</div>

Hi @Ljubomir_Budinski — In your circuit you are preparing the zeroth Fock state (vacuum) and then displacing by \alpha = \frac{1}{\sqrt{2 \hbar} }(x+i p) = 1 . Since the default value of \hbar is 2 that means you prepared a coherent state centered around (x=2, p=0) in phase space.  
This coherent state will have a probability distribution centered around x=2 with variance equal to 1.  
Thus you sampled a standard normal distribution with mean 2 and got the value 3.04… .  
If you generated many X-samples and histogrammed them you would see that they start to clump like the usual bell shape with mean 2 and variance 1 for this circuit.  
Obviously, like any statistical experiment you cannot attach a lot of meaning to a single sample, to get understanding you will need to do statistics over many samples.

Hope this helps,

Nicolas

---

<div class="post-metadata">

**Author:** ![Ljubomir\_Budinski](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ljubomir_budinski/32/491_2.png) [@Ljubomir\_Budinski](https://discuss.pennylane.ai/u/Ljubomir_Budinski)\
**Post date:** [March 17, 2021, 5:02pm UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927/5 "2021-03-17T17:02:10Z")

</div>

Hi @Nicolas_Quesada

Thank you very much for the explanation. Honestly, it is much clearer now. I was puzzled by the fact that every time I repeat the try (program) the same value of 3.04 is obtained. But, as you said, this is just a sample pulled out from normal distribution. If we perform many of this experiments we will then be able to build entire distribution. Thanks again for the help. You are very kind.

Best regards,

Ljubomir

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [March 19, 2021, 5:40am UTC](https://discuss.pennylane.ai/t/homodyne-measurement/927/6 "2021-03-19T05:40:04Z")

</div>

@Ljubomir_Budinski glad you got it working 🙂 Feel free to open another thread if you have any more questions!
