quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Ensure the result of simulation is normalized #6522

Closed NoureldinYosri closed 5 months ago

NoureldinYosri commented 6 months ago
codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.78%. Comparing base (f955650) to head (7856e81). Report is 1 commits behind head on main.

:exclamation: Current head 7856e81 differs from pull request most recent head 9aac89e. Consider uploading reports for the commit 9aac89e to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6522 +/- ## ========================================== - Coverage 97.78% 97.78% -0.01% ========================================== Files 1107 1105 -2 Lines 95182 95113 -69 ========================================== - Hits 93073 93004 -69 Misses 2109 2109 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

daxfohl commented 6 months ago

I considered doing this in the past when the earlier issue came up, but was concerned it was like sweeping dirt under the rug. Does doing this then make other invariants start failing? I think it's worth looking at what other projects do here, and try to follow prior art on the subject.

NoureldinYosri commented 6 months ago

@daxfohl for state vector there is not an issue

for density matrix it doesn't work (I reverted my changes and restricted this PR to state vector simulation). the invariant of density matrix is that $Tr[\rho^2] \leq 1$ with equality if and only if $\rho$ is pure. I don't think we should implicitly add the computation $Tr[\rho^2]$