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

Output of "Circuits" tutorial differs from local output #457

Closed glassnotes closed 4 years ago

glassnotes commented 4 years ago

Issue description

I was working through the Circuits tutorial, and found that the output after simulation when run locally does not match the tutorial. Below is a screenshot with a comparison of the outputs.

2020-09-18_12-05

  • cutoff point in result.state is 15 instead of 5 (typo?)
  • pure in result.state shows True instead of False
  • dimensions of result.state.dm().shape is (5,5,5,5,5,5) instead of (5,5,5)
Strawberry Fields: a Python library for continuous-variable quantum circuits.
Copyright 2018-2020 Xanadu Quantum Technologies Inc.

Python version:            3.8.5
Platform info:             Linux-5.3.0-64-generic-x86_64-with-glibc2.10
Installation path:         /home/olivia/Software/anaconda3/envs/xanadu/lib/python3.8/site-packages/strawberryfields
Strawberry Fields version: 0.15.0
Numpy version:             1.18.5
Scipy version:             1.4.1
SymPy version:             1.6.2
NetworkX version:          2.4
The Walrus version:        0.13.0
Blackbird version:         0.2.4
TensorFlow version:        2.3.0
ziofil commented 4 years ago

Shouldn’t the shape of a density matrix always have an even number of dimensions?

co9olguy commented 4 years ago

:thinking:

thisac commented 4 years ago

@glassnotes I'm not sure about exactly why this is, although it seems to me like you're getting the correct output (and that the tutorial needs to be updated). I believe the dm should have dimension 2*number-of-measured-modes (right?), and, looking at the code, it actually states that the cutoff=15 although the printed cutoff clearly is 5.

josh146 commented 4 years ago

My guess for what happened here: This tutorial used to output the statevector (which will be an array of shape [cutoff] * num_modes), and the cutoff used to be 5. At some point the commands got updated, but the output cell didn't.

The fix should simply be changing the cutoff_dim to 5 and updating the output cell to be [5, 5, 5, 5, 5, 5].

co9olguy commented 4 years ago

shouldn't the cell update by automatic?

josh146 commented 4 years ago

No, this is a quickstart in the SF docs (it's not a sphinx gallery page). It's just a handwritten ReST page.

co9olguy commented 4 years ago

That explains it