# Shape of the probabilities array in scattershot boson sampling with lossy channels

Hello! I am trying to simulate a 4-mode Scattershot Boson Sampling (SBS) using lossy channels. This is similar to the code for the SBS tutorial in the Strawberry fields website.

The code that I am executing is below:

``````r_squeezing = 0.5   # squeezing parameter for the S2gate
cutoff = 7          # max number of photons computed per mode

# 4X4 Random Unitary Matrix
theta1 = 0.5
theta2 = 1

U = np.array([[np.cos(theta1), -np.sin(theta1), 0,               0             ],
[np.sin(theta1),  np.cos(theta1), 0,               0             ],
[0,               0,              np.cos(theta2), -np.sin(theta2)],
[0,               0,              np.sin(theta2),  np.cos(theta2)]])

# 4 mode Scattershot Boson Sampling
prog = sf.Program(8)
with prog.context as q:
S2gate(r_squeezing) | (q[0], q[4])
S2gate(r_squeezing) | (q[1], q[5])
S2gate(r_squeezing) | (q[2], q[6])
S2gate(r_squeezing) | (q[3], q[7])

# introducing loss in the channels
LossChannel(0.060) |   q[4]
LossChannel(0.070) |   q[5]
LossChannel(0.065) |   q[6]
LossChannel(0.066) |   q[7]

Interferometer(U) | (q[4], q[5], q[6], q[7])

# Initializing the engine
eng = sf.Engine("fock", backend_options={"cutoff_dim":cutoff})

# Executing the program with the engine
state = eng.run(prog).state
``````

After executing the code, I am getting the following error:

``````MemoryError: Unable to allocate 484. TiB for an array with shape (7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7) and data type complex128
``````
• My question is even if there is no enough memory in my computer for the simulation why the shape of the array is showing (7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7) instead of (7, 7, 7, 7, 7, 7, 7, 7), as there are 8 qumodes, instead of 16. Is my understanding incorrect here?
• Secondly, when I am executing the same code without the lossy channels with the same cutoff dimension, then the code is getting executed without any errors. Introducing losses should decrease the mean photon number and hence there shouldn’t be this memory allocation error. Right?

Thanks for the help in advance.

Let me get back to you on this.

This happens because when you introduce the lossy channel kets become density matrices, so you double the number of dimensions from 8 → 16, and unitaries become channels (same story).

You should be able to simulate the effect of loss after measurement, since loss is diagonal in the photon number.

I hope this helps!

Hey @CatalinaAlbornoz. Thank you very much for your reply. But, even if the kets are transformed into density matrices, shouldn’t the density matrix be also a 8X8 matrix (as the number of qumodes are not changing).

Also, can you please tell me how can I simulate the effect of losses after the measurements on Strawberry fields?

Thank you very much for your help.

I’ll ask one of my colleagues to take a look at your question. We’ll be back with an answer next week!

We asked around internally, and we aren’t sure how to simulate loss after detection on Strawberryfields . This is possible with Mr Mustard, however!