Skip to content

(2/2) Combine Pauli measurements and postselection#7970

Open
ddddddanni wants to merge 10 commits intoquantumlib:mainfrom
ddddddanni:pauli_postselection
Open

(2/2) Combine Pauli measurements and postselection#7970
ddddddanni wants to merge 10 commits intoquantumlib:mainfrom
ddddddanni:pauli_postselection

Conversation

@ddddddanni
Copy link
Copy Markdown
Collaborator

@ddddddanni ddddddanni commented Mar 24, 2026

This commit implements the postselection symmetry functionality in CircuitToPauliStringsParameters. Circuits provided with postselection_symmetries will now successfully filter measurement results based on the expected eigenvalues rather than defaulting to the confusion matrix method.

@ddddddanni ddddddanni requested review from a team and vtomole as code owners March 24, 2026 03:19
@ddddddanni ddddddanni marked this pull request as draft March 24, 2026 03:19
@github-actions github-actions Bot added the size: L 250< lines changed <1000 label Mar 24, 2026
@ddddddanni
Copy link
Copy Markdown
Collaborator Author

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!

Some testing in this colab.

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.

Actually, maybe the docstrings could make it a bit clearer that it doesn't perform readout benchmarking if postselection symmetries are included and that the parameters readout_repetitions and num_random_bitstrings are ignored in this case.

@ddddddanni
Copy link
Copy Markdown
Collaborator Author

Actually, maybe the docstrings could make it a bit clearer that it doesn't perform readout benchmarking if postselection symmetries are included and that the parameters readout_repetitions and num_random_bitstrings are ignored in this case.

Done! I added this: https://screenshot.googleplex.com/6B7SV7HRxZWyH9C

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.63%. Comparing base (b3366ab) to head (e16729b).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7970    +/-   ##
========================================
  Coverage   99.63%   99.63%            
========================================
  Files        1110     1110            
  Lines       99738    99855   +117     
========================================
+ Hits        99376    99493   +117     
  Misses        362      362            

☔ 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.

@ddddddanni ddddddanni marked this pull request as ready for review April 15, 2026 21:45
Copy link
Copy Markdown
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

Please check if we can avoid some code repetition (see inline).

We should also check if measure_pauli_strings can have a simpler interface.

@eliottrosenberg - is it required for measure_pauli_strings to handle an argument with a mixture of post-selection-symmetry and confusion-matrix cases?

Comment thread cirq-core/cirq/contrib/paulistring/__init__.py Outdated
Comment on lines +1113 to +1115
Note: If `postselection_symmetries` are included in the `circuits_to_pauli` parameters,
the circuit will be measured using the post-selection symmetry method.
In this case, the `readout_repetitions` and `num_random_bitstrings` arguments are ignored.
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 a bit over-complicated interface. Both readout_repetitions and num_random_bitstrings arguments are mandatory, but unused for the post-selection symmetry case.

Would it work to include readout_repetitions and num_random_bitstrings in CircuitToPauliStringsParameters where they would be mutually exclusive with postselection_symmetries and the split this interface to 2 overloads:

1 legacy interface (if feasible deprecate):

@overload
def measure_pauli_strings(
    circuits_to_pauli: (
        Mapping[circuits.FrozenCircuit, Sequence[ops.PauliString]
        | Sequence[Sequence[ops.PauliString]]]
    ),
    sampler: work.Sampler,
    pauli_repetitions: int,
    readout_repetitions: int,
    num_random_bitstrings: int,
    ...
)

2 preferred interface (readout_repetitions, num_random_bitstrings in CircuitToPauliStringsParameters)

@overload
def measure_pauli_strings(
    circuits_to_pauli: list[CircuitToPauliStringsParameters],
    sampler: work.Sampler,
    pauli_repetitions: int,
    ...
)

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.

I'm not sure if it's better to put readout_repetitions and num_random_bitstrings under CircuitToPauliStringsParameters, because these two parameters are more like global parameters that could take effects to all circuits, while CircuitToPauliStringsParameters is only for one circuit. wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants