From c9fbe07fd6fff5a2526eb501ae3f20c595afde5b Mon Sep 17 00:00:00 2001 From: andrea-pasquale Date: Tue, 14 May 2024 11:57:36 +0400 Subject: [PATCH 1/2] fix: Handle division 0 error --- .../characterization/two_qubit_interaction/chsh/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py b/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py index fea6225d1..d18fc97d7 100644 --- a/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py +++ b/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py @@ -17,4 +17,7 @@ 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: + return 0 From 4336866ddfd05c1998ef11f2301620423d1534a9 Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 14 May 2024 13:12:09 +0400 Subject: [PATCH 2/2] feat: Add log --- .../characterization/two_qubit_interaction/chsh/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py b/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py index d18fc97d7..0f38a3589 100644 --- a/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py +++ b/src/qibocal/protocols/characterization/two_qubit_interaction/chsh/utils.py @@ -1,5 +1,7 @@ """Auxiliary functions to run CHSH protocol.""" +from qibo.config import log + READOUT_BASIS = ["ZZ", "ZX", "XZ", "XX"] @@ -20,4 +22,5 @@ def compute_chsh(frequencies, basis, i): try: return chsh / nshots except ZeroDivisionError: + log.warning("Zero number of shots, returning zero.") return 0