Skip to content

Commit

Permalink
[unitaryHACK] Strawberry Fields: Gaussian Merge (#591)
Browse files Browse the repository at this point in the history
* Added gaussian merge compiler, which merges gaussian operations in
hybrid circuits

Github Issue: #574

* gaussian_merge: add more comments and documentation

* gaussian_merge: fix codefactor issues

* gaussian_merge: fix last codefactor issues

* gaussian_merge: reformat files with to pass formatting check / black tests

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Nicolas Quesada <nicolas@xanadu.ai>

* gaussian_merge: Add unit tests and fix bugs

* gaussian_merge: add actual tests and fix Code Factor issues bbrought up

* Add Gaussian Transform to primatives

* gaussian_merge: edited unit test to increase code coverage

* gaussian_merge: removed unnecessary method

* gaussian_merge: removed deprecated functions and if statements and updated test cases to get 100% code coverage

* Edited CHANGELOG.md to explain Gaussian Merge

* Fix contributors alphabetical order

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update .github/CHANGELOG.md

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update CHANGELOG.md

* Update tests/frontend/compilers/test_gaussianmerge.py

Co-authored-by: Nicolas Quesada <nicolas@xanadu.ai>

* Added more gaussian merge test cases for in test_gaussianunitary and fixed primatives

* test_gaussianmerge.py: added init parametrization for initial ket states.

* test_gaussianmerge.py: added ket vacuum state

* fixed black formatting issue

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Fixed docstrings and added info on logic flow.

* Apply suggestions from code review

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update strawberryfields/compilers/gaussian_merge.py

* Fixed inheritance for gaussian merge class

* Fixed inheritance issue with Compiler by defining interactive variable

* Update .github/CHANGELOG.md

Co-authored-by: Nicolas Quesada <nicolas@xanadu.ai>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Nicolas Quesada <nicolas@xanadu.ai>

* Update strawberryfields/compilers/gaussian_merge.py

Co-authored-by: Nicolas Quesada <nicolas@xanadu.ai>

* Apply suggestions from code review

Co-authored-by: Josh Izaac <josh146@gmail.com>

* Added check for Gaussian Unitary returning a single Displacement gate

Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Nicolas Quesada <nicolas@xanadu.ai>
Co-authored-by: antalszava <antalszava@gmail.com>
  • Loading branch information
4 people committed Jun 11, 2021
1 parent 07c6f95 commit 6b7b5c5
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 22 deletions.
43 changes: 42 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,47 @@
print(np.allclose(U, Uout))
```

* A new compiler, ``GaussianMerge``, has been added. It is aimed at reducing calculation
overhead for non-Gaussian circuits by minimizing the amount of Gaussian operations
in a circuit, while retaining the same functionality.
[(#591)](https://github.com/XanaduAI/strawberryfields/pull/591)

``GaussianMerge`` merges Gaussian operations, where allowed, into ``GaussianTransform``
and ``Dgate`` operations. It utilizes the existing ``GaussianUnitary`` compiler to
merge operations and Directed Acyclic Graphs to determine which operations can be merged.

```python
modes = 4
cutoff_dim = 6

# prepare an intial state with 4 photons in as many modes
initial_state = np.zeros([cutoff_dim] * modes, dtype=complex)
initial_state[1, 1, 1, 1] = 1

prog = sf.Program(4)

with prog.context as q:
ops.Ket(initial_state) | q # Initial state preparation
# Gaussian Layer
ops.S2gate(0.01, 0.01) | (q[0], q[1])
ops.BSgate(1.9, 1.7) | (q[1], q[2])
ops.BSgate(0.9, 0.2) | (q[0], q[1])
# Non-Gaussian Layer
ops.Kgate(0.5) | q[3]
ops.CKgate(0.7) | (q[2], q[3])
# Gaussian Layer
ops.BSgate(1.0, 0.4) | (q[0], q[1])
ops.BSgate(2.0, 1.5) | (q[1], q[2])
ops.Dgate(0.01) | q[0]
ops.Dgate(0.01) | q[0]
ops.Sgate(0.01, 0.01) | q[1]
# Non-Gaussian Layer
ops.Vgate(0.5) | q[2]

prog_merged = prog.compile(compiler="gaussian_merge")
```


<h3>Improvements</h3>

* Cleanup `backends/tfbackend/ops.py` to reduce line count, clarify function
Expand Down Expand Up @@ -66,7 +107,7 @@

This release contains contributions from (in alphabetical order):

Jake Bulmer, Aaron Robertson, Jeremy Swinarton, Antal Száva, Yuan Yao.
Jake Bulmer, Aaron Robertson, Jeremy Swinarton, Antal Száva, Federico Rueda, Yuan Yao.

# Release 0.18.0 (current release)

Expand Down
12 changes: 2 additions & 10 deletions strawberryfields/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,9 @@
from .bosonic import Bosonic
from .gbs import GBS
from .gaussian_unitary import GaussianUnitary
from .gaussian_merge import GaussianMerge

compilers = (
Fock,
Gaussian,
Bosonic,
GBS,
GaussianUnitary,
Xcov,
Xstrict,
Xunitary,
)
compilers = (Fock, Gaussian, Bosonic, GBS, GaussianUnitary, Xcov, Xstrict, Xunitary, GaussianMerge)

compiler_db = {c.short_name: c for c in compilers}
"""dict[str, ~strawberryfields.compilers.Compiler]: Map from compiler name to the corresponding
Expand Down

0 comments on commit 6b7b5c5

Please sign in to comment.