Skip to content

Add the capability to accept group Paulis that can be measured using same measurement results#7236

Merged
eliottrosenberg merged 8 commits intoquantumlib:mainfrom
ddddddanni:group_ps
May 1, 2025
Merged

Add the capability to accept group Paulis that can be measured using same measurement results#7236
eliottrosenberg merged 8 commits intoquantumlib:mainfrom
ddddddanni:group_ps

Conversation

@ddddddanni
Copy link
Copy Markdown
Collaborator

@ddddddanni ddddddanni commented Apr 8, 2025

This PR introduces an optimization to the tool responsible for measuring expectation values of Pauli strings (the tool was added in #7067). Previously, each Pauli string required separate measurement results for expectation calculation. By allowing gwc Pauli strings as a group, the tool can now measure the expectation values for multiple gwc pauli strings using a single set of measurement results.

@ddddddanni ddddddanni changed the title Add the capability to group Paulis that can be measured simultaneously Add the capability to accept group Paulis that can be measured using same measurement results Apr 9, 2025
@ddddddanni ddddddanni marked this pull request as ready for review April 9, 2025 06:37
@ddddddanni ddddddanni requested review from a team and vtomole as code owners April 9, 2025 06:37
@ddddddanni
Copy link
Copy Markdown
Collaborator Author

Hey @eliottrosenberg and @NoureldinYosri if you could take a look at this. Thanks!

@pavoljuhas pavoljuhas added the priority/after-1.5 Leave for after the Cirq 1.5 release label Apr 9, 2025
Copy link
Copy Markdown
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks, @ddddddanni!

@github-actions github-actions bot added the size: L 250< lines changed <1000 label Apr 15, 2025
Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial review

return op1 == op2


def _are_two_qwc(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a more descriptive name

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

first_value = next(iter(circuits_to_pauli.values()))
for circuit, pauli_strs_list in circuits_to_pauli.items():
if not isinstance(pauli_strs_list, list):
raise TypeError(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is too restricitve ... what if the variable is a tuple or iterator? same below

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Change to check sequence instead of list.

for circuit, paulis in circuits_to_pauli.items():
normalized_circuits_to_pauli[circuit] = [[ps] for ps in paulis] # type: ignore[list-item]
return normalized_circuits_to_pauli
return circuits_to_pauli # type: ignore
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are all these ignore statements here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I use some cast to make the type as expected.

Copy link
Copy Markdown
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @ddddddanni

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.67%. Comparing base (de37106) to head (72c0600).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7236    +/-   ##
========================================
  Coverage   98.67%   98.67%            
========================================
  Files        1108     1108            
  Lines       96220    96407   +187     
========================================
+ Hits        94942    95129   +187     
  Misses       1278     1278            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NoureldinYosri NoureldinYosri added this pull request to the merge queue Apr 30, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 30, 2025
…same measurement results (#7236)

* Modify the pauli string measurement tool to allow a group of paulis been measured using the same measurement results

* Add more tests and fix some code

* Fix format

* Fix type

* Fix lint

* Make changes based on @NoureldinYosri's comments.

* Fix format and coverage. Also optimize group pauli tests to make them finish quicker.

---------

Co-authored-by: Noureldin <noureldinyosri@google.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 30, 2025
@NoureldinYosri NoureldinYosri added this pull request to the merge queue Apr 30, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 30, 2025
@eliottrosenberg eliottrosenberg added this pull request to the merge queue May 1, 2025
Merged via the queue into quantumlib:main with commit 63b0f17 May 1, 2025
39 checks passed
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…same measurement results (quantumlib#7236)

* Modify the pauli string measurement tool to allow a group of paulis been measured using the same measurement results

* Add more tests and fix some code

* Fix format

* Fix type

* Fix lint

* Make changes based on @NoureldinYosri's comments.

* Fix format and coverage. Also optimize group pauli tests to make them finish quicker.

---------

Co-authored-by: Noureldin <noureldinyosri@google.com>
github-merge-queue bot pushed a commit that referenced this pull request Jun 24, 2025
…uli_strings``` method (#7416)

[PR #7236](#7236) adds the
feature to measure groups of qubit-wise-commuting Pauli operators
simultaneously.

However, the current implementation generates a separate readout circuit
for each individual Pauli operator within a group. This leads to
non-simultaneous measurements, which is corrected in this PR.
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 25, 2025
…uli_strings``` method (quantumlib#7416)

[PR quantumlib#7236](quantumlib#7236) adds the
feature to measure groups of qubit-wise-commuting Pauli operators
simultaneously.

However, the current implementation generates a separate readout circuit
for each individual Pauli operator within a group. This leads to
non-simultaneous measurements, which is corrected in this PR.
ddddddanni added a commit to ddddddanni/Cirq that referenced this pull request Jul 15, 2025
…uli_strings``` method (quantumlib#7416)

[PR quantumlib#7236](quantumlib#7236) adds the
feature to measure groups of qubit-wise-commuting Pauli operators
simultaneously.

However, the current implementation generates a separate readout circuit
for each individual Pauli operator within a group. This leads to
non-simultaneous measurements, which is corrected in this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/after-1.5 Leave for after the Cirq 1.5 release size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants