Closed josh146 closed 5 years ago
Merging #13 into master will increase coverage by
0.94%
. The diff coverage is100%
.
@@ 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
Impacted Files | Coverage Δ | |
---|---|---|
blackbird_python/blackbird/listener.py | 100% <100%> (ø) |
:arrow_up: |
blackbird_python/blackbird/auxiliary.py | 100% <100%> (ø) |
:arrow_up: |
blackbird_python/blackbird/tests/test_utils.py | 100% <100%> (ø) |
|
blackbird_python/blackbird/utils.py | 100% <100%> (ø) |
|
blackbird_python/blackbird/tests/test_program.py | 100% <100%> (ø) |
:arrow_up: |
blackbird_python/blackbird/program.py | 100% <100%> (ø) |
:arrow_up: |
blackbird_python/blackbird/tests/test_listener.py | 100% <100%> (+0.52%) |
: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 fea01a4...3b8fca5. Read the comment docs.
maybe we could overload the select
argument as a way to pass placeholders?
Please add the "Future work" items to backlog
All suggested changes applied.
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.