# 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 either- an 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 finite-difference
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
(with multiplier \(c_k\), parameter shift \(s_k\) for parameter \(\phi_k\))
works as follows:

#### CV Operation base classes¶

Due to additional requirements, continuous-variable (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 (first-order observables) or symmetric matrix (second-order observables) of coefficients of the quadrature operators \(\x\) and \(\p\).

PennyLane uses the convention \(\mathbf{r} = (\I, \x, \p)\) for single-mode operations and observables and \(\mathbf{r} = (\I, \x_0, \p_0, \x_1, \p_1, \ldots)\) for multi-mode operations and observables.

Note

Non-Gaussian CV operations and observables are currently only supported via the finite-difference method of gradient computation.

## Functions¶

`classproperty` (func) |
The class property decorator |

## Classes¶

`CV` |
A mixin base class denoting a continuous-variable operation. |

`CVObservable` (*params[, wires, do_queue]) |
Base class for continuous-variable observables. |

`CVOperation` (*params[, wires, do_queue]) |
Base class for continuous-variable quantum operations. |

`Observable` (*params[, wires, do_queue]) |
Base class for observables supported by a device. |

`ObservableReturnTypes` |
Enumeration class to represent the type of return types of an observable. |

`Operation` (*params[, wires, do_queue]) |
Base class for quantum operations supported by a device. |

`Operator` (*params[, wires, do_queue]) |
Base class for quantum operators supported by a device. |

`Tensor` (*args) |
Container class representing tensor products of observables. |

`Wires` |
Integer enumeration class to represent the number of wires an operation acts on |

## Variables¶

`All` |
An enumeration which represents all wires in the subsystem. |

`Any` |
An enumeration which represents any wires in the subsystem. |

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

`Sample` |
An enumeration which represents sampling an observable. |

`Variance` |
An enumeration which represents returning the variance of an observable on specified wires. |

## Contents

## Downloads