XanaduAI / strawberryfields

Strawberry Fields is a full-stack Python library for designing, simulating, and optimizing continuous variable (CV) quantum optical circuits.
https://strawberryfields.ai
Apache License 2.0
754 stars 191 forks source link

Number of shots in Fock and Gaussian spaces #333

Closed kareem1925 closed 2 years ago

kareem1925 commented 4 years ago

Issue description

import strawberryfields as sf
from strawberryfields.ops import *
import numpy as np
sf.__version__  
>> '0.12.1'

#### create random points

x1 = 1
x2 = 0

eng = sf.Engine(
    backend="fock",
    backend_options={"cutoff_dim": 8,'shots':5000}
)
dist = sf.Program(4)

with dist.context as q:
    Fock(1) |q[0]
    Vacuum() | q[1]
    Dgate(a=x1) | q[2]
    Dgate(a=x2) | q[3]
    BSgate() | (q[0],q[1])
    BSgate() | (q[2],q[3])
    CZgate(np.pi) | (q[1],q[3])
    BSgate() | (q[0],q[1])
    BSgate() | (q[2],q[3])
    MeasureFock() | q[0]
    MeasureFock() | q[1]

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

>> [0, 0, None, None]

The code above is an implementation of this figure: image

I just want to know if I’m correct with my code and also how I can interpret the outcome as stated in the paper. I also want to know why the number of the samples is just one and I set the shots to 5000

According to this discussion I am requesting an explanation for the number of shots in both the gaussian and fock spaces. This is the paper I'm trying to implement

co9olguy commented 4 years ago

Thanks @kareem1925. This is a good spot for us to discuss any potential bugs in the SF code (i.e., if you're not seeing the right number of shots that you expect). We can't guarantee any support for research questions here though. For the benefit of future viewers, can you edit your issue to focus up-front on the potential observed bug? Thanks :smile:

josh146 commented 4 years ago

Hi @kareem1925, the number of shots to run a program with are runtime options, so they are passed in eng.run(), not when creating the backend:

results = eng.run(dist, run_options={"shots": 5000})

Unfortunately, the Fock backend does not currently support multiple shots! This is something we are working to support, and hopefully should have this available soon.

thisac commented 2 years ago

Closed in favour of #678.