sum(*summands, do_queue=None, id=None, lazy=True)[source]

Construct an operator which is the sum of the given operators.


summands (tuple[Operator]) – the operators we want to sum together.

Keyword Arguments
  • do_queue (bool) – determines if the sum operator will be queued (currently not supported). This argument is deprecated, instead of setting it to False use stop_recording().

  • id (str or None) – id for the Sum operator. Default is None.

  • lazy=True (bool) – If lazy=False, a simplification will be performed such that when any of the operators is already a sum operator, its operands (summands) will be used instead.


The operator representing the sum of summands.

Return type



This operator supports batched operands:

>>> op = qml.sum(qml.RX(np.array([1, 2, 3]), wires=0), qml.PauliX(1))
>>> op.matrix().shape
(3, 4, 4)

But it doesn’t support batching of operators:

>>> op = qml.sum(np.array([qml.RX(0.4, 0), qml.RZ(0.3, 0)]), qml.PauliZ(0))
AttributeError: 'numpy.ndarray' object has no attribute 'wires'

See also



>>> summed_op = qml.sum(qml.PauliX(0), qml.PauliZ(0))
>>> summed_op
PauliX(wires=[0]) + PauliZ(wires=[0])
>>> summed_op.matrix()
array([[ 1,  1],
       [ 1, -1]])