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

Fix einsum gradient by using old TF einsum #377

Closed trbromley closed 4 years ago

trbromley commented 4 years ago

TF2.1+ introduces a bug into einsum that results in an incorrect gradient for complex numbers: https://github.com/tensorflow/tensorflow/issues/37307.

This PR adds a quick fix where the old version of einsum will be used for TF2.1+.

codecov[bot] commented 4 years ago

Codecov Report

Merging #377 into tf2 will decrease coverage by 0.04%. The diff coverage is 75.00%.

@@            Coverage Diff             @@
##              tf2     #377      +/-   ##
==========================================
- Coverage   97.80%   97.76%   -0.05%     
==========================================
  Files          52       52              
  Lines        6375     6387      +12     
==========================================
+ Hits         6235     6244       +9     
- Misses        140      143       +3     
Impacted Files Coverage Δ
strawberryfields/backends/tfbackend/circuit.py 95.81% <75.00%> (-0.19%) :arrow_down:
strawberryfields/backends/tfbackend/ops.py 96.85% <75.00%> (-0.16%) :arrow_down:
strawberryfields/backends/tfbackend/states.py 98.46% <75.00%> (-0.50%) :arrow_down:

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 18849ba...907040a. Read the comment docs.

co9olguy commented 4 years ago

I'm glad to have this hotfix in, but can we give the commensurate test a bit more attention?

josh146 commented 4 years ago

@co9olguy, the test was updated and available here: https://github.com/XanaduAI/strawberryfields/blob/c7dd6f58fb6b8a9cb306de4b2e4e9ef13824d2a1/tests/integration/test_tf_integration.py#L484

co9olguy commented 4 years ago

Thanks