Skip to content

Commit

Permalink
fix: improve cov
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacfomg committed May 10, 2024
1 parent 482520f commit b2b9b64
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SINGLE_QUBIT_CLIFFORDS_NAMES,
find_cliffords,
generate_inv_dict_cliffords_file,
separator,
)

GLOBAL_PHASES = [
Expand Down Expand Up @@ -144,22 +145,7 @@ def add_inverse_2q_layer(circuit: Circuit, two_qubit_cliffords, file_inv):

clifford_gate = []
for clifford in clifford_list:

# Separate values containing 1
values_with_1 = [value for value in clifford if "1" in value]
values_with_1 = ",".join(values_with_1)

# Separate values containing 2
values_with_2 = [value for value in clifford if "2" in value]
values_with_2 = ",".join(values_with_2)

# Check if CZ
value_with_CZ = [value for value in clifford if "CZ" in value]
value_with_CZ = len(value_with_CZ) == 1

values_with_1 = values_with_1.replace("1", "")
values_with_2 = values_with_2.replace("2", "")

values_with_1, values_with_2, value_with_CZ = separator(clifford)
clifford_gate.append(SINGLE_QUBIT_CLIFFORDS_NAMES[values_with_1](0))
clifford_gate.append(SINGLE_QUBIT_CLIFFORDS_NAMES[values_with_2](1))
if value_with_CZ:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
from ..utils import table_dict, table_html
from .circuit_tools import add_inverse_2q_layer, add_measurement_layer, layer_2q_circuit
from .fitting import exp1B_func, fit_exp1B_func
from .utils import data_uncertainties, number_to_str, random_2q_clifford

NPULSES_PER_CLIFFORD = 8.6
# NPULSES_PER_CLIFFORD = calculate_pulses_clifford(two_qubit_cliffords)
from .utils import (
calculate_pulses_clifford,
data_uncertainties,
number_to_str,
random_2q_clifford,
)


class Depthsdict(TypedDict):
Expand Down Expand Up @@ -61,6 +63,8 @@ class RB2QData(RBData):
"""Raw data acquired."""
circuits: dict[QubitPairId, list[list[int]]] = field(default_factory=dict)
"""Clifford gate indexes executed."""
npulses_per_clifford: float = 8.6 # Assuming U3s and 1 pulse CZ
"""Number of pulses for an average clifford."""

def extract_probabilities(self, qubits):
"""Extract the probabilities given (`qubit`, `qubit`)"""
Expand Down Expand Up @@ -127,6 +131,13 @@ def layer_gen(self):
"""
return random_2q_clifford(self.random_index, self.two_qubit_cliffords)

def calculate_average_pulses(self):
"""
Returns:
- Average number of pulses per clifford.
"""
return calculate_pulses_clifford(self.two_qubit_cliffords)


def random_circuits(
depth: int,
Expand Down Expand Up @@ -261,6 +272,7 @@ def _acquisition(
),
)
data.circuits = indexes
data.npulses_per_clifford = rb_gen.calculate_average_pulses()

return data

Expand Down Expand Up @@ -301,7 +313,7 @@ def _fit(data: RB2QData) -> StandardRB2QResult:
# Compute the fidelities
infidelity = (1 - popt[1]) / 2
fidelity[qubit] = 1 - infidelity
pulse_fidelity[qubit] = 1 - infidelity / NPULSES_PER_CLIFFORD
pulse_fidelity[qubit] = 1 - infidelity / data.npulses_per_clifford

# conversion from np.array to list/tuple
error_bars = error_bars.tolist()
Expand Down Expand Up @@ -416,7 +428,7 @@ def _plot(
number_to_str(
fit.pulse_fidelity[qubits],
np.array(fit.fit_uncertainties[qubits][1])
/ (2 * NPULSES_PER_CLIFFORD),
/ (2 * data.npulses_per_clifford),
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,32 @@ def find_cliffords(cz_list):
return clifford_list


def clifford2gates(clifford):
gate_list = clifford.split(",")
def separator(clifford):
# Separate values containing 1
values_with_1 = [value for value in clifford if "1" in value]
values_with_1 = ",".join(values_with_1)

clifford_list = find_cliffords(gate_list)
# Separate values containing 2
values_with_2 = [value for value in clifford if "2" in value]
values_with_2 = ",".join(values_with_2)

clifford_gate = []
for clifford in clifford_list:
# Check if CZ
value_with_CZ = [value for value in clifford if "CZ" in value]
value_with_CZ = len(value_with_CZ) == 1

# Separate values containing 1
values_with_1 = [value for value in clifford if "1" in value]
values_with_1 = ",".join(values_with_1)
values_with_1 = values_with_1.replace("1", "")
values_with_2 = values_with_2.replace("2", "")
return values_with_1, values_with_2, value_with_CZ

# Separate values containing 2
values_with_2 = [value for value in clifford if "2" in value]
values_with_2 = ",".join(values_with_2)

# Check if CZ
value_with_CZ = [value for value in clifford if "CZ" in value]
value_with_CZ = len(value_with_CZ) == 1
def clifford2gates(clifford):
gate_list = clifford.split(",")

values_with_1 = values_with_1.replace("1", "")
values_with_2 = values_with_2.replace("2", "")
clifford_list = find_cliffords(gate_list)

clifford_gate = []
for clifford in clifford_list:
values_with_1, values_with_2, value_with_CZ = separator(clifford)
clifford_gate.append(SINGLE_QUBIT_CLIFFORDS_NAMES[values_with_1](0))
clifford_gate.append(SINGLE_QUBIT_CLIFFORDS_NAMES[values_with_2](1))
if value_with_CZ:
Expand Down Expand Up @@ -303,27 +306,14 @@ def clifford_to_pulses(clifford):

pulses = 0
for clifford in clifford_list:
# Separate values containing 1
values_with_1 = [value for value in clifford if "1" in value]
values_with_1 = ",".join(values_with_1)

# Separate values containing 2
values_with_2 = [value for value in clifford if "2" in value]
values_with_2 = ",".join(values_with_2)

# Check if CZ
value_with_CZ = [value for value in clifford if "CZ" in value]
value_with_CZ = len(value_with_CZ) == 1

values_with_1 = values_with_1.replace("1", "")
values_with_2 = values_with_2.replace("2", "")
values_with_1, values_with_2, value_with_CZ = separator(clifford)

if SINGLE_QUBIT_CLIFFORDS_NAMES[values_with_1](0).name != "id":
pulses += 2
pulses += 2 # This assumes a U3 transpiled into 2 pulses
if SINGLE_QUBIT_CLIFFORDS_NAMES[values_with_2](1).name != "id":
pulses += 2
pulses += 2 # This assumes a U3 transpiled into 2 pulses
if value_with_CZ:
pulses += 1
pulses += 1 # This assumes a CZ without parking so 1 pulse

return pulses

Expand Down

0 comments on commit b2b9b64

Please sign in to comment.