Fock States and Beamsplitter

Hi, I am fairly new to PennyLane and I don’t know if this is the correct place for this question, please correct me if I should ask someplace else.

I am trying to simulate a simple two wire experiment, where I start by initiating two wires and set both into Fock-State with n=1. After that I connect both wires to a beamsplitter.

I did the analytical calculations by hand and I think that when changing \theta the states should evolve, such that I measure different probabilities for the numberoperator. I am a little bit confused now since when I run the code, the states do not evolve and I measure the state n=1 for both wires for any value of \theta.

If I run the code for without initiating a second Fock-State on a wire, the States evolve as I expect and I measure that the Fock-State n=1 of e.g. wire 1 evolves into n=0 on wire 1 and into n=1 on wire 2.

What am I missing here?

dev_boson = qml.device('strawberryfields.fock', wires=2, cutoff_dim=10)

def two_bosons_fock(theta):
    qml.FockState(1, wires=0)
    qml.FockState(1, wires=1)
    qml.Beamsplitter(theta, 0, wires=[0, 1])
    return [qml.expval(qml.NumberOperator(0)),qml.expval(qml.NumberOperator(1))]

Hi @nlwach,

Welcome to the forum! This is absolutely the correct place to ask your question :slight_smile:

The reason the results don’t change is because qml.expval(qml.NumberOperator) returns for you the average number of photons, which in this case is 1 in each mode regardless of the value of \theta.

If you’re interested to look under the hood you can implement the same code in StrawberryFields proper and look at the output samples (QNodes in PennyLane don’t currently support sampling from the strawberryfields device):

import strawberryfields as sf
from strawberryfields import ops
import numpy as np

prog = sf.Program(2)

with prog.context as q:
    ops.Fock(1) | q[0]
    ops.Fock(1) | q[1]
    ops.BSgate(np.pi/4, 0) | (q[0], q[1])
    ops.MeasureFock()| q

eng = sf.Engine("fock", backend_options={"cutoff_dim" :  10})
result =

The output will be arrays like [[0 2]], [[2 0]], sometimes [[1 1]] depending on your input \theta. You can average over many shots and will reproduce the results of the PennyLane code.

Let us know if you have any further questions!

1 Like

Hi @glassnotes,

thank you so much for the reply. Thats exactly what I have been looking for!

Of course, no problem!