Skip to content

Commit 1460b9c

Browse files
Apply suggestions from code review
Co-authored-by: Austin Huang <[email protected]>
1 parent a7e54b5 commit 1460b9c

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

pennylane/estimator/compact_hamiltonian.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,9 @@ def _validate_pauli_dist(pauli_dist: dict) -> bool:
422422

423423
def _pauli_dist_from_commuting_groups(commuting_groups: tuple[dict]):
424424
"""Construct the total Pauli word distribution from the commuting groups."""
425-
total_pauli_dist = defaultdict(int)
426-
425+
total_pauli_dist = Counter()
427426
for group in commuting_groups:
428-
for pauli_word, frequency in group.items():
429-
total_pauli_dist[pauli_word] += frequency
430-
427+
total_pauli_dist.update(group)
431428
return total_pauli_dist
432429

433430

pennylane/estimator/templates/trotter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,8 +2097,7 @@ def cost_pauli_group(pauli_dist: dict):
20972097
a commuting group of Pauli words.
20982098
20992099
"""
2100-
gate_count_lst = []
2101-
for pauli_word, count in pauli_dist.items():
2102-
gate_count_lst.append(GateCount(PauliRot.resource_rep(pauli_word), count))
2103-
2104-
return gate_count_lst
2100+
return [
2101+
GateCount(PauliRot.resource_rep(pauli_word), count)
2102+
for pauli_word, count in pauli_dist.items()
2103+
]

0 commit comments

Comments
 (0)