Skip to content

Commit 324a086

Browse files
make DensityMatrixSimulator more numerically stable (#6850)
Co-authored-by: Pavol Juhas <[email protected]>
1 parent ea605d4 commit 324a086

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cirq-core/cirq/sim/simulation_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ def state_probabilities_by_indices(
5656
probs = np.sum(probs, axis=-1)
5757

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

0 commit comments

Comments
 (0)