-
Notifications
You must be signed in to change notification settings - Fork 615
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
[WIP] Redesign capabilities dictionary #781
Changes from 12 commits
c365ff5
d0b2435
fae2c75
b118948
8f8c05a
48915e5
511710e
ffdf851
36e2300
d48d568
db44760
a433006
0251a3e
1bf5d3b
1a2b9cd
37050ee
a3c8166
12e7efd
909a775
ec2ec7a
45498d9
455bb89
e5b0b18
0a6c28c
9a3376a
106c719
2f0ba49
a7159b6
b168253
a3acad7
aba06fe
f22737a
09a983a
227d4d4
9b277a9
0b78eeb
5d01545
48c4bae
34c4bfe
b9b5a60
0cc5b10
21b9726
3c7b9eb
f9ee3d0
1d8cef9
fc86431
6cecd28
5b0925a
35413ec
1b4e97c
b5aa8b2
73be770
d658563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,22 @@ class Device(abc.ABC): | |
""" | ||
|
||
# pylint: disable=too-many-public-methods | ||
_capabilities = {} #: dict[str->*]: plugin capabilities | ||
_capabilities = { | ||
'model': None, | ||
'passthru_interface': None, | ||
'supports_reversible_diff': False, | ||
'supports_exact': False, | ||
'supports_sampled': False, | ||
'supports_inverse_operations': False, | ||
'supports_tensor_observables': False, | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'provides_jacobian': False, | ||
'executes_in_remote': False, | ||
'takes_fixed_number_of_wires': False, | ||
'performs_noisy_computation': False, | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
"""The capabilities dictionary stores the properties of a device. Devices can add their | ||
own custom properties and overwrite existing ones by overwriting the ``capabilities`` class method.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if one would use docstrings for class attributes? |
||
|
||
_circuits = {} #: dict[str->Circuit]: circuit templates associated with this API class | ||
_asarray = staticmethod(np.asarray) | ||
|
||
|
@@ -213,9 +228,19 @@ def map_wires(self, wires): | |
|
||
@classmethod | ||
def capabilities(cls): | ||
"""Get the other capabilities of the plugin. | ||
"""Get the capabilities of this device class. | ||
|
||
Inheriting classes that overwrite or add capabilities should overwrite this method with | ||
|
||
Measurements, batching etc. | ||
.. code-block:: | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@classmethod | ||
def capabilities(cls): | ||
capabilities = super().capabilities().copy() | ||
capabilities.update( | ||
new_capability=..., | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
return capabilities | ||
|
||
Returns: | ||
dict[str->*]: results | ||
|
@@ -413,7 +438,7 @@ def supports_operation(self, operation): | |
if operation.endswith(Operation.string_for_inverse): | ||
mariaschuld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return operation[ | ||
: -len(Operation.string_for_inverse) | ||
] in self.operations and self.capabilities().get("inverse_operations", False) | ||
] in self.operations and self.capabilities().get("supports_inverse_operations", False) | ||
|
||
return operation in self.operations | ||
|
||
|
@@ -468,7 +493,7 @@ def check_validity(self, queue, observables): | |
operation_name = o.name | ||
|
||
if o.inverse: | ||
if not self.capabilities().get("inverse_operations", False): | ||
if not self.capabilities().get("supports_inverse_operations", False): | ||
raise DeviceError( | ||
"The inverse of gates are not supported on device {}".format( | ||
self.short_name | ||
|
@@ -484,7 +509,7 @@ def check_validity(self, queue, observables): | |
for o in observables: | ||
|
||
if isinstance(o, Tensor): | ||
if not self.capabilities().get("tensor_observables", False): | ||
if not self.capabilities().get("supports_tensor_observables", False): | ||
raise DeviceError( | ||
"Tensor observables not supported on device {}".format(self.short_name) | ||
) | ||
|
@@ -501,7 +526,7 @@ def check_validity(self, queue, observables): | |
observable_name = o.name | ||
|
||
if issubclass(o.__class__, Operation) and o.inverse: | ||
if not self.capabilities().get("inverse_operations", False): | ||
if not self.capabilities().get("supports_inverse_operations", False): | ||
raise DeviceError( | ||
"The inverse of gates are not supported on device {}".format( | ||
self.short_name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,6 @@ class DefaultQubit(QubitDevice): | |
pennylane_requires = "0.12" | ||
version = "0.12.0" | ||
author = "Xanadu Inc." | ||
_capabilities = {"inverse_operations": True, "reversible_diff": True} | ||
|
||
operations = { | ||
"BasisState", | ||
|
@@ -158,6 +157,15 @@ def _get_unitary_matrix(self, unitary): # pylint: disable=no-self-use | |
|
||
return unitary.matrix | ||
|
||
@classmethod | ||
def capabilities(cls): | ||
capabilities = super().capabilities().copy() | ||
capabilities.update( | ||
supports_reversible_diff=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come this would not be defined among the capabilities in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is set to False in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh not sure how I missed that, my bad! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my understanding, how do we know if something supports reversible diff? |
||
supports_inverse_operations=True, | ||
) | ||
return capabilities | ||
|
||
def _create_basis_state(self, index): | ||
"""Return a computational basis state over all wires. | ||
|
||
|
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.
In two minds about this one: we could only define it in the devices that actually have passthru functionality (so that absence of the key signifies that the device does not)...