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

Adds an Xstrict compiler #438

Closed josh146 closed 4 years ago

josh146 commented 4 years ago

Adds a strict compiler for the X class of circuits.

Ensure that the compiled program exactly matches the devices topology. As a result, this compiler only accepts :S2gate, MZgate, and MeasureFock() operations.

This compiler must be used with an X series device specification.

>>> eng = sf.RemoteEngine("X8")
>>> spec = eng.device_spec
>>> prog.compile(device=spec, compiler="Xstrict")
codecov[bot] commented 4 years ago

Codecov Report

Merging #438 into master will increase coverage by 0.12%. The diff coverage is 99.26%.

@@            Coverage Diff             @@
##           master     #438      +/-   ##
==========================================
+ Coverage   97.84%   97.97%   +0.12%     
==========================================
  Files          58       68      +10     
  Lines        6784     6949     +165     
==========================================
+ Hits         6638     6808     +170     
+ Misses        146      141       -5     
Impacted Files Coverage Δ
strawberryfields/apps/plot.py 100.00% <ø> (ø)
strawberryfields/apps/train/embed.py 100.00% <ø> (ø)
...awberryfields/backends/gaussianbackend/__init__.py 100.00% <ø> (ø)
strawberryfields/backends/gaussianbackend/ops.py 100.00% <ø> (+2.70%) :arrow_up:
strawberryfields/utils/decorators.py 100.00% <ø> (ø)
strawberryfields/utils/post_processing.py 100.00% <ø> (ø)
strawberryfields/utils/program_functions.py 97.77% <ø> (ø)
strawberryfields/utils/random_numbers_matrices.py 100.00% <ø> (ø)
strawberryfields/utils/states.py 100.00% <ø> (ø)
strawberryfields/io.py 97.70% <80.00%> (-1.13%) :arrow_down:
... and 62 more

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

josh146 commented 4 years ago

[ch269]

heltluke commented 4 years ago

I note that the tests involve adding dummy Rgate parameters or so-called "final phases". That is, if I understand correctly, for the Xstrict compiler to work on e.g. X8_01, the supplied BB program must contain 4 S2gates, 12 MZgates, and 8 Rgates.

Is this correct? If so, I suppose the docstring for the Xstrict class should be updated to mention the necessity of the inconsequential Rgates. However, I also wonder whether these gates should be supplied by users of the Xstrict compiler, or inserted by SF...

josh146 commented 4 years ago

However, I also wonder whether these gates should be supplied by users of the Xstrict compiler, or inserted by SF...

@heltluke this is a good point. Is requiring the user add in the final phase gates too strict? What we could do is have the Xstrict compiler add in final phase gates with phi=0 if they don't exist, so that the user doesn't need to specify them

heltluke commented 4 years ago

Is requiring the user add in the final phase gates too strict? What we could do is have the Xstrict compiler add in final phase gates with phi=0 if they don't exist, so that the user doesn't need to specify them.

That sounds incredibly convenient to me, but I guess we should run this by a number of others as well. @tymomboe @DavidSPhillips @lneuhaus @xanadu-zvernon

josh146 commented 4 years ago

That sounds incredibly convenient to me, but I guess we should run this by a number of others as well.

@heltluke I've just gone through the logic again, and unfortunately this is somewhat non-trivial just by construction. The way this compiler is written, it avoids compilation and just performs a simple equivalence check. I might merge this in now as-is, and we can make a new PR to add in this behaviour.