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

Simulon device spec `mode` validation #545

Closed thisac closed 3 years ago

thisac commented 3 years ago

Context: program.compile doesn't support device specifications with dictionary mode entries (currently only Simulon and TD2). The TD2 compilation is handled by tdmprogram.compile, and the device spec validation works fine, while the Simulon target compilation is handled by program.compile which currently will not perform any validation based on the modes entry since it is a dictionary.

The current device spec mode entry for Simulon looks like this:

"modes": {
    "max": {
        "pnr": 20,
        "homodyne": 1000,
        "heterodyne": 1000
    }
},

and is currently ignored in SF, since it's a dictionary instead of an integer.

Description of the Change: A new assert_number_of_measurements method is added that, similarly to what the existing assert_number_of_modes does for integer mode entries, asserts that the program conforms to the mode entry when it contains the maximum number of allowed measurements as written in the example above.

This is only run if the target is Simulon, but could easily be updated in the future if other targets will have a similar entry for modes.

Benefits: The number of measurements are checked to be below the allowed number of measurements according to the device specification for Simulon.

Possible Drawbacks: None

Related GitHub Issues: None

codecov[bot] commented 3 years ago

Codecov Report

Merging #545 (8d3eaa4) into master (57c4242) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #545   +/-   ##
=======================================
  Coverage   98.22%   98.23%           
=======================================
  Files          76       76           
  Lines        8360     8384   +24     
=======================================
+ Hits         8212     8236   +24     
  Misses        148      148           
Impacted Files Coverage Δ
strawberryfields/program.py 100.00% <100.00%> (ø)

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 57c4242...8d3eaa4. Read the comment docs.