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

Bell decomp #584

Closed jakeffbulmer closed 3 years ago

jakeffbulmer commented 3 years ago

This is the residency demo project by myself and Yuan @sylviemonet. We are implementing the decomposition in https://arxiv.org/abs/2104.07561


Context: There are several ways to decompose a linear optical unitary transformation into 2x2 unitary elements. Here, we implement a new decomposition by Bell and Walmsley (https://arxiv.org/abs/2104.07561). This decomposition is lower in depth than e.g. 'rectangular' mesh in strawberryfields, as many of the phases are applied in parallel, resulting in just N+2 layers of phase shifters for an NxN unitary, instead of the 2N+1 layers of phase-shifters needed for the standard 'rectangular' decomposition.

Description of the Change: We add a new gate: sMZgate, which has a phase shifter (Rgate) on each arm of the interferometer. We add functions to strawberryfields.decompositions: rectangular_compact and triangular_compact. These implement the rectangular/triangular decompositions described in https://arxiv.org/abs/2104.07561. We also add this functionality to the Interferometer operation, which can be accessed using the options mesh='rectangular_compact' and mesh='triangular_compact'.

Benefits: Future devices may wish to use this decomposition instead of the conventional rectangular scheme, as it allows for a shorter depth, and so could lead to more compact footprint and lower loss. Therefore, having the decomposition available through strawberryfields could be useful for programming these future devices.

Possible Drawbacks: We have used a different datastructure to store the phases as compared to the existing strawberryfields decompositions. This means that how the decomposition is handled inside Interferometer is different to the other mesh options.

Related GitHub Issues:

codecov[bot] commented 3 years ago

Codecov Report

Merging #584 (1deaf65) into master (2eae95d) will increase coverage by 0.03%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #584      +/-   ##
==========================================
+ Coverage   98.38%   98.42%   +0.03%     
==========================================
  Files          75       75              
  Lines        8414     8608     +194     
==========================================
+ Hits         8278     8472     +194     
  Misses        136      136              
Impacted Files Coverage Δ
strawberryfields/compilers/fock.py 100.00% <ø> (ø)
strawberryfields/compilers/gaussian.py 100.00% <ø> (ø)
strawberryfields/compilers/gaussian_unitary.py 100.00% <100.00%> (ø)
strawberryfields/decompositions.py 99.77% <100.00%> (+0.10%) :arrow_up:
strawberryfields/ops.py 98.97% <100.00%> (+0.07%) :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 2eae95d...1deaf65. Read the comment docs.

nquesada commented 3 years ago

@jakeffbulmer: Don't forget to update the CHANGELOG.

sylviemonet commented 3 years ago

Maybe delete the two functions below in decompositions.py? @jakeffbulmer

1) def _rectangular_compact_recompose(phases):

2) def _triangular_compact_recompose(phases):


These were two test functions for us to test if the decomposition works.

Because we have used the "Gate" version of it inside ops.py to construct the circuit, and we'll not call it anymore in decompositions.py.

jakeffbulmer commented 3 years ago

Maybe delete the two functions below in decompositions.py? @jakeffbulmer

def _rectangular_compact_recompose(phases):

def _triangular_compact_recompose(phases):

These were two test functions for us to test if the decomposition works.

Because we have used the "Gate" version of it inside ops.py to construct the circuit, and we'll not call it anymore in decompositions.py.

@sylviemonet I think it is best to keep them, they are used in the tests e.g.: https://github.com/jakeffbulmer/strawberryfields/blob/dc671f1e24ac4e7c42c17d8ef81cc02cf1e629d3/tests/frontend/test_decompositions.py#L388

josh146 commented 3 years ago

Oh, it also looks like there is still one Codecov/pylint warning: image

You can fix this by adding the comment:

def _decompose(self, reg, **kwargs):
    """docstring"""
    # pylint: disable=too-many-branches