Skip to content

Conversation

pavoljuhas
Copy link
Collaborator

@pavoljuhas pavoljuhas commented Mar 25, 2025

Ensure random Pauli strings have a non-identity operator for real.
Also add missing spaces to the exception message.

This fixes randomly-seed dependent test failure for

check/pytest -n0 --randomly-seed=3289494540 \
    cirq-core/cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py::test_many_circuits_input_measurement_with_noise \
    cirq-core/cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py::test_many_circuits_with_coefficient

cc: @ddddddanni

Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.14%. Comparing base (e1deffc) to head (834eda1).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7185      +/-   ##
==========================================
- Coverage   98.14%   98.14%   -0.01%     
==========================================
  Files        1100     1100              
  Lines       96194    96191       -3     
==========================================
- Hits        94412    94408       -4     
- Misses       1782     1783       +1     

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

Copy link
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.

can this be a symptom of a real bug?

@pavoljuhas
Copy link
Collaborator Author

can this be a symptom of a real bug?

The test flakes were failing on Pauli string validation which rejects identity-only strings, for example, https://github.com/quantumlib/Cirq/actions/runs/14068636480/job/39397251223#step:7:402

The original test code intended to avoid such strings, but could in fact produce them with

operators = {q: random.choice(pauli_ops) for q in qubits}

This PR ensures that there is at least one non-identity Pauli in the operators dictionary, which prevents the flake.

@pavoljuhas pavoljuhas added this pull request to the merge queue Mar 26, 2025
Merged via the queue into quantumlib:main with commit 0eea89e Mar 26, 2025
38 checks passed
@pavoljuhas pavoljuhas deleted the fix-paulistring-flake branch March 26, 2025 01:38
@ddddddanni
Copy link
Contributor

Thanks for fixing it! I recall adding the Pauli-I validation to the verification stage, but I overlooked the need to prevent the generation of all Pauli-I test strings in the test file. Thanks for catching the error and fix it quickly!

BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…uantumlib#7185)

* Deflake pauli_string_measurement_with_readout_mitigation_test

Ensure random Pauli strings have a non-identity operator for real.

* Add missing spaces to exception message

* Simplify - make do without an extra local variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants