qml.pauli.group_observables

group_observables(observables, coefficients=None, grouping_type='qwc', method='rlf')[source]

Partitions a list of observables (Pauli operations and tensor products thereof) into groupings according to a binary relation (qubit-wise commuting, fully-commuting, or anticommuting).

Partitions are found by 1) mapping the list of observables to a graph where vertices represent observables and edges encode the binary relation, then 2) solving minimum clique cover for the graph using graph-colouring heuristic algorithms.

Parameters
  • observables (list[Observable]) – a list of Pauli word Observable instances (Pauli operation instances and Tensor instances thereof)

  • coefficients (tensor_like) – A tensor or list of coefficients. If not specified, output partitioned_coeffs is not returned.

  • grouping_type (str) – The type of binary relation between Pauli words. Can be 'qwc', 'commuting', or 'anticommuting'.

  • method (str) – the graph coloring heuristic to use in solving minimum clique cover, which can be 'lf' (Largest First) or 'rlf' (Recursive Largest First)

Returns

  • list[list[Observable]]: A list of the obtained groupings. Each grouping is itself a list of Pauli word Observable instances.

  • list[tensor_like]: A list of coefficient groupings. Each coefficient grouping is itself a tensor or list of the grouping’s corresponding coefficients. This is only returned if coefficients are specified.

Return type

tuple

Raises

IndexError – if the input list of coefficients is not of the same length as the input list of Pauli words

Example

>>> obs = [qml.Y(0), qml.X(0) @ qml.X(1), qml.Z(1)]
>>> coeffs = [1.43, 4.21, 0.97]
>>> obs_groupings, coeffs_groupings = group_observables(obs, coeffs, 'anticommuting', 'lf')
>>> obs_groupings
[[Z(1), X(0) @ X(1)],
 [Y(0)]]
>>> coeffs_groupings
[[0.97, 4.21], [1.43]]