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.
Welcome to the forum! This is absolutely the correct place to ask your question
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 = eng.run(prog)
print(result.samples)
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.