Skip to content

Commit 76abde3

Browse files
feat: adding greedy algorithm for pauli grouping
1 parent 91fbac5 commit 76abde3

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

mpqp/core/instruction/measurement/expectation_value.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ def _check_targets_order(self):
371371
)
372372

373373
def get_pauli_grouping(
374-
self, method: Literal["full_commutative_graph", "b"] = "full_commutative_graph"
374+
self,
375+
method: Literal[
376+
"full_clique", "full_greedy", "qubit_wise_clique"
377+
] = "full_greedy",
375378
) -> list[set[PauliStringMonomial]]:
376379
"""
377380
TODO: decompose the observables, regroup the pauli measurements by commutativity relation,

mpqp/tools/pauli_grouping.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
from mpqp.core.instruction.measurement.pauli_string import PauliStringMonomial
22

33

4-
def full_commutation_pauli_grouping(monomials: set[PauliStringMonomial]):
4+
def full_commutation_pauli_grouping_greedy(monomials: set[PauliStringMonomial]):
5+
"""
6+
TODO: comment
7+
Args:
8+
monomials:
9+
10+
Returns:
11+
12+
"""
13+
groups = []
14+
15+
for m in monomials:
16+
added = False
17+
for group in groups:
18+
if all(m.commutes_with(m_g) for m_g in group):
19+
group.append(m)
20+
added = True
21+
break
22+
23+
if not added:
24+
groups.append([m])
25+
26+
return groups
27+
28+
29+
def full_commutation_pauli_grouping_ibm_clique(monomials: set[PauliStringMonomial]):
530
pass
631

732

0 commit comments

Comments
 (0)