Skip to content

Commit

Permalink
feat: Fix compute_chsh
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-pasquale committed Aug 30, 2024
1 parent 64ca7fc commit dbe4121
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
28 changes: 10 additions & 18 deletions src/qibocal/protocols/two_qubit_interaction/chsh/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .utils import READOUT_BASIS


def create_bell_circuit(theta=np.pi / 4, bell_state=0):
def create_bell_circuit(bell_state=0):
"""Creates the circuit to generate the bell states and with a theta-measurement
bell_state chooses the initial bell state for the test:
0 -> |00>+|11>
Expand All @@ -32,7 +32,7 @@ def create_bell_circuit(theta=np.pi / 4, bell_state=0):
return c


def create_bell_circuit_native(theta=np.pi / 4, bell_state=0):
def create_bell_circuit_native(bell_state=0):
"""Creates the circuit to generate the bell states and with a theta-measurement
bell_state chooses the initial bell state for the test:
0 -> |00>+|11>
Expand All @@ -43,30 +43,22 @@ def create_bell_circuit_native(theta=np.pi / 4, bell_state=0):
"""

c = Circuit(2)
p = [0, 0]
c.add(gates.GPI2(0, np.pi / 2))
c.add(gates.GPI2(1, np.pi / 2))
c.add(gates.CZ(0, 1))
c.add(gates.GPI2(1, np.pi / 2))
c.add(gates.GPI2(1, -np.pi / 2))

c.add(gates.GPI2(0, p[0]))
if bell_state == 0:
p[0] += np.pi
elif bell_state == 1:
p[0] += 0
c.add(gates.Z(0))
elif bell_state == 2:
p[0] += 0
c.add(gates.GPI2(0, p[0]))
c.add(gates.GPI2(0, p[0]))
c.add(gates.GPI(0, 0))
elif bell_state == 3:
p[0] += np.pi
c.add(gates.GPI2(0, p[0]))
c.add(gates.GPI2(0, p[0]))
c.add(gates.Z(0))
c.add(gates.GPI(0, 0))

p[0] += theta
c.add(gates.GPI2(0, np.pi))
c.add(gates.GPI2(0, 0))

return c, p
return c


def create_chsh_circuits(
Expand All @@ -82,7 +74,7 @@ def create_chsh_circuits(
create_bell = create_bell_circuit_native if native else create_bell_circuit
chsh_circuits = {}
for basis in readout_basis:
c = create_bell(theta, bell_state)
c = create_bell(bell_state)
c.add(gates.RY(0, theta))
for i, base in enumerate(basis):
if base == "X":
Expand Down
3 changes: 2 additions & 1 deletion src/qibocal/protocols/two_qubit_interaction/chsh/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ def _fit(data: CHSHData) -> CHSHResults:
# mitigated_freq[format(j, f"0{2}b")].append(float(val))
# mitigated_freq_list.append(mitigated_freq)
results[pair[0], pair[1], bell_state] = [
compute_chsh(bell_pair_data, l) for l in range(len(data.thetas))
compute_chsh(bell_pair_data, l, bell_state)
for l in range(len(data.thetas))
]

# if data.mitigation_matrix:
Expand Down
7 changes: 4 additions & 3 deletions src/qibocal/protocols/two_qubit_interaction/chsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
READOUT_BASIS = ["ZZ", "ZX", "XZ", "XX"]


def compute_chsh(frequencies, i):
def compute_chsh(frequencies, i, bell_state):
"""Computes the chsh inequality out of the frequencies of the 4 circuits executed."""

zz = frequencies["ZZ"]
Expand All @@ -17,5 +17,6 @@ def compute_chsh(frequencies, i):
result_zx = zx["11"][i] + zx["00"][i] - zx["10"][i] - zx["01"][i]
result_xz = xz["11"][i] + xz["00"][i] - xz["10"][i] - xz["01"][i]
result_xx = xx["11"][i] + xx["00"][i] - xx["10"][i] - xx["01"][i]

return (result_zz + result_xz - result_zx + result_xx) / nshots
if bell_state % 2 == 0:
return (result_zz + result_xz - result_zx + result_xx) / nshots
return (result_zz + result_xz + result_zx - result_xx) / nshots

0 comments on commit dbe4121

Please sign in to comment.