Skip to content

Commit

Permalink
[New Device Capabilities] Implement the DeviceCapabilities data cla…
Browse files Browse the repository at this point in the history
…ss and the TOML module. (#6407)

This implementation assumes the new TOML schema as defined below:

```toml
schema = 3

# The set of all gate types supported at the runtime execution interface of the
# device, i.e., what is supported by the `execute` method of the Device API.
# The gate definition has the following format:
#
#   GATE = { properties = [ PROPS ], conditions = [ CONDS ] }
#
# where PROPS and CONS are zero or more comma separated quoted strings.
#
# PROPS: zero or more comma-separated quoted strings:
#        - "controllable": if a controlled version of this gate is supported.
#        - "invertible": if the adjoint of this operation is supported.
#        - "differentiable": if device gradient is supported for this gate.
# CONDS: zero or more comma-separated quoted strings:
#        - "analytic" or "finiteshots": if this operation is only supported in
#          either analytic execution or with shots, respectively.
#        - "terms-commute": if this composite operator is only supported
#          given that its terms commute. Only relevant for Prod, SProd, Sum,
#          LinearCombination, and Hamiltonian.
#
[operators.gates]

PauliX = { properties = ["controllable", "invertible"] }
PauliY = { properties = ["controllable", "invertible"] }
PauliZ = { properties = ["controllable", "invertible"] }
RY = { properties = ["controllable", "invertible", "differentiable"] }
RZ = { properties = ["controllable", "invertible", "differentiable"] }
CRY = { properties = ["invertible", "differentiable"] }
CRZ = { properties = ["invertible", "differentiable"] }
CNOT = { properties = ["invertible"] }

# Observables that the device is able to measure.
[operators.observables]

PauliX = { }
PauliY = { }
PauliZ = { }
Hamiltonian = { }
Sum = { }
SProd = { }
Prod = { }

# Types of measurement processes supported on the device.
[measurement_processes]

ExpectationMP = { }
SampleMP = { }
CountsMP = { conditions = ["finiteshots"] }
StateMP = { conditions = ["analytic"] }

# Additional support that the device may provide. All accepted fields and their 
# default values are listed below. Any fields missing from the TOML file will be 
# set to their default values.
[compilation]

# Whether the device is compatible with qjit.
qjit_compatible = false
# Whether the device requires run time generation of the quantum circuit.
runtime_code_generation = false
# Whether the device supports dynamic qubit allocation/deallocation.
dynamic_qubit_management = false
# Whether simultaneous measurements of observables with overlapping wires is supported.
overlapping_observables = true
# Whether simultaneous measurements of non-commuting observables is supported.
non_commuting_observables = false
# Whether the device supports initial state preparation.
initial_state_prep = false
# The methods of handling mid-circuit measurements that the device supports, e.g.,
# "one-shot", "device", "tree-traversal", etc. An empty list indicates that the device 
# does not support mid-circuit measurements. 
supported_mcm_methods = [ ]

# These options represent custom runtime parameters that can be passed to the
# device upon initialization. A dictionary will be constructed at run time
# containing the entries below.
[options]

option_key = "option_field"
```

[sc-71712]
  • Loading branch information
astralcai authored Nov 6, 2024
1 parent 9ff1015 commit 95788c0
Show file tree
Hide file tree
Showing 4 changed files with 1,126 additions and 3 deletions.
14 changes: 13 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

<h3>New features since last release</h3>

* A `DeviceCapabilities` data class is defined to contain all capabilities of the device's execution interface (i.e. its implementation of `Device.execute`). A TOML file can be used to define the capabilities of a device, and it can be loaded into a `DeviceCapabilities` object.
[(#6407)](https://github.com/PennyLaneAI/pennylane/pull/6407)

```pycon
>>> from pennylane.devices.capabilities import load_toml_file, parse_toml_document, DeviceCapabilities
>>> document = load_toml_file("my_device.toml")
>>> capabilities = parse_toml_document(document)
>>> isinstance(capabilities, DeviceCapabilities)
True
```

<h3>Improvements 🛠</h3>

<h4>Other Improvements</h4>
Expand Down Expand Up @@ -38,4 +49,5 @@

This release contains contributions from (in alphabetical order):

Andrija Paurevic
Astral Cai,
Andrija Paurevic
Loading

0 comments on commit 95788c0

Please sign in to comment.