-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Ensure the result of simulation is normalized #6522
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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 ☔ View full report in Codecov by Sentry. |
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. |
@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 |
ret = self._get_merged_sim_state().target_tensor.reshape(-1) | ||
return ret / np.linalg.norm(ret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we raise UserWarning if abs(norm(state_vector) - 1) > np.sqrt(np.finfo(state_vector.dtype).eps)
?
That should be sufficient for an accumulated round off from ~1/eps operations, but give some warning in case the state vector would be widely off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have some check here so we don't re-normalize incorrect state vector.
This fixes failure of check/pytest -n0 cirq-core/cirq/circuits/circuit_test.py::test_final_state_vector which happened because normalization of a state vector at `np.complex64` precision can subtly increase the overall round-off error. Follow up to quantumlib#6522 and quantumlib#6402
…mlib#6556) This fixes failure of check/pytest -n0 cirq-core/cirq/circuits/circuit_test.py::test_final_state_vector which happened because normalization of a state vector at `np.complex64` precision can subtly increase the overall round-off error. Follow up to quantumlib#6522 and quantumlib#6402
…mlib#6556) This fixes failure of check/pytest -n0 cirq-core/cirq/circuits/circuit_test.py::test_final_state_vector which happened because normalization of a state vector at `np.complex64` precision can subtly increase the overall round-off error. Follow up to quantumlib#6522 and quantumlib#6402
cirq.Simulator
final_state_vector is not normalized #6402