qml.operation¶
Warning
Unless you are a PennyLane or plugin developer, you likely do not need to use these classes directly.
See the main operations page for details on available operations and observables.
This module contains the abstract base classes for defining PennyLane operations and observables.
Description¶
Qubit Operations¶
The Operator
class serves as a base class for operators,
and is inherited by both the Observable
class and the
Operation
class. These classes are subclassed to implement quantum operations
and measure observables in PennyLane.
Each
Operator
subclass represents a general type of map between physical states. Each instance of these subclasses represents eitheran application of the operator or
an instruction to measure and return the respective result.
Operators act on a sequence of wires (subsystems) using given parameter values.
Each
Operation
subclass represents a type of quantum operation, for example a unitary quantum gate. Each instance of these subclasses represents an application of the operation with given parameter values to a given sequence of wires (subsystems).Each
Observable
subclass represents a type of physical observable. Each instance of these subclasses represents an instruction to measure and return the respective result for the given parameter values on a sequence of wires (subsystems).
Differentiation¶
In general, an Operation
is differentiable (at least using the finitedifference
method) with respect to a parameter iff
the domain of that parameter is continuous.
For an Operation
to be differentiable with respect to a parameter using the
analytic method of differentiation, it must satisfy an additional constraint:
the parameter domain must be real.
Note
These conditions are not sufficient for analytic differentiation. For example, CV gates must also define a matrix representing their Heisenberg linear transformation on the quadrature operators.
For gates that are supported via the analytic method, the gradient recipe works as follows:
where \(f\) is the expectation value of an observable on a circuit that has been evolved by the operation being considered with parameter \(\phi_k\), there are multiple terms indexed with \(i\) for each parameter \(\phi\) and the \([c_i, a_i, s_i]\) are coefficients specific to the gate.
The following specific case holds for example for qubit operations that are generated by one of the Pauli matrices and results in an overall positive and negative shift:
i.e., so that \([c_0, a_0, s_0]=[1/2, 1, \pi/2]\) and \([c_1, a_1, s_1]=[1/2, 1, \pi/2]\).
CV Operation base classes¶
Due to additional requirements, continuousvariable (CV) operations must subclass the
CVOperation
or CVObservable
classes instead of Operation
and Observable
.
Differentiation¶
To enable gradient computation using the analytic method for Gaussian CV operations, in addition, you need to
provide the static class method _heisenberg_rep()
that returns the Heisenberg representation of
the operation given its list of parameters, namely:
For Gaussian CV Operations this method should return the matrix of the linear transformation carried out by the operation on the vector of quadrature operators \(\mathbf{r}\) for the given parameter values.
For Gaussian CV Observables this method should return a real vector (firstorder observables) or symmetric matrix (secondorder observables) of coefficients of the quadrature operators \(\x\) and \(\p\).
PennyLane uses the convention \(\mathbf{r} = (\I, \x, \p)\) for singlemode operations and observables and \(\mathbf{r} = (\I, \x_0, \p_0, \x_1, \p_1, \ldots)\) for multimode operations and observables.
Note
NonGaussian CV operations and observables are currently only supported via the finitedifference method of gradient computation.
Functions¶

The class property decorator 

Calculate the derivative of an operation. 
Classes¶

A mixin base class denoting a continuousvariable operation. 

Base class for continuousvariable observables. 

Base class for continuousvariable quantum operations. 

Base class for quantum channels. 

Base class for diagonal quantum operations supported by a device. 

Base class for observables supported by a device. 

Enumeration class to represent the return types of an observable. 

Base class for quantum operations supported by a device. 

Base class for quantum operators supported by a device. 

Container class representing tensor products of observables. 

Integer enumeration class to represent the number of wires an operation acts on 
Variables¶
An enumeration which represents all wires in the subsystem. 

An enumeration which represents any wires in the subsystem. 

An enumeration which represents returning the expectation value of an observable on specified wires. 

An enumeration which represents returning probabilities of all computational basis states. 

An enumeration which represents sampling an observable. 

An enumeration which represents returning the state in the computational basis. 

An enumeration which represents returning the variance of an observable on specified wires. 
Contents
Downloads