qml.pauli.group_observables

group_observables(observables, coefficients=None, grouping_type='qwc', method='lf')[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 (TensorLike) – 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 colouring heuristic to use in solving minimum clique cover, which can be 'lf' (Largest First), 'rlf' (Recursive Largest First), 'dsatur' (Degree of Saturation), or 'gis' (IndependentSet). Defaults to 'lf'.

Returns

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

  • list[TensorLike]: 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

See also

rustworkx.ColoringStrategy for more information on the ('lf', 'dsatur', 'gis') strategies.

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
[[Y(0), X(0) @ X(1)], [Z(1)]]
>>> coeffs_groupings
[[1.43, 4.21], [0.97]]