XanaduAI / blackbird

Blackbird is a quantum assembly language for continuous-variable quantum computation, that can be used to program Xanadu's quantum photonics hardware and Strawberry Fields simulator.
https://quantum-blackbird.readthedocs.io
Apache License 2.0
70 stars 26 forks source link

Add `expr` to RegRefTransform class #46

Closed thisac closed 3 years ago

thisac commented 3 years ago

This is part of an attempt to keep support for feed-forwarding when serializing and deserializing a Blackbird script. To be able to use a RegRefTransform type parameter as a symbolic expression in Strawberry Fields it needs to be accessible from the RegRefTransform class.

Below is an example that, when loaded as a Blackbird program and then transformed into an SF program, needs access to the Xgate and Zgate parameters symbolic expressions (instead of only as a RegRefTransform).

name Teleportation
version 1.0
target gaussian

Coherent(1, 0.0) | 0
Sgate(2, 0) | 2
Sgate(-2, 0) | 1
BSgate(0.7854, 0) | [1, 2]
BSgate(0.7854, 0) | [0, 1]
MeasureHomodyne(phi=1.5707963267948966) | 1
MeasureHomodyne(phi=0) | 0
Xgate(1.41421356237*q0) | 2
Zgate(1.41421356237*q1) | 2

By allowing this, we can load a script with Blackbird and then transform it into a valid Strawberry Fields program that contains feedforwarding.

Note: currently, Strawberry Fields converts the 1.41421356237*q0 parameter into a string while creating the Blackbird program. This has to be updated to keep it as a symbolic expression instead.

codecov[bot] commented 3 years ago

Codecov Report

Merging #46 (170c2ad) into master (2104667) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master      #46   +/-   ##
=======================================
  Coverage   97.17%   97.18%           
=======================================
  Files          12       12           
  Lines        1914     1915    +1     
=======================================
+ Hits         1860     1861    +1     
  Misses         54       54           
Impacted Files Coverage Δ
blackbird_python/blackbird/listener.py 99.59% <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 2104667...170c2ad. Read the comment docs.