Skip to content

Commit

Permalink
Merge pull request #842 from qiboteam/chsh_fail
Browse files Browse the repository at this point in the history
Handling `ZeroDivisionError`
  • Loading branch information
andrea-pasquale authored May 15, 2024
2 parents 09feed8 + 4336866 commit f869f28
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Auxiliary functions to run CHSH protocol."""

from qibo.config import log

READOUT_BASIS = ["ZZ", "ZX", "XZ", "XX"]


Expand All @@ -17,4 +19,8 @@ def compute_chsh(frequencies, basis, i):
chsh += (-1) ** (int(outcome[0]) + int(outcome[1])) * freq[outcome][i]
aux += 1
nshots = sum(freq[x][i] for x in freq)
return chsh / nshots
try:
return chsh / nshots
except ZeroDivisionError:
log.warning("Zero number of shots, returning zero.")
return 0

0 comments on commit f869f28

Please sign in to comment.