Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert spec and layout target equality #687

Merged
merged 8 commits into from Mar 10, 2022
Merged

Conversation

thisac
Copy link
Contributor

@thisac thisac commented Mar 8, 2022

Context:
Currently, there's no check against using different targets in the specification (Device.target, or Device._spec["target"]) and in the Blackbird layout (target field in Device.layout, or BlackbirdProgram.target). This shouldn't be an issue for the user unless the specification is incorrect, although it's safer to have a check for this at device creation directly.

Description of the Change:

  • A Device.assert_spec static method is added which checks that the target in the layout is the same as the target field in the specification. This check is also performed at Device initialization.
  • If no target is specified in the layout, the device target is used instead. This is useful e.g., when compiling a program with a device (currently, if this would be attempted without a target in the layout, an obscure CircuitError would be raised.

Benefits:

  • The target in the layout can either be omitted, or must be the same as the target in the specification.

Possible Drawbacks:
None

Related GitHub Issues:
None

@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #687 (8b6d019) into master (627b491) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #687   +/-   ##
=======================================
  Coverage   98.69%   98.69%           
=======================================
  Files          75       75           
  Lines        9198     9209   +11     
=======================================
+ Hits         9078     9089   +11     
  Misses        120      120           
Impacted Files Coverage Δ
strawberryfields/device.py 97.18% <100.00%> (+0.40%) ⬆️
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 627b491...8b6d019. Read the comment docs.

@thisac thisac requested a review from josh146 March 8, 2022 22:34
@thisac thisac self-assigned this Mar 8, 2022
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @thisac! I suppose I have one question, though - is there anywhere in the logic where we are making use of the fact that different spec and different layout targets are allowed?

That is, do we have any existing cases where they might already differ?

strawberryfields/device.py Outdated Show resolved Hide resolved
strawberryfields/device.py Outdated Show resolved Hide resolved
tests/api/test_devicespec.py Show resolved Hide resolved
@thisac thisac merged commit efdf123 into master Mar 10, 2022
@thisac thisac deleted the sc-15707-assert-target branch March 10, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants