@@ -38,16 +38,20 @@ class LinearCombination(Sum):
38
38
coeffs (tensor_like): coefficients of the ``LinearCombination`` expression
39
39
observables (Iterable[Observable]): observables in the ``LinearCombination`` expression, of same length as ``coeffs``
40
40
simplify (bool): Specifies whether the ``LinearCombination`` is simplified upon initialization
41
- (like-terms are combined). The default value is `False`. Note that ``coeffs`` cannot
42
- be differentiated when using the ``'torch'`` interface and ``simplify=True``. Use of this argument is deprecated.
41
+ (like-terms are combined). The default value is `False`. Note that ``coeffs`` cannot
42
+ be differentiated when using the ``'torch'`` interface and ``simplify=True``. Use of this argument is deprecated.
43
43
grouping_type (str): If not ``None``, compute and store information on how to group commuting
44
44
observables upon initialization. This information may be accessed when a :class:`~.QNode` containing this
45
45
``LinearCombination`` is executed on devices. The string refers to the type of binary relation between Pauli words.
46
46
Can be ``'qwc'`` (qubit-wise commuting), ``'commuting'``, or ``'anticommuting'``.
47
- method (str): The graph coloring heuristic to use in solving minimum clique cover for grouping, which
48
- can be ``'lf'`` (Largest First) or ``'rlf'`` (Recursive Largest First). Ignored if ``grouping_type=None``.
47
+ method (str): The graph colouring heuristic to use in solving minimum clique cover for grouping, which
48
+ can be ``'lf'`` (Largest First), ``'rlf'`` (Recursive Largest First), ``'dsatur'`` (Degree of Saturation), or ``'gis'`` (IndependentSet).
49
+ Defaults to ``'lf'``. Ignored if ``grouping_type=None``.
49
50
id (str): name to be assigned to this ``LinearCombination`` instance
50
51
52
+ .. seealso:: `rustworkx.ColoringStrategy <https://www.rustworkx.org/apiref/rustworkx.ColoringStrategy.html#coloringstrategy>`_
53
+ for more information on the ``('lf', 'dsatur', 'gis')`` strategies.
54
+
51
55
.. warning::
52
56
The ``simplify`` argument is deprecated and will be removed in a future release.
53
57
Instead, you can call ``qml.simplify`` on the constructed operator.
@@ -122,7 +126,7 @@ def __init__(
122
126
observables : list [Operator ],
123
127
simplify = False ,
124
128
grouping_type = None ,
125
- method = "rlf " ,
129
+ method = "lf " ,
126
130
_grouping_indices = None ,
127
131
_pauli_rep = None ,
128
132
id = None ,
@@ -229,7 +233,7 @@ def terms(self):
229
233
"""
230
234
return self .coeffs , self .ops
231
235
232
- def compute_grouping (self , grouping_type = "qwc" , method = "rlf " ):
236
+ def compute_grouping (self , grouping_type = "qwc" , method = "lf " ):
233
237
"""
234
238
Compute groups of operators and coefficients corresponding to commuting
235
239
observables of this ``LinearCombination``.
@@ -242,9 +246,10 @@ def compute_grouping(self, grouping_type="qwc", method="rlf"):
242
246
Args:
243
247
grouping_type (str): The type of binary relation between Pauli words used to compute
244
248
the grouping. Can be ``'qwc'``, ``'commuting'``, or ``'anticommuting'``.
245
- method (str): The graph coloring heuristic to use in solving minimum clique cover for
249
+ Defaults to ``'qwc'``.
250
+ method (str): The graph colouring heuristic to use in solving minimum clique cover for
246
251
grouping, which can be ``'lf'`` (Largest First) or ``'rlf'`` (Recursive Largest
247
- First).
252
+ First). Defaults to ``'lf'``.
248
253
249
254
**Example**
250
255
@@ -271,27 +276,9 @@ def compute_grouping(self, grouping_type="qwc", method="rlf"):
271
276
272
277
_ , ops = self .terms ()
273
278
274
- with qml .QueuingManager .stop_recording ():
275
- op_groups = qml .pauli .group_observables (ops , grouping_type = grouping_type , method = method )
276
-
277
- ops = copy (ops )
278
-
279
- indices = []
280
- available_indices = list (range (len (ops )))
281
- for partition in op_groups : # pylint:disable=too-many-nested-blocks
282
- indices_this_group = []
283
- for pauli_word in partition :
284
- # find index of this pauli word in remaining original observables,
285
- for ind , observable in enumerate (ops ):
286
- if qml .pauli .are_identical_pauli_words (pauli_word , observable ):
287
- indices_this_group .append (available_indices [ind ])
288
- # delete this observable and its index, so it cannot be found again
289
- ops .pop (ind )
290
- available_indices .pop (ind )
291
- break
292
- indices .append (tuple (indices_this_group ))
293
-
294
- self ._grouping_indices = tuple (indices )
279
+ self ._grouping_indices = qml .pauli .compute_partition_indices (
280
+ ops , grouping_type = grouping_type , method = method
281
+ )
295
282
296
283
@property
297
284
def wires (self ):
0 commit comments