Swap test in using CV

Hi, I hope everything is well and no one is infected. I’m trying to implement this paper and I get lost when I try to extract the information from the circuit. I’m trying to implement figure 13.
can anyone help me please?

Hi @kareem_essafty,

Can you provide a bit more detail about which part is getting you stuck? Is there an exception thrown by the code? Or you’re unclear how to code up that circuit? What have you tried so far that didn’t work?

Hi Mr @nathan,
I’m sorry i didn’t provide any code :frowning:.

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

#### create random points

    x1 = 1
x2 = 0

eng = sf.Engine(
    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)

>> [0, 0, None, None]

I implemented this figure:

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

sorry for not including the code from the beginning and I hope that the coronavirus situation is not bad at your place.

Hey karrem_essafty. We’ll get back to you with more explanations asap, but from looking into your code I agree that the SF documentation is rather silent about issues of shot numbers, and about what valid backend_options and run_options are (I suspect that what you want to do would use run_options in the eng.run function).

1 Like

Would you be able to open an issue in the StrawberryFields github repo, asking for improvements of the documentation with regards to the use of shots, including minimum code examples of what is not intuitive?

That would be great!

1 Like

Hi Mrs @Maria_Schuld,
I’ve created an issue and I’m looking forward to your explanation.
can I use slack to discuss more advanced ideas about what I’m doing?

Hi @kareem_essafty,

Can you try replacing the final two-line measurements with a single-line measurement?
MeasureFock() | q[0], q[1])

As an explanation: The MeasureFock operation measures one or “a set of” modes (see here)

Only don’t forget the opening brackets:

MeasureFock() | (q[0], q[1])

You are welcome to share your ideas on slack, but I cannot promise that we will be able to give in-depth research level support…

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.

Hi, Can you help me how to create bosonic operator in strawberry field?

Hi @Gargi_Tyagi — Could you tell us what is that you have in mind with a bosonic operator?