Skip to content

Commit

Permalink
fix: use 2q circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
Edoardo-Pedicillo committed Nov 21, 2024
1 parent b7a9249 commit a5f5dd0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
57 changes: 27 additions & 30 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(nqubits, qubits, theta=np.pi / 4, bell_state=0):
def create_bell_circuit(theta=np.pi / 4, 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 @@ -17,24 +17,24 @@ def create_bell_circuit(nqubits, qubits, theta=np.pi / 4, bell_state=0):
Native defaults to only using GPI2 and GPI gates.
"""
p = [0, 0]
c = Circuit(nqubits)
c.add(gates.H(qubits[0]))
c.add(gates.H(qubits[1]))
c.add(gates.CZ(qubits[0], qubits[1]))
c.add(gates.H(qubits[1]))
c = Circuit(2)
c.add(gates.H(0))
c.add(gates.H(1))
c.add(gates.CZ(0, 1))
c.add(gates.H(1))
if bell_state == 1:
c.add(gates.Z(qubits[0]))
c.add(gates.Z(0))
elif bell_state == 2:
c.add(gates.Z(qubits[0]))
c.add(gates.X(qubits[0]))
c.add(gates.Z(0))
c.add(gates.X(0))
elif bell_state == 3:
c.add(gates.X(qubits[0]))
c.add(gates.X(0))

c.add(gates.RY(qubits[0], theta))
c.add(gates.RY(0, theta))
return c, p


def create_bell_circuit_native(nqubits, qubits, theta=np.pi / 4, bell_state=0):
def create_bell_circuit_native(theta=np.pi / 4, 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 @@ -44,35 +44,33 @@ def create_bell_circuit_native(nqubits, qubits, theta=np.pi / 4, bell_state=0):
Native defaults to only using GPI2 and GPI gates.
"""

c = Circuit(nqubits)
c = Circuit(2)
p = [0, 0]
c.add(gates.GPI2(qubits[0], np.pi / 2))
c.add(gates.GPI2(qubits[1], np.pi / 2))
c.add(gates.CZ(qubits[0], qubits[1]))
c.add(gates.GPI2(qubits[1], -np.pi / 2))
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))
if bell_state == 0:
p[0] += np.pi
elif bell_state == 1:
p[0] += 0
elif bell_state == 2:
p[0] += 0
c.add(gates.GPI2(qubits[0], p[0]))
c.add(gates.GPI2(qubits[0], p[0]))
c.add(gates.GPI2(0, p[0]))
c.add(gates.GPI2(0, p[0]))
elif bell_state == 3:
p[0] += np.pi
c.add(gates.GPI2(qubits[0], p[0]))
c.add(gates.GPI2(qubits[0], p[0]))
c.add(gates.GPI2(0, p[0]))
c.add(gates.GPI2(0, p[0]))

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

return c, p


def create_chsh_circuits(
platform,
qubits,
theta=np.pi / 4,
bell_state=0,
native=True,
Expand All @@ -84,15 +82,14 @@ def create_chsh_circuits(
"""
create_bell = create_bell_circuit_native if native else create_bell_circuit
chsh_circuits = {}
nqubits = platform.nqubits if platform else max(qubits) + 1
for basis in readout_basis:
c, p = create_bell(nqubits, qubits, theta, bell_state)
c, p = create_bell(theta, bell_state)
for i, base in enumerate(basis):
if base == "X":
if native:
c.add(gates.GPI2(qubits[i], p[i] + np.pi / 2))
c.add(gates.GPI2(i, p[i] + np.pi / 2))
else:
c.add(gates.H(qubits[i]))
c.add(gates.M(*qubits))
c.add(gates.H(i))
c.add(gates.M(0, 1))
chsh_circuits[basis] = c
return chsh_circuits
5 changes: 1 addition & 4 deletions src/qibocal/protocols/two_qubit_interaction/chsh/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def _acquisition_circuits(
backend = GlobalBackend()
backend.platform = platform
transpiler = dummy_transpiler(backend)
qubit_map = [i for i in range(platform.nqubits)]
if params.apply_error_mitigation:
mitigation_data = mitigation_acquisition(
mitigation_params(nshots=params.nshots), platform, targets
Expand All @@ -242,8 +241,6 @@ def _acquisition_circuits(
for bell_state in params.bell_states:
for theta in thetas:
chsh_circuits = create_chsh_circuits(
platform,
qubits=pair,
bell_state=bell_state,
theta=theta,
native=params.native,
Expand All @@ -254,7 +251,7 @@ def _acquisition_circuits(
nshots=params.nshots,
transpiler=transpiler,
backend=backend,
qubit_map=qubit_map,
qubit_map=pair,
)
frequencies = result.frequencies()
data.register_basis(pair, bell_state, basis, frequencies)
Expand Down

0 comments on commit a5f5dd0

Please sign in to comment.