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
745 stars 187 forks source link

Symbolic parameter support in TDM compiler #625

Closed thisac closed 2 years ago

thisac commented 2 years ago

Context: The TDM compiler is failing when attempting to compile TDM program using device specs with symbolic template parameters in operations. This is due to the compiler seeing anything that is not a string (e.g., a value or a symbolic parameter) as a hard-coded parameter, which a template parameter is not, and concludes that the values in the spec differ from the values in the program.

Description of the Change:

Example: The following works, with all {s} values being validated using the gate parameter range 's': [[0.0, 99999999.]]. Also works as before with non-template p-types (e.g. p0) using the same name as in the device spec.

bbt = """\
name template_td3_fake
version 1.0
target TD3_fake (shots=1)
type tdm (temporal_modes=259, copies=1)

float array p0[1, 259] =
    {s}

Sgate({s}, 0.0) | 43
"""

device_spec = {
    'layout': bbt,
    'modes': 
    {
        'spatial': 1, 
        'concurrent': 44, 
        'temporal_max': 259
    }, 
    'compiler': ['TD3_fake'], 
    'gate_parameters': 
    {
        's': [[0.0, 99999999.]], 
    }
}

Benefits: TDM and QKD programs can be be more easily run through the compiler.

Possible Drawbacks: None

Related GitHub Issues: None

codecov[bot] commented 2 years ago

Codecov Report

Merging #625 (24988b1) into master (4254e59) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #625   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files          77       77           
  Lines        8985     8987    +2     
=======================================
+ Hits         8855     8857    +2     
  Misses        130      130           
Impacted Files Coverage Δ
strawberryfields/tdm/tdmprogram.py 98.26% <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 4254e59...24988b1. Read the comment docs.