qml.operation.Operator

class Operator(*params, wires=None, do_queue=True)[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, Variable]) – 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.

do_check_domain

should we perform a domain check for the parameters?

eigvals

Eigenvalues of an instantiated operator.

matrix

Matrix representation of an instantiated operator in the computational basis.

name

String for the name of the operator.

num_params

Number of parameters the operator takes.

num_wires

Number of wires the operator acts on.

par_domain

Domain of the gate parameters.

parameters

Current parameter values.

wires

Wires of this operator.

do_check_domain = True

should we perform a domain check for the parameters?

Type

bool

Type

flag

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

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 parameters the operator takes.

num_wires

Number of wires the operator acts on.

par_domain

Domain of the gate parameters.

  • 'N': natural numbers (including zero).

  • 'R': floats.

  • 'A': arrays of real or complex values.

  • 'L': list of arrays of real or complex values.

  • None: if there are no parameters.

parameters

Current parameter values.

Fixed parameters are returned as is, free parameters represented by Variable instances are replaced by their current numerical value.

Returns

parameter values

Return type

list[Any]

wires

Wires of this operator.

Returns

wires

Return type

Wires

check_domain(p[, flattened])

Check the validity of a parameter.

queue()

Append the operator to the Operator queue.

check_domain(p, flattened=False)[source]

Check the validity of a parameter.

Variable instances can represent any real scalars (but not arrays).

Parameters
  • p (Number, array, Variable) – parameter to check

  • flattened (bool) – True means p is an element of a flattened parameter sequence (affects the handling of ‘A’ parameters)

Raises
  • TypeError – parameter is not an element of the expected domain

  • ValueError – parameter is an element of an unknown domain

Returns

p

Return type

Number, array, Variable

queue()[source]

Append the operator to the Operator queue.