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

Add program code generator function #496

Closed thisac closed 3 years ago

thisac commented 3 years ago

Context: The convert-to-python-code functionality in SF interactive should be moved to SF.

Description of the Change: Added a generate_code function to io.py that generates SF code from a Program or a TDMProgram, returning the code as a string. If an engine is passed, the engine-related code is also serialized.

Benefits: It's possible to convert a program/engine into code directly via SF.

Possible Drawbacks: None

Related GitHub Issues: None

codecov[bot] commented 3 years ago

Codecov Report

Merging #496 (79df368) into master (98f557a) will increase coverage by 0.00%. The diff coverage is 98.07%.

@@           Coverage Diff           @@
##           master     #496   +/-   ##
=======================================
  Coverage   97.86%   97.86%           
=======================================
  Files          70       70           
  Lines        7316     7368   +52     
=======================================
+ Hits         7160     7211   +51     
- Misses        156      157    +1     
Impacted Files Coverage Δ
strawberryfields/io.py 96.85% <98.07%> (+0.45%) :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 98f557a...79df368. Read the comment docs.

antalszava commented 3 years ago

Thanks for the clarification @thisac! The main piece missing for me was that internally we'd already have the numeric values for gate parameters (which actually makes a lot of sense now) and we'd like to convert those numeric values to expressions that contain np.pi.

antalszava commented 3 years ago

[ch1778]