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

Hardware-friendly decomposition #363

Closed shreyapkumar closed 4 years ago

shreyapkumar commented 4 years ago

Context: This PR attempts to remove needless complications in the code arising from the difference between how theorists define T matrices and the equivalent transformations that the chip implements.

Currently, the unitary is decomposed into Clements T matrices which are later converted to phases on the chip by rectangular_symmetric function. Decomposing the unitary directly into Mach Zehnder units would make the code simpler. It would also make it easier to modify the code and decompositions as planned in order to account for imperfect beamsplitters and also for power reduction, etc.

Description of the Change:

Possible Drawbacks:

shreyapkumar commented 4 years ago

Possible reviewers could be @lneuhaus , @nquesada and/or @ishdhand

codecov[bot] commented 4 years ago

Codecov Report

Merging #363 into master will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #363   +/-   ##
=======================================
  Coverage   97.77%   97.77%           
=======================================
  Files          52       52           
  Lines        6435     6435           
=======================================
  Hits         6292     6292           
  Misses        143      143           

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 4844687...4844687. Read the comment docs.

josh146 commented 4 years ago

@shreyapkumar, by the way, CodeFactor runs some static analysis on the PR, and picked up the following issues. Running the Black formatter locally should automatically fix most of them,

black -l 100 strawberryfields/decompositions.py

and the remainder can be fixed by hand.


CodeFactor found multiple issues last seen at 2fa0b43f300d92bae13c9424d1add9346de1e570:

Redefining name 'T' from outer scope (line 233)

strawberryfields\decompositions.py:499

No space allowed before :

if U[n, m] == 0 :
                ^

strawberryfields\decompositions.py:541

Trailing whitespace

strawberryfields\decompositions.py:493 strawberryfields\decompositions.py:654 strawberryfields\decompositions.py:661 strawberryfields\decompositions.py:492 strawberryfields\decompositions.py:548 strawberryfields\decompositions.py:500

No space allowed before :

if U[m, n] == 0 :
                ^

strawberryfields\decompositions.py:520

shreyapkumar commented 4 years ago

Documentation and formatting changes are fixed now. Comments about this or anything else are welcome!

shreyapkumar commented 4 years ago

Thanks so much, @josh146 for the very helpful comments! I learnt a lot :)

josh146 commented 4 years ago

@shreyapkumar, is this ready to be merged in?

shreyapkumar commented 4 years ago

Yes, nothing more to add from my side!