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

TF2 polar parameters #378

Closed ziofil closed 4 years ago

ziofil commented 4 years ago

Context: Update to the frontend-to-backend pipeline to remove the use of complex parameters.

Description of the Change:

  1. Updated gate classes in backend/ops.py
  2. Updated all function signatures in all backends
  3. Added new functions from thewalrus which now work with polar parameters

Benefits: Much faster tfbackend and no unnecessary float to complex conversions

Possible Drawbacks: Tests still have to be updated

Related GitHub Issues:

antalszava commented 4 years ago

Hi @ziofil, I've gone through some of the tests, let me know if you're on board with the changes! Got slightly blocked with the TF specific ones. It seems that there is a problem with functions from fock_gradients.py in TheWalrus related to the data structure of the input arguments.

Once those are resolved, the last step would be to rebase the PR to master (now it still targets tf2). I've checked locally by merging in master and it seems that there will be some conflicts, but it seemed that most of them are doable to be resolved (e.g. changes in docs, or conflicts due to formatting).

codecov[bot] commented 4 years ago

Codecov Report

Merging #378 into master will increase coverage by 0.04%. The diff coverage is 99.14%.

@@            Coverage Diff             @@
##           master     #378      +/-   ##
==========================================
+ Coverage   97.84%   97.89%   +0.04%     
==========================================
  Files          58       63       +5     
  Lines        6784     6782       -2     
==========================================
+ Hits         6638     6639       +1     
+ Misses        146      143       -3     
Impacted Files Coverage Δ
strawberryfields/api/result.py 100.00% <ø> (ø)
...awberryfields/backends/gaussianbackend/__init__.py 100.00% <ø> (ø)
strawberryfields/backends/gaussianbackend/ops.py 100.00% <ø> (+2.70%) :arrow_up:
strawberryfields/circuitspecs/gaussian_unitary.py 100.00% <ø> (ø)
strawberryfields/circuitspecs/tensorflow.py 100.00% <ø> (ø)
strawberryfields/backends/fockbackend/ops.py 94.04% <94.11%> (+2.04%) :arrow_up:
strawberryfields/ops.py 98.84% <96.29%> (-0.19%) :arrow_down:
strawberryfields/backends/tfbackend/ops.py 96.69% <97.88%> (-0.17%) :arrow_down:
strawberryfields/apps/__init__.py 100.00% <100.00%> (ø)
strawberryfields/apps/qchem/__init__.py 100.00% <100.00%> (ø)
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 58da193...fdd6daf. Read the comment docs.

ziofil commented 4 years ago

Merged!

This PR does two main things:

  1. All complex parameters are now in polar form and the BS parameters are 2 angles
  2. Introduces a speed improvement of the Fock and TF backends, especially for large cutoff