qml.operation.Operator

class Operator(*params, wires=None, do_queue=True, id=None)[source]

Bases: abc.ABC

Base class for quantum operators supported by a device.

The following class attributes must be defined for all Operators:

Parameters

params (tuple[float, int, array]) – operator parameters

Keyword Arguments
  • wires (Iterable[Number, str], Number, str, Wires) – Wires that the operator acts on. If not given, args[-1] is interpreted as wires.

  • do_queue (bool) – Indicates whether the operator should be immediately pushed into the Operator queue.

eigvals

Eigenvalues of an instantiated operator.

hash

returns an integer hash uniquely representing the operator

id

String for the ID of the operator.

matrix

Matrix representation of an instantiated operator in the computational basis.

name

String for the name of the operator.

num_params

Number of trainable parameters that this operator expects to be fed via the dynamic *params argument.

num_wires

Number of wires the operator acts on.

parameters

Current parameter values.

wires

Wires of this operator.

eigvals

Eigenvalues of an instantiated operator.

Note that the eigenvalues are not guaranteed to be in any particular order.

Example:

>>> U = qml.RZ(0.5, wires=1)
>>> U.eigvals
>>> array([0.96891242-0.24740396j, 0.96891242+0.24740396j])
Returns

eigvals representation

Return type

array

hash

returns an integer hash uniquely representing the operator

Type

int

id

String for the ID of the operator.

matrix

Matrix representation of an instantiated operator in the computational basis.

Example:

>>> U = qml.RY(0.5, wires=1)
>>> U.matrix
>>> array([[ 0.96891242+0.j, -0.24740396+0.j],
           [ 0.24740396+0.j,  0.96891242+0.j]])
Returns

matrix representation

Return type

array

name

String for the name of the operator.

num_params

Number of trainable parameters that this operator expects to be fed via the dynamic *params argument.

By default, this property returns as many parameters as were used for the operator creation. If the number of parameters for an operator subclass is fixed, this property can be overwritten to return the fixed value.

Returns

number of parameters

Return type

int

num_wires

Number of wires the operator acts on.

parameters

Current parameter values.

wires

Wires of this operator.

Returns

wires

Return type

Wires

decompose()

Decomposes this operator into products of other operators.

decomposition(*params, wires)

Defines a decomposition of this operator into products of other operators.

label([decimals, base_label])

A customizable string representation of the operator.

queue([context])

Append the operator to the Operator queue.

decompose()[source]

Decomposes this operator into products of other operators.

Returns

list[Operation]

static decomposition(*params, wires)[source]

Defines a decomposition of this operator into products of other operators.

Parameters
  • params (tuple[float, int, array]) – operator parameters

  • wires (Union(Sequence[int], Wires)) – wires the operator acts on

Returns

list[Operation]

label(decimals=None, base_label=None)[source]

A customizable string representation of the operator.

Parameters
  • decimals=None (int) – If None, no parameters are included. Else, specifies how to round the parameters.

  • base_label=None (str) – overwrite the non-parameter component of the label

Returns

label to use in drawings

Return type

str

Example:

>>> op = qml.RX(1.23456, wires=0)
>>> op.label()
"RX"
>>> op.label(decimals=2)
"RX\n(1.23)"
>>> op.label(base_label="my_label")
"my_label"
>>> op.label(decimals=2, base_label="my_label")
"my_label\n(1.23)"
>>> op.inv()
>>> op.label()
"RX⁻¹"
queue(context=<class 'pennylane.queuing.QueuingContext'>)[source]

Append the operator to the Operator queue.