qml.devices.default_gaussian.DefaultGaussian¶

class
DefaultGaussian
(wires, *, shots=1000, hbar=2, analytic=True)[source]¶ Bases:
pennylane._device.Device
Default Gaussian device for PennyLane.
 Parameters
wires (int, Iterable[Number, str]) – Number of subsystems represented by the device, or iterable that contains unique labels for the subsystems as numbers (i.e.,
[1, 0, 2]
) or strings (['ancilla', 'q1', 'q2']
). Default 1 if not specified.shots (int) – How many times the circuit should be evaluated (or sampled) to estimate the expectation values. If
analytic == True
, then the number of shots is ignored in the calculation of expectation values and variances, and only controls the number of samples returned bysample
.hbar (float) – (default 2) the value of \(\hbar\) in the commutation relation \([\x,\p]=i\hbar\)
analytic (bool) – indicates if the device should calculate expectations and variances analytically
Attributes
The observables to be measured and returned.
Get the supported set of observables.
The operation queue to be applied.
Get the supported set of operations.
Mapping from free parameter index to the list of
Operations
in the device queue that depend on it.Number of circuit evaluations/random samples used to estimate expectation values of observables
Ordered dictionary that defines the map from userprovided wire labels to the wire labels used on this device
All wires that can be addressed on this device

name
= 'Default Gaussian PennyLane plugin'¶

obs_queue
¶ The observables to be measured and returned.
Note that this property can only be accessed within the execution context of
execute()
. Raises
ValueError – if outside of the execution context
 Returns
list[~.operation.Observable]

observables
¶ Get the supported set of observables.
 Returns
the set of PennyLane observable names the device supports
 Return type
set[str]

op_queue
¶ The operation queue to be applied.
Note that this property can only be accessed within the execution context of
execute()
. Raises
ValueError – if outside of the execution context
 Returns
list[~.operation.Operation]

operations
¶ Get the supported set of operations.
 Returns
the set of PennyLane operation names the device supports
 Return type
set[str]

parameters
¶ Mapping from free parameter index to the list of
Operations
in the device queue that depend on it.Note that this property can only be accessed within the execution context of
execute()
. Raises
ValueError – if outside of the execution context
 Returns
the mapping
 Return type
dict[int>list[ParameterDependency]]

pennylane_requires
= '0.11'¶

short_name
= 'default.gaussian'¶

shots
¶ Number of circuit evaluations/random samples used to estimate expectation values of observables

version
= '0.11.0'¶

wire_map
¶ Ordered dictionary that defines the map from userprovided wire labels to the wire labels used on this device

wires
¶ All wires that can be addressed on this device
Methods
apply
(operation, wires, par)Apply a quantum operation.
Get the other capabilities of the plugin.
check_validity
(queue, observables)Checks whether the operations and observables in queue are all supported by the device.
define_wire_map
(wires)Create the map from userprovided wire labels to the wire labels used by the device.
execute
(queue, observables[, parameters])Execute a queue of quantum operations on the device and then measure the given observables.
The device execution context used during calls to
execute()
.expand
(S, wires)Expands a Symplectic matrix S to act on the entire subsystem.
expval
(observable, wires, par)Returns the expectation value of observable on specified wires.
map_wires
(wires)Map the wire labels of wires using this device’s wire map.
Called during
execute()
after the individual operations have been executed.Called during
execute()
after the individual observables have been measured.Called during
execute()
before the individual operations are executed.Called during
execute()
before the individual observables are measured.probability
([wires])Return the (marginal) probability of each computational basis state from the last run of the device.
reduced_state
(wires)Returns the vector of means and the covariance matrix of the specified wires.
reset
()Reset the device
sample
(observable, wires, par)Return a sample of an observable.
supports_observable
(observable)Checks if an observable is supported by this device. Raises a ValueError,
supports_operation
(operation)Checks if an operation is supported by this device.
var
(observable, wires, par)Returns the variance of observable on specified wires.

apply
(operation, wires, par)[source]¶ Apply a quantum operation.
For plugin developers: this function should apply the operation on the device.
 Parameters
operation (str) – name of the operation
wires (Wires) – wires that the operation is applied to
par (tuple) – parameters for the operation

classmethod
capabilities
()¶ Get the other capabilities of the plugin.
Measurements, batching etc.
 Returns
results
 Return type
dict[str>*]

check_validity
(queue, observables)¶ Checks whether the operations and observables in queue are all supported by the device. Includes checks for inverse operations.
 Parameters
queue (Iterable[Operation]) – quantum operation objects which are intended to be applied on the device
observables (Iterable[Observable]) – observables which are intended to be evaluated on the device
 Raises
DeviceError – if there are operations in the queue or observables that the device does not support

define_wire_map
(wires)¶ Create the map from userprovided wire labels to the wire labels used by the device.
The default wire map maps the user wire labels to wire labels that are consecutive integers.
However, by overwriting this function, devices can specify their preferred, nonconsecutive and/or noninteger wire labels.
 Parameters
wires (Wires) – userprovided wires for this device
 Returns
dictionary specifying the wire map
 Return type
OrderedDict
Example
>>> dev = device('my.device', wires=['b', 'a']) >>> dev.wire_map() OrderedDict( [(<Wires = ['a']>, <Wires = [0]>), (<Wires = ['b']>, <Wires = [1]>)])

execute
(queue, observables, parameters={}, **kwargs)¶ Execute a queue of quantum operations on the device and then measure the given observables.
For plugin developers: Instead of overwriting this, consider implementing a suitable subset of
pre_apply()
,apply()
,post_apply()
,pre_measure()
,expval()
,var()
,sample()
,post_measure()
, andexecution_context()
. Parameters
queue (Iterable[Operation]) – operations to execute on the device
observables (Iterable[Observable]) – observables to measure and return
parameters (dict[int, list[ParameterDependency]]) – Mapping from free parameter index to the list of
Operations
(in the queue) that depend on it.
 Keyword Arguments
return_native_type (bool) – If True, return the result in whatever type the device uses internally, otherwise convert it into array[float]. Default: False.
 Raises
QuantumFunctionError – if the value of
return_type
is not supported Returns
measured value(s)
 Return type
array[float]

execution_context
()¶ The device execution context used during calls to
execute()
.You can overwrite this function to return a context manager in case your quantum library requires that; all operations and method calls (including
apply()
andexpval()
) are then evaluated within the context of this context manager (see the source ofDevice.execute()
for more details).

expand
(S, wires)[source]¶ Expands a Symplectic matrix S to act on the entire subsystem.
 Parameters
S (array) – a \(2M\times 2M\) Symplectic matrix
wires (Wires) – wires of the modes that S acts on
 Returns
the resulting \(2N\times 2N\) Symplectic matrix
 Return type
array

expval
(observable, wires, par)[source]¶ Returns the expectation value of observable on specified wires.
Note: all arguments accept _lists_, which indicate a tensor product of observables.
 Parameters
observable (str or list[str]) – name of the observable(s)
wires (Wires) – wires the observable(s) are to be measured on
par (tuple or list[tuple]]) – parameters for the observable(s)
 Returns
expectation value \(\expect{A} = \bra{\psi}A\ket{\psi}\)
 Return type
float

map_wires
(wires)¶ Map the wire labels of wires using this device’s wire map.

probability
(wires=None)¶ Return the (marginal) probability of each computational basis state from the last run of the device.
 Parameters
wires (Sequence[int]) – Sequence of wires to return marginal probabilities for. Wires not provided are traced out of the system.
 Returns
Dictionary mapping a tuple representing the state to the resulting probability. The dictionary should be sorted such that the state tuples are in lexicographical order.
 Return type
OrderedDict[tuple, float]

reduced_state
(wires)[source]¶ Returns the vector of means and the covariance matrix of the specified wires.
 Parameters
wires (Wires) – requested wires
 Returns
means is an array containing the vector of means, and cov is a square array containing the covariance matrix
 Return type
tuple (means, cov)

sample
(observable, wires, par)[source]¶ Return a sample of an observable.
Note
The
default.gaussian
plugin only supports sampling fromX
,P
, andQuadOperator
observables. Parameters
observable (str) – name of the observable
wires (Wires) – wires the observable is to be measured on
par (tuple) – parameters for the observable
 Returns
samples in an array of dimension
(n, num_wires)
 Return type
array[float]

supports_observable
(observable)¶  Checks if an observable is supported by this device. Raises a ValueError,
if not a subclass or string of an Observable was passed.
 Parameters
observable (type or str) – observable to be checked
 Raises
ValueError – if observable is not a
Observable
class or string Returns
True
iff supplied observable is supported Return type
bool

supports_operation
(operation)¶ Checks if an operation is supported by this device.
 Parameters
operation (type or str) – operation to be checked
 Raises
ValueError – if operation is not a
Operation
class or string Returns
True
iff supplied operation is supported Return type
bool

var
(observable, wires, par)[source]¶ Returns the variance of observable on specified wires.
Note: all arguments support _lists_, which indicate a tensor product of observables.
 Parameters
observable (str or list[str]) – name of the observable(s)
wires (Wires) – wires the observable(s) is to be measured on
par (tuple or list[tuple]]) – parameters for the observable(s)
 Raises
NotImplementedError – if the device does not support variance computation
 Returns
variance \(\mathrm{var}(A) = \bra{\psi}A^2\ket{\psi}  \bra{\psi}A\ket{\psi}^2\)
 Return type
float
Contents
Using PennyLane
Development
API
Downloads