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
Add connection to device spec API #429
Conversation
Codecov Report
@@ Coverage Diff @@
## master #429 +/- ##
==========================================
+ Coverage 97.84% 97.94% +0.09%
==========================================
Files 58 69 +11
Lines 6784 7096 +312
==========================================
+ Hits 6638 6950 +312
Misses 146 146
Continue to review full report at Codecov.
|
.pylintrc
Outdated
@@ -10,7 +10,7 @@ extension-pkg-whitelist=numpy,tensorflow,scipy,networkx,strawberryfields | |||
# (useful for modules/projects where namespaces are manipulated during runtime | |||
# and thus existing member attributes cannot be deduced by static analysis. It | |||
# supports qualified module names, as well as Unix pattern matching. | |||
ignored-modules=numpy,tensorflow,scipy,networkx,strawberryfields,strawberryfields.parameters | |||
ignored-modules=numpy,tensorflow,scipy,networkx,strawberryfields,strawberryfields.parameters,collections.abc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, pylint/codefactor was saying 'No Sequence in module collections.abc'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great on my end @thisac! Let's get @antalszava's thoughts before we merge it in
def __eq__(self, other): | ||
if len(self.ranges) != len(other.ranges): | ||
return False | ||
|
||
return all(i == j for i, j in zip(self.ranges, other.ranges)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note here: this assumes that the Ranges
obtained contain Range
objects in a monotonously increasing fashion. I'd think that that's okay, as we'd obtained these objects through the API. Perhaps a check could be placed in __init__
for it? 🤔 (though out of scope I think)
from strawberryfields.circuitspecs import Ranges
x = Ranges([0], [0.2, 0.55], [1.0])
y = Ranges([0], [1.0], [0.2, 0.55])
assert x == y
AssertionError Traceback (most recent call last)
<ipython-input-6-cdb229d2c821> in <module>
4 y = Ranges([0], [1.0], [0.2, 0.55])
5
----> 6 assert x == y
AssertionError:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point @antal!
**Example** | ||
|
||
>>> spec.gate_parameters | ||
{'squeezing_amplitude_0': x=0, x=1, 'phase_0': x=0, 0≤x≤6.283185307179586} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Out of scope): find 'squeezing_amplitude_0': x=0, x=1
slightly confusing, would perhaps prefer 'squeezing_amplitude_0': x ∈ {0, 1}
. For intervals this would get slightly more complicated, having to have unions of sets with U
. Could just be me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! We're thinking about updating the Ranges
class to produce nicer/clearer outputs (it's quite messy right now since the actual output would be {'squeezing_amplitude_0': squeezing_amplitude_0=0, squeezing_amplitude_0=1, 'phase_0': phase_0=0, 0≤phase_0≤6.283185307179586}
in this case. 😕
This would be in a separate PR, though, and it could also solve the issue you mentioned above with the ordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, let's save this for a subsequent PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of minor suggestions, but overall looks good to me! 💯
Co-authored-by: antalszava <antalszava@gmail.com>
…berryfields into add_device_API_connection
@thisac, @antalszava: I've gone through and made suggested changes, and merged in master. Might be good if you have one last look through this, and then we can merge it into master and work on finishing #432 🙂 |
💯 |
Thanks @josh146. Looks good! I only had one, very minor, comment on the way |
Co-authored-by: Theodor <theodor@xanadu.ai>
* Add connection to device spec API (#429) * Implement a get_device method * Return DeviceSpec fro get_device * Split get_device method * Add devicespec class * Fix formatting * write out docstrings * add to documentation * linting * update changelog * add PR link * done * blacking * undo weird string concatenation * Fix minor error * Add tests * Fix failing test * adding tests * add initialization test * Add kwargs and return to docstring * Update .github/CHANGELOG.md Co-authored-by: antalszava <antalszava@gmail.com> * suggested changes * Update strawberryfields/api/devicespec.py Co-authored-by: Theodor <theodor@xanadu.ai> * suggested changes Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: antalszava <antalszava@gmail.com> * Update analytic expression in variance test (#436) * Update analytic expression * Decrease amount of displacement & squeezing to remove custom tolerance * Applying suggestion to simplify squared_term * Raise error for complex arguments to Coherent, DisplacedSqueezed and Dgate gates (#428) * error/warning if Dgate, Sgate, S2gate are misused * added any() in complex test to handle batching * fixed theta --> r * simpler conditional * fixed usage of any() * added collections.abc to ignored modules * added warn+error for Coherent, DisplacedSqueezed * Use polar in remaining tests * Remove unnecessary complex var * Removing warnings; removing errors from BSgate and S2gate * Formatting * Modifying further tests * Updating test of warning for tests on errors * Adjust test docstring * Creating test class * Test * Move parametrize Co-authored-by: antalszava <antalszava@gmail.com> * Add duschinsky function to qchem utils (#434) * Device spec API implementation (#432) * Implement a get_device method * Return DeviceSpec fro get_device * Split get_device method * Add devicespec class * Fix formatting * write out docstrings * add to documentation * linting * update changelog * add PR link * done * blacking * undo weird string concatenation * Fix minor error * Add tests * Fix failing test * adding tests * add initialization test * Add kwargs and return to docstring * Update .github/CHANGELOG.md Co-authored-by: antalszava <antalszava@gmail.com> * Change name of circuitspecs to compiler * Add spec method to engine * Update program.compile to support DeviceSpec * Add default_compiler method * Update circuitspecs name to compiler in tests * finish compiler renaming * blacking * fix tests * fix tests * fix documentation * fix documentation * fix documentation * linting * black * Minor fixes * Update docstring * Add tests * suggested changes * black * fix failing tests * merge master * linting * increase coverage * linting * added logging * tidying up * fix test * fix test * linting * Update strawberryfields/compilers/xunitary.py Co-authored-by: antalszava <antalszava@gmail.com> * Update signature of `Program.compile` * Update code and docs to use new compile signature * Update tests to use the new `Program.compile` signature * Remove unused import * Apply suggestions from code review Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: antalszava <antalszava@gmail.com> * First working version. Mostly copies and pastes the outcome of the ADR * Adds docstrings * Adds docstrings * Implements reshaper for the samples * First test * Correct implementation of reshape * Fixes tests * Not quite yet working test for EPR generation * Update test_tdmprogram.py * Implements minor change in engine.py * Adds tests for most errors * minor lint fix * minor lint fix * removes matplotlib import * fix import * add default * tests for ghz and cluster states + correction of BS operation Found a convention error: It seems important that the qumodes of a BSgate are ordered with the "older" qumode (lower index) mentioned first, so ops.BSgate(p[0]) | (q[1], q[2]) instead of ops.BSgate(p[0]) | (q[2], q[1]) * test for tokyo's million-mode cluster state * Minor changes * 2D cluster state from DTU implemented * some refactoring and a bunch of comments * adding tdmprogram2 supporting individual conveyor belts for each spatial mode * local changes in examples * Renames tdmprograms * Fix reshape_samples * Removes incorrectly committed files * changing "tdmprogram2" back to "tdmprogram" in the test script * Fix reshape_samples * adaption to new samples shape * Add argument to reshape_samples * Fix reshape_samples * small correction * added test for tokyo's 2D state * Fix reshaping * Add docstring to reshape_samples * Tokyo2D running successfully Co-authored-by: Theodor <theodor@xanadu.ai> Co-authored-by: Josh Izaac <josh146@gmail.com> Co-authored-by: antalszava <antalszava@gmail.com> Co-authored-by: ziofil <ziofil@users.noreply.github.com> Co-authored-by: soranjh <40344468+soranjh@users.noreply.github.com> Co-authored-by: fab1an-q <62264296+fab1an-q@users.noreply.github.com> Co-authored-by: Theodor Isacsson <theodor.isacsson@gmail.com>
Context:
A new device spec API has been created and thus needs to be connected to Strawberry Fields.
Description of the Change:
A new
DeviceSpec
class has been added, containing device specifications for a certain target, along with aconnection.get_device
method that fetches the device specifications for the target chip and returns aDeviceSpec
object.Benefits:
Information about the hardware devices can now be refreshed and used in Strawberry Fields without the need to update Strawberry Fields.
Possible Drawbacks:
N/A
Related GitHub Issues:
N/A