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
745 stars 187 forks source link

faster gaussian unitary compiling #603

Closed jakeffbulmer closed 3 years ago

jakeffbulmer commented 3 years ago

Context: The gaussian_unitary compiler takes a full Gaussian circuit and compiles it into an interferometer -> squeezing -> interferometer -> displacement circuit. Previously, it would compute an MxM matrix-matrix multiplication for each additional gate. Here, we make this faster by replacing the expand and multiply operations with a custom function.

Description of the Change: the functions _apply_symp_one_mode_gate and _apply_symp_two_mode_gate, defined in compilers/gaussian_unitary.py update symplectic transformations and means vectors in linear time complexity.

Benefits: Running the gaussian_unitary compiler should be much faster for large numbers of modes.

Possible Drawbacks:

Related GitHub Issues:

codecov[bot] commented 3 years ago

Codecov Report

Merging #603 (ec20d89) into master (9f6debb) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #603   +/-   ##
=======================================
  Coverage   98.50%   98.50%           
=======================================
  Files          77       77           
  Lines        8835     8859   +24     
=======================================
+ Hits         8703     8727   +24     
  Misses        132      132           
Impacted Files Coverage Δ
strawberryfields/compilers/gaussian_unitary.py 100.00% <100.00%> (ø)

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 9f6debb...ec20d89. Read the comment docs.

jakeffbulmer commented 3 years ago

The speedup isn't massive, I just tried a 100 mode circuit with 100 SMSV states followed by ~5000 beam splitters. The compile time went from 2.6s to 660ms.

nquesada commented 3 years ago

I'd say a factor of 4 is still pretty nice!