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
747 stars 186 forks source link

new passive circuit compiler #600

Closed jakeffbulmer closed 3 years ago

jakeffbulmer commented 3 years ago

Context: If you want to run a circuit on a large number of modes, with a large depth of passive optical operations, this can be quite slow. In this PR, we introduce a new compiler which works for fully passive circuits. This is able to compile any passive, linear operation into a single matrix. This can then be applied as a single operation.

Description of the Change: The "passive" compiler can compile passive linear circuits. The PassiveChannel operation can apply arbitrary passive multimode operations to a state.

Benefits: Should allow for faster computation of e.g. large multimode covariance matrices which are formed by a large depth of operations.

Possible Drawbacks: Only implemented for the Gaussian backened.

Not compatible with active operations, such as squeezing, displacement etc. So circuits can only be compiled if they produce a vacuum state, which is a bit confusing.

Related GitHub Issues:

codecov[bot] commented 3 years ago

Codecov Report

Merging #600 (094ca1d) into master (7984174) will increase coverage by 0.04%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #600      +/-   ##
==========================================
+ Coverage   98.45%   98.50%   +0.04%     
==========================================
  Files          76       77       +1     
  Lines        8758     8834      +76     
==========================================
+ Hits         8623     8702      +79     
+ Misses        135      132       -3     
Impacted Files Coverage Δ
strawberryfields/compilers/gaussian.py 100.00% <ø> (ø)
...rawberryfields/backends/gaussianbackend/backend.py 98.43% <100.00%> (ø)
...fields/backends/gaussianbackend/gaussiancircuit.py 99.23% <100.00%> (+1.14%) :arrow_up:
strawberryfields/compilers/__init__.py 100.00% <100.00%> (ø)
strawberryfields/compilers/passive.py 100.00% <100.00%> (ø)
strawberryfields/ops.py 98.98% <100.00%> (+0.01%) :arrow_up:

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 7984174...094ca1d. Read the comment docs.

jakeffbulmer commented 3 years ago

I'm not sure why the coverage is so bad, maybe it's not aware of my new test files? Also "test_all_passive_gates" is failing but it passes on my laptop, so I'm not sure what's going on here.

josh146 commented 3 years ago

@jakeffbulmer the coverage is low because the following CI test is failing:

image

This check is the one that contains frontend test and Gaussian backend tests :) Since it is not completing, it is not reporting its coverage information to the coverage check.

nquesada commented 3 years ago

@josh146 : when I run the test that the bots are failing locally, it passes. Not to sure what to do. Maybe I am missing one of the fancy options when the test are run. I am simply typing pytest -s -k test_passive_channel_vacuum

jakeffbulmer commented 3 years ago

@josh146 one fairly easy way to implement passive channels in other backends would be to perform a singlular value decomposition on T, then implement it as Interferometer -> Loss -> Interferometer. What would be the best way to implement a direct implementation in gaussian backened and a decomposition with the other backends for the PassiveChannel operation?

josh146 commented 3 years ago

@jakeffbulmer if you add a decompose method for the PassiveChannel that decomposes as you suggest (Interferometer, Loss, Interferometer), then that should automatically work on all backends 🙂

Since all backends support interferometers and loss