Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
RevanthGundala wants to merge4 commits intoquantumlib:main
base:main
Choose a base branch
Loading
fromRevanthGundala:batch

Conversation

@RevanthGundala
Copy link
Contributor

Summary

Fixes#4819

This PR replaces the existing eigen‑decomposition formula for two density matrices

state1_sqrt=_sqrt_positive_semidefinite_matrix(state1)eigs=eigvalsh(state1_sqrt @state2 @state1_sqrt)trace=sum(sqrt(abs(eigs)))fidelity=trace**2

with an equivalent but more accurate form

rho1_sqrt=scipy.linalg.sqrtm(rho1)rho2_sqrt=scipy.linalg.sqrtm(rho2)fidelity=np.sum(scipy.linalg.svdvals(rho1_sqrt @rho2_sqrt))**2

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

@codecov
Copy link

codecovbot commentedApr 22, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.68%. Comparing base (e9a592d) to head (9a46b19).
⚠️ Report is 249 commits behind head on main.

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

@github-actionsgithub-actionsbot added the size: S10< lines changed <50 labelApr 30, 2025
@mhucka
Copy link
Contributor

@RevanthGundala would you be able to take a look at the merge conflicts?

RevanthGundala reacted with thumbs up emoji

@github-actions
Copy link

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 thestatus/stale label is not removed by a maintainer within 60 days, this pull request will be closed. If you would like to restore its active status, please leave a comment here; doing so will cause the staleness handler to remove the label.

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 atquantum-oss-maintainers@google.com.

@github-actionsgithub-actionsbot added status/staleThis has been closed due to inactivity for an extended period of time. and removed status/staleThis has been closed due to inactivity for an extended period of time. labelsAug 20, 2025
@github-actions
Copy link

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 thestatus/stale label is not removed by a maintainer within 60 days, this pull request will be closed. If you would like to restore its active status, please leave a comment here; doing so will cause the staleness handler to remove the label.

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 atquantum-oss-maintainers@google.com.

@github-actionsgithub-actionsbot added status/staleThis has been closed due to inactivity for an extended period of time. and removed status/staleThis has been closed due to inactivity for an extended period of time. labelsNov 19, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@vtomolevtomoleAwaiting requested review from vtomolevtomole is a code owner

@viathorviathorAwaiting requested review from viathorviathor is a code owner automatically assigned from quantumlib/cirq-maintainers

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

size: S10< lines changed <50

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Fidelity calculation for density matrices improvement

2 participants

@RevanthGundala@mhucka

[8]ページ先頭

©2009-2025 Movatter.jp