You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve implementation of group_observables (#6043)
**Context:**
`qml.pauli.group_observables` has several areas of improvement that make
the calculation slow. This PR attempts to address some of them.
**Description of the Change:**
1. Solve the Graph colouring algorithm using `Rustworkx` instead of
custom implementation. This adds 2 additional methods to solve the
Minimum Clique cover problem: DSATUR (`'dsatur'`) and IndependentSet
(`'gis'`)
2. Use the symplectic representation of the Pauli observables to
construct the adjacency matrix of the complement graph.
3. Introduce a new function to obtain the indices of the partitions
directly: `qml.pauli.compute_partition_indices`
**Benefits:**
Improves of orders of magnitude compared to the current implementation
of the `qwc` grouping type strategy. The current implementation is based
on an $\mathcal{O}(m^2)$ computation, with $m$ the number of observables
to be grouped. Instead, taking advantage of the symplectic inner
product, and its relation with the commutator and anti commutator of
Pauli observables [1], we can obtain a significant improvement.

In addition, by introducing `qml.pauli.compute_partition_indices`, we
now avoid the (rather often) inefficient computation of partitions of
observables, just to then calculate the indices from them - see
https://github.com/PennyLaneAI/pennylane/blob/2892a9a0aa6797912ef4a03f3c4759eaff01d8ef/pennylane/ops/qubit/hamiltonian.py#L37
Instead, we obtain the indices of the partitions directly from the graph
colouring algorithm. Putting all together, the improvement in
performance when calculating the partitions of large Hamiltonians is
evident.

This graph was obtained by running
``` python
%timeit hamiltonian.compute_grouping(grouping_type="qwc", method='lf')
```
**Notes:**
Profiling the implementation from `linear_combination` demonstrates that
the post processing to obtain the indices remains a significant burden
in the calculations, and therefore should be addressed for the remaining
functions - see reference code above.

[1] Andrew Jena (2019). Partitioning Pauli Operators: in Theory and in
Practice. UWSpace. http://hdl.handle.net/10012/15017
[sc-64594]
## Performance comparisons between colouring algorithms
Comparison for `LinearCombination.compute_grouping()`


Comparison for `colour_paui_graph` (only between `Rustworkx` algorithms)

---------
Co-authored-by: Ali Asadi <[email protected]>
*`qml.pauli.group_observables` now uses `Rustworkx` colouring algorithms to solve the Minimum Clique Cover problem.
57
+
This adds two new options for the `method` argument: `dsatur` and `gis`. In addition, the creation of the adjancecy matrix
58
+
now takes advantage of the symplectic representation of the Pauli observables. An additional function `qml.pauli.compute_partition_indices`
59
+
is added to calculate the indices from the partitioned observables more efficiently. `qml.pauli.grouping.PauliGroupingStrategy.idx_partitions_from_graph`
60
+
can be used to compute partitions of custom indices. These changes improve the wall time of `qml.LinearCombination.compute_grouping`
61
+
and the `grouping_type='qwc'` by orders of magnitude.
0 commit comments