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 andTensor
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.PauliY(0), qml.PauliX(0) @ qml.PauliX(1), qml.PauliZ(1)] >>> coeffs = [1.43, 4.21, 0.97] >>> obs_groupings, coeffs_groupings = group_observables(obs, coeffs, 'anticommuting', 'lf') >>> obs_groupings [[PauliZ(wires=[1]), PauliX(wires=[0]) @ PauliX(wires=[1])], [PauliY(wires=[0])]] >>> coeffs_groupings [[0.97, 4.21], [1.43]]