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

Adds the ability to serialize a Blackbird program #7

Closed josh146 closed 5 years ago

josh146 commented 5 years ago

This PR adds several things to the Blackbird library:

  1. A new BlackbirdProgram class, to encapsulate a blackbird program using Python data structures. The blackbird parser now automatically returns a BlackbirdProgram object. This is useful for several reasons:

    • It standardizes how the Blackbird data is represented in Python, and is much easier to document in Sphinx.

    • It allows us to return an object with properties and methods that provide useful information to the developer/user.

  2. A BlackbirdProgram.serialize() method has been added, allowing a loaded/parsed blackbird program to be re-serialized. This can be used by any library that needs to send or save blackbird data, i.e. Strawberry Fields/backends.

  3. Top level load, loads, dump, and dumps functions have been added, for serializing/deserializing Blackbird program to a file/string. This terminology matches that used for the standard Python JSON library, and also uses the same function signatures, allowing it to almost be a drop in replacement for users familiar with Python JSON.

codecov[bot] commented 5 years ago

Codecov Report

Merging #7 into master will increase coverage by 1.68%. The diff coverage is 97.59%.

@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   93.51%   95.19%   +1.68%     
==========================================
  Files           7       10       +3     
  Lines         802     1083     +281     
==========================================
+ Hits          750     1031     +281     
  Misses         52       52
Impacted Files Coverage Δ
blackbird_python/blackbird/tests/test_load_dump.py 100% <100%> (ø)
blackbird_python/blackbird/tests/test_program.py 100% <100%> (ø)
blackbird_python/blackbird/listener.py 100% <100%> (ø) :arrow_up:
blackbird_python/blackbird/program.py 100% <100%> (ø)
blackbird_python/blackbird/__init__.py 100% <100%> (ø) :arrow_up:
blackbird_python/blackbird/error.py 20.31% <11.11%> (ø) :arrow_up:
blackbird_python/blackbird/tests/test_listener.py 99.43% <98.63%> (+0.03%) :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 3c3e2b0...ade25a0. Read the comment docs.

josh146 commented 5 years ago

Note: from my side, after this PR is merged, the Blackbird library is functionally complete. It does 3 simple things, and 3 simple things only:

  1. Defines the Blackbird grammar

  2. Deserializes Blackbird scripts to a Python dataclass

  3. Serializes the Blackbird Python dataclass to a blackbird script

Barring simple maintenance, bug fixes, and potential changes to the Blackbird grammar, there are likely no new features that need to be added.

If changes to the Blackbird grammar are required in the future, having it centralized and versioned here means we can easily deploy new versions of the parser to different components of the ecosystem with minimal issue/effort.