qp.core.operator

This module contains the abstract base classes for defining PennyLane operations and observables.

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.

Description

Qubit Operations

The Operator class serves as a base class for operators, and is inherited by 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).

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.

Contents

Operator Types

Operator(*params[, wires])

Base class representing quantum operators.

Operator2(*args, **kwargs)

Base class representing quantum operators that are designed for compatibility with qjit().

Operation(*params[, wires])

Base class representing quantum gates or channels applied to quantum states.

Channel(*params[, wires])

Base class for quantum channels.

StatePrepBase(*params[, wires])

An interface for state-prep operations.

Operator1(*args, **kwargs)

A class for checking if a object specifying implements the old version of Operator.

Operator2(*args, **kwargs)

Base class representing quantum operators that are designed for compatibility with qjit().

Inheritance diagram of Operator, Operation, Channel, StatePrepBase

Utility Functions

abstractify(val)

Convert the provided object into its abstract form.

Boolean Functions

BooleanFn’s are functions of a single object that return True or False. The operation module provides the following:

is_trainable

Returns True if any of the parameters of an operator is trainable according to qp.math.requires_grad.

Other

operation_derivative(operation)

Calculate the derivative of an operation.

Operation attributes

PennyLane contains a mechanism for storing lists of operations with similar attributes and behaviour (for example, those that are their own inverses). The attributes below are already included, and are used primarily for the purpose of compilation transforms. New attributes can be added by instantiating new Attribute objects. Please note that these objects are located in pennylane.ops.qubit.attributes, not pennylane.operation.

Attribute

Class to represent a set of operators with a certain attribute.

composable_rotations

Operations for which composing multiple copies of the operation results in an addition (or alternative accumulation) of parameters.

diagonal_in_z_basis

Operations that are diagonal in the computational basis.

has_unitary_generator

Operations that are generated by a unitary operator.

self_inverses

Operations that are their own inverses.

supports_broadcasting

Operations that support parameter broadcasting.

symmetric_over_all_wires

Operations that are the same if you exchange the order of wires.

symmetric_over_control_wires

Controlled operations that are the same if you exchange the order of all but the last (target) wire.