Difference between The Walrus and Strawberry Fields sample functions

The python library The Walrus has functions that can be used for sampling from Gaussian states and Strawberry Fields also has similar modules for sampling from a GBS device. I’m curious if anyone knows if there is any difference between the hafnian_sample_graph function from The Walrus library vs the sample function from SF’s sample module. Both functions take similar arguments (the adjacency matrix and mean photon number) and return samples as python lists so they seem to have the same function but I wanted to make this post to ask if there are any nuances.

Hi Amanuel,

Although results should be equivalent, the two methods differ in the way the samples are calculated:

  • Strawberryfields will encode the input symmetric matrix A into a GBS device/circuit (a set of squeezers and interferometer) and then would simulate such circuit to generate the outcomes.

  • The Walrus will return samples from the Hafnian of the Gaussian state associated with the input symmetric matrix A. No circuit involved here — samples will be generated directly using the covariance matrix and means vector of the Gaussian state.

Hi Sebastian, thanks for the reply! I had suspected the difference would be something like that. I also wanted to ask if one library would generate samples faster than the other? From the experiments I’ve run it seems The Walrus is slightly faster but I’m not sure if this difference is significant.

I haven’t done any benchmark but I believe The Walrus would be faster. Also, if you have access to a workstation with multiple cores you could use hafnian_sample_graph(..., parallel=True) to speed up the calculation.

1 Like

Thanks for the answer Sebastian. One last question about The Walrus. When using the torontonian_sample_state function to generate torontonian samples is possible that a sample of the form [0,0…,0], i.e. of all zeros, can be returned? I ask because there is no option to set the amount of loss when generating the samples so I assume they are lossless and therefore at least one photon will always be detected in a mode?

Glad to help Amanuel!

As per your last question, for Gaussian states there is always a non-zero probability of sampling from vacuum. However, if you want to include loss in your simulations such that you sample from mixed Gaussian states, the best option is to use strawberryfields.

1 Like