Skip to content

Commit

Permalink
make DensityMatrixSimulator more numerically stable (#6850)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavol Juhas <[email protected]>
  • Loading branch information
NoureldinYosri and pavoljuhas authored Dec 17, 2024
1 parent ea605d4 commit 324a086
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cirq-core/cirq/sim/simulation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ def state_probabilities_by_indices(
probs = np.sum(probs, axis=-1)

# To deal with rounding issues, ensure that the probabilities sum to 1.
return probs / np.sum(probs)
probs = np.clip(probs, 0, None)
probs /= probs.sum()
return probs

0 comments on commit 324a086

Please sign in to comment.