-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use SVD-based fidelity for density matrices and add numerical stability test #7292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7292 +/- ##
=======================================
Coverage 98.68% 98.68%
=======================================
Files 1112 1112
Lines 97599 97616 +17
=======================================
+ Hits 96315 96334 +19
+ Misses 1284 1282 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@RevanthGundala would you be able to take a look at the merge conflicts? |
|
This pull request has been automatically labeled as stale because 90 days have passed without comments or other activity. If no further activity occurs and the If you have questions or feedback about this process, we welcome your input. You can open a new issue to let us know (please also reference this issue there, for continuity), or reach out to the project maintainers at quantum-oss-maintainers@google.com. |
|
This pull request has been automatically labeled as stale because 90 days have passed without comments or other activity. If no further activity occurs and the If you have questions or feedback about this process, we welcome your input. You can open a new issue to let us know (please also reference this issue there, for continuity), or reach out to the project maintainers at quantum-oss-maintainers@google.com. |
Summary
Fixes #4819
This PR replaces the existing eigen‑decomposition formula for two density matrices
with an equivalent but more accurate form
This ensures fidelity never exceeds 1 due to round‑off error in higher dimensions.
What’s Changed
In cirq/qis/measures.py, the density‑matrix branch of _fidelity_state_vectors_or_density_matrices now uses sqrtm + svdvals.
A new unit test test_fidelity_numerical_stability_high_dim in measures_test.py constructs a 10‑qubit pure state, traces out one qubit, and verifies that the old eigen‑value‑based fidelity exceeds 1, and the new SVD‑based fidelity ≈ 1.
Testing
Ran pytest cirq-core/cirq/qis/measures_test.py::test_fidelity_numerical_stability_high_dim — old formula fails (>1), new passes (≈1).