-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds parametrized template support #13
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
==========================================
+ Coverage 95.6% 96.54% +0.94%
==========================================
Files 10 12 +2
Lines 1182 1475 +293
==========================================
+ Hits 1130 1424 +294
+ Misses 52 51 -1
Continue to review full report at Codecov.
|
maybe we could overload the |
Please add the "Future work" items to backlog |
Co-Authored-By: Nathan Killoran <co9olguy@users.noreply.github.com>
All suggested changes applied. |
Co-Authored-By: Nathan Killoran <co9olguy@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left 2 more minor changes. Otherwise good to go!
This PR adds support for:
Parametrized Blackbird templates
Pattern matching of template parameters (
blackbird.utils.match_template()
)a utility function for converting a Blackbird program to a NetworkX directed acyclic graph (
blackbird.utils.to_DiGraph()
)Templates
This PR adds support for creating Blackbird 'templates', that can be loaded and used as parametrized functions. Template parameters use the syntax
{parameter_name}
, and can be placed within any arithmetic expression. This syntax is inspired by the Python templating library Jinja.For example, consider the following template file (
'teleport.xbt'
), with two template parameters{alpha}
and{sq}
.Deserializing the template:
We can also use the template to generate static blackbird programs:
Benefits
Support for templated Blackbird scripts will be advantageous for:
Variational quantum circuits, where the circuit need only be compiled once, but certain parameters can be updated independently
Serializing/deserializing parametrized quantum programs in Strawberry Fields
Communicating template parameters (for example, large or sparse graphs) separately from the blackbird template.
Future work
Support for including templates in Blackbird scripts will be added. Example:
Load a template into Strawberry Fields, to create a 'program factory':
Save a parametrized program from Strawberry Fields, to create a template. This will necessitate adding some sort of 'placeholder' variable class to Strawberry Fields.