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
751 stars 187 forks source link

sf.ops.Bosonic with negative coefficients makes non-states #732

Closed ScottGlancy closed 1 year ago

ScottGlancy commented 1 year ago

Before posting a bug report

Expected behavior

The documentation here says that Bosonic(weights=None, means=None, covs=None) will prepare a mode as a linear combination of Gaussian functions in phase space. The input weights are coefficients for each Gaussian in the linear combination. "Linear combination" is ambiguous, but based on some testing, I believe it means "probabilistic mixture" rather than "superposition". If that is true, I expect that Bosonic should test that weights are probabilities and give an error if they are not.

Actual behavior

The resulting state is has a Wigner function that is the sum of the weighted Gaussian functions, regardless of the weights. The result will not be a quantum state if the weights are not probabilities.

sf.ops.Bosonic([-1], [[0,0]], [[[1,0],[0,1]]]) prepares a state whose Wigner function is equal to the vacuum Wigner function except that is it negative everywhere.

Reproduces how often

always

System information

Strawberry Fields: a Python library for continuous-variable quantum circuits.
Copyright 2018-2020 Xanadu Quantum Technologies Inc.

Python version:            3.9.13
Platform info:             Windows-10-10.0.19044-SP0
Installation path:         c:\ProgramData\Anaconda3\envs\...\lib\site-packages\strawberryfields
Strawberry Fields version: 0.23.0
Numpy version:             1.23.2
Scipy version:             1.8.1
SymPy version:             1.11.1
NetworkX version:          2.8.7
The Walrus version:        0.19.0
Blackbird version:         0.4.0
XCC version:               0.2.1
TensorFlow version:        None

Source code

import strawberryfields as sf
prog = sf.Program(1)
with prog.context as q:
    sf.ops.Bosonic([-1], [[0,0]], [[[1,0],[0,1]]]) | q[0]
    eng = sf.Engine("bosonic")
    result = eng.run(prog)

result.state.wigner(0,0,0)

Tracebacks

No response

Additional information

No response

CatalinaAlbornoz commented 1 year ago

Hi @ScottGlancy , thank you for reporting this bug. We will look into it.

sduquemesa commented 1 year ago

Hi @ScottGlancy!

The bosonic backend does not restrict the input coefficients to be real and hence does not do a "hard" check to see if the weights add up to one. The reason for this is that some states require imaginary weights to produce interference fringes and negativity in the Wigner function.

On the other hand, a "linear combination of Gaussians" refers to

image

You can find all details about the bosonic backend in the paper Fast simulation of bosonic qubits via Gaussian functions in phase space as well as some hands-on examples (e.g., check 1, 2, 3) on the strawberryfields documentation.

ScottGlancy commented 1 year ago

@sduquemesa, I understand that creating states using linear combinations of Gaussians that are not probabilistic mixtures can be useful, but I don't know of any situations in which one would want to use ops.Bosonic to create something that is not a quantum state. Checking that the input parameters create a quantum state seems like it would be helpful.

However, I just noticed that the concluding section of the "Fast Simulation..." paper says "it would be of interest to determine the exact mathematical conditions for physicality in terms of the parameters of the states (weights, vectors of means and covariances matrices).". Apparently building the input error checking that I am asking for will require actual research.

In the meantime, I would recommend better documentation of ops.Bosonic to explain the precise input format it needs and to warn users that it might create non-physical states. ops.Bosonic is never used in the examples demonstrating the bosonic engine, so I had to use some trial-and-error to find the input format.