Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cirq-core/cirq/sim/state_vector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ def final_state_vector(self) -> np.ndarray:
"skipping renormalization"
)
return ret
return ret / norm
# normalize only if doing so improves the round-off on total probability
ret_norm = ret / norm
round_off_change = abs(np.vdot(ret_norm, ret_norm) - 1) - abs(np.vdot(ret, ret) - 1)
result = ret_norm if round_off_change < 0 else ret
return result

def state_vector(self, copy: bool = False) -> np.ndarray:
"""Return the state vector at the end of the computation.
Expand Down