Skip to content

Commit d7f30da

Browse files
Merge pull request #1047 from qiboteam/chsh
Increase the compatibility between transpiler and chsh
2 parents b7a9249 + 4c0013a commit d7f30da

File tree

2 files changed

+38
-42
lines changed

2 files changed

+38
-42
lines changed

src/qibocal/protocols/two_qubit_interaction/chsh/circuits.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .utils import READOUT_BASIS
88

99

10-
def create_bell_circuit(nqubits, qubits, theta=np.pi / 4, bell_state=0):
10+
def create_bell_circuit(theta=np.pi / 4, bell_state=0):
1111
"""Creates the circuit to generate the bell states and with a theta-measurement
1212
bell_state chooses the initial bell state for the test:
1313
0 -> |00>+|11>
@@ -17,24 +17,24 @@ def create_bell_circuit(nqubits, qubits, theta=np.pi / 4, bell_state=0):
1717
Native defaults to only using GPI2 and GPI gates.
1818
"""
1919
p = [0, 0]
20-
c = Circuit(nqubits)
21-
c.add(gates.H(qubits[0]))
22-
c.add(gates.H(qubits[1]))
23-
c.add(gates.CZ(qubits[0], qubits[1]))
24-
c.add(gates.H(qubits[1]))
20+
c = Circuit(2)
21+
c.add(gates.H(0))
22+
c.add(gates.H(1))
23+
c.add(gates.CZ(0, 1))
24+
c.add(gates.H(1))
2525
if bell_state == 1:
26-
c.add(gates.Z(qubits[0]))
26+
c.add(gates.Z(0))
2727
elif bell_state == 2:
28-
c.add(gates.Z(qubits[0]))
29-
c.add(gates.X(qubits[0]))
28+
c.add(gates.Z(0))
29+
c.add(gates.X(0))
3030
elif bell_state == 3:
31-
c.add(gates.X(qubits[0]))
31+
c.add(gates.X(0))
3232

33-
c.add(gates.RY(qubits[0], theta))
33+
c.add(gates.RY(0, theta))
3434
return c, p
3535

3636

37-
def create_bell_circuit_native(nqubits, qubits, theta=np.pi / 4, bell_state=0):
37+
def create_bell_circuit_native(theta=np.pi / 4, bell_state=0):
3838
"""Creates the circuit to generate the bell states and with a theta-measurement
3939
bell_state chooses the initial bell state for the test:
4040
0 -> |00>+|11>
@@ -44,35 +44,33 @@ def create_bell_circuit_native(nqubits, qubits, theta=np.pi / 4, bell_state=0):
4444
Native defaults to only using GPI2 and GPI gates.
4545
"""
4646

47-
c = Circuit(nqubits)
47+
c = Circuit(2)
4848
p = [0, 0]
49-
c.add(gates.GPI2(qubits[0], np.pi / 2))
50-
c.add(gates.GPI2(qubits[1], np.pi / 2))
51-
c.add(gates.CZ(qubits[0], qubits[1]))
52-
c.add(gates.GPI2(qubits[1], -np.pi / 2))
49+
c.add(gates.GPI2(0, np.pi / 2))
50+
c.add(gates.GPI2(1, np.pi / 2))
51+
c.add(gates.CZ(0, 1))
52+
c.add(gates.GPI2(1, -np.pi / 2))
5353
if bell_state == 0:
5454
p[0] += np.pi
5555
elif bell_state == 1:
5656
p[0] += 0
5757
elif bell_state == 2:
5858
p[0] += 0
59-
c.add(gates.GPI2(qubits[0], p[0]))
60-
c.add(gates.GPI2(qubits[0], p[0]))
59+
c.add(gates.GPI2(0, p[0]))
60+
c.add(gates.GPI2(0, p[0]))
6161
elif bell_state == 3:
6262
p[0] += np.pi
63-
c.add(gates.GPI2(qubits[0], p[0]))
64-
c.add(gates.GPI2(qubits[0], p[0]))
63+
c.add(gates.GPI2(0, p[0]))
64+
c.add(gates.GPI2(0, p[0]))
6565

66-
c.add(gates.GPI2(qubits[0], p[0]))
66+
c.add(gates.GPI2(0, p[0]))
6767
p[0] += theta
68-
c.add(gates.GPI2(qubits[0], p[0] + np.pi))
68+
c.add(gates.GPI2(0, p[0] + np.pi))
6969

7070
return c, p
7171

7272

7373
def create_chsh_circuits(
74-
platform,
75-
qubits,
7674
theta=np.pi / 4,
7775
bell_state=0,
7876
native=True,
@@ -84,15 +82,14 @@ def create_chsh_circuits(
8482
"""
8583
create_bell = create_bell_circuit_native if native else create_bell_circuit
8684
chsh_circuits = {}
87-
nqubits = platform.nqubits if platform else max(qubits) + 1
8885
for basis in readout_basis:
89-
c, p = create_bell(nqubits, qubits, theta, bell_state)
86+
c, p = create_bell(theta, bell_state)
9087
for i, base in enumerate(basis):
9188
if base == "X":
9289
if native:
93-
c.add(gates.GPI2(qubits[i], p[i] + np.pi / 2))
90+
c.add(gates.GPI2(i, p[i] + np.pi / 2))
9491
else:
95-
c.add(gates.H(qubits[i]))
96-
c.add(gates.M(*qubits))
92+
c.add(gates.H(i))
93+
c.add(gates.M(0, 1))
9794
chsh_circuits[basis] = c
9895
return chsh_circuits

src/qibocal/protocols/two_qubit_interaction/chsh/protocol.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ class CHSHData(Data):
7676

7777
def save(self, path: Path):
7878
"""Saving data including mitigation matrix."""
79-
80-
np.savez(
81-
path / f"{MITIGATION_MATRIX_FILE}.npz",
82-
**{
83-
json.dumps((control, target)): self.mitigation_matrix[control, target]
84-
for control, target, _, _, _ in self.data
85-
},
86-
)
79+
if self.mitigation_matrix:
80+
np.savez(
81+
path / f"{MITIGATION_MATRIX_FILE}.npz",
82+
**{
83+
json.dumps((control, target)): self.mitigation_matrix[
84+
control, target
85+
]
86+
for control, target, _, _, _ in self.data
87+
},
88+
)
8789
super().save(path=path)
8890

8991
@classmethod
@@ -223,7 +225,6 @@ def _acquisition_circuits(
223225
backend = GlobalBackend()
224226
backend.platform = platform
225227
transpiler = dummy_transpiler(backend)
226-
qubit_map = [i for i in range(platform.nqubits)]
227228
if params.apply_error_mitigation:
228229
mitigation_data = mitigation_acquisition(
229230
mitigation_params(nshots=params.nshots), platform, targets
@@ -242,8 +243,6 @@ def _acquisition_circuits(
242243
for bell_state in params.bell_states:
243244
for theta in thetas:
244245
chsh_circuits = create_chsh_circuits(
245-
platform,
246-
qubits=pair,
247246
bell_state=bell_state,
248247
theta=theta,
249248
native=params.native,
@@ -254,7 +253,7 @@ def _acquisition_circuits(
254253
nshots=params.nshots,
255254
transpiler=transpiler,
256255
backend=backend,
257-
qubit_map=qubit_map,
256+
qubit_map=pair,
258257
)
259258
frequencies = result.frequencies()
260259
data.register_basis(pair, bell_state, basis, frequencies)

0 commit comments

Comments
 (0)