From 4c413ed31130fe9214a4e6a6b6b543f3b6479027 Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Mon, 6 May 2024 22:40:41 +0400 Subject: [PATCH 1/8] feat: delay on readout characterization --- .../characterization/readout_characterization.py | 16 ++++++++++++++-- tests/runcards/protocols.yml | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index 32671e5d0..3f8ef264d 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -1,4 +1,5 @@ from dataclasses import dataclass, field +from typing import Optional import numpy as np import numpy.typing as npt @@ -23,6 +24,9 @@ class ReadoutCharacterizationParameters(Parameters): """ReadoutCharacterization runcard inputs.""" + delay: Optional[float] = None + """Delay between readouts, could account for resonator deplation or not [ns].""" + @dataclass class ReadoutCharacterizationResults(Results): @@ -55,6 +59,9 @@ class ReadoutCharacterizationData(Data): qubit_frequencies: dict[QubitId, float] = field(default_factory=dict) """Qubit frequencies.""" + + delay: Optional[float] = None + """Delay between readouts [ns].""" data: dict[tuple, npt.NDArray[ReadoutCharacterizationType]] = field( default_factory=dict ) @@ -73,7 +80,8 @@ def _acquisition( data = ReadoutCharacterizationData( qubit_frequencies={ qubit: platform.qubits[qubit].drive_frequency for qubit in targets - } + }, + delay=float(params.delay), ) # FIXME: ADD 1st measurament and post_selection for accurate state preparation ? @@ -93,7 +101,9 @@ def _acquisition( ro_pulses[qubit] = [] for _ in range(2): ro_pulse = platform.create_qubit_readout_pulse(qubit, start=start) - start += ro_pulse.duration + start += ro_pulse.duration + int( + params.delay + ) # device required conversion sequence.add(ro_pulse) ro_pulses[qubit].append(ro_pulse) @@ -236,12 +246,14 @@ def _plot( table_dict( target, [ + "Delay between readouts [ns]", "Assignment Fidelity", "Fidelity", "QND", "Effective Qubit Temperature [K]", ], [ + np.round(data.delay), np.round(fit.assignment_fidelity[target], 6), np.round(fit.fidelity[target], 6), np.round(fit.qnd[target], 6), diff --git a/tests/runcards/protocols.yml b/tests/runcards/protocols.yml index b3b69a2cd..9cacc941b 100644 --- a/tests/runcards/protocols.yml +++ b/tests/runcards/protocols.yml @@ -475,6 +475,7 @@ actions: - id: readout characterization operation: readout_characterization parameters: + delay: 1000 nshots: 10 - id: allXY @@ -490,7 +491,6 @@ actions: unrolling: True nshots: 10 - - id: drag_pulse_tuning operation: drag_tuning parameters: From db007b34b155a651632a3d5c8d1207aeead94ff4 Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Wed, 8 May 2024 11:44:17 +0400 Subject: [PATCH 2/8] fix: comments --- .../protocols/characterization/readout_characterization.py | 5 ++--- tests/runcards/protocols.yml | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index 3f8ef264d..735026c7e 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -1,5 +1,4 @@ from dataclasses import dataclass, field -from typing import Optional import numpy as np import numpy.typing as npt @@ -24,7 +23,7 @@ class ReadoutCharacterizationParameters(Parameters): """ReadoutCharacterization runcard inputs.""" - delay: Optional[float] = None + delay: float = 0 """Delay between readouts, could account for resonator deplation or not [ns].""" @@ -60,7 +59,7 @@ class ReadoutCharacterizationData(Data): qubit_frequencies: dict[QubitId, float] = field(default_factory=dict) """Qubit frequencies.""" - delay: Optional[float] = None + delay: float """Delay between readouts [ns].""" data: dict[tuple, npt.NDArray[ReadoutCharacterizationType]] = field( default_factory=dict diff --git a/tests/runcards/protocols.yml b/tests/runcards/protocols.yml index 9cacc941b..6eaae8e22 100644 --- a/tests/runcards/protocols.yml +++ b/tests/runcards/protocols.yml @@ -478,6 +478,12 @@ actions: delay: 1000 nshots: 10 + - id: readout characterization delay 0 + operation: readout_characterization + parameters: + delay: 0 + nshots: 10 + - id: allXY operation: allxy parameters: From 0116fcc81e35063570948b16e845117bfbb3e997 Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Wed, 8 May 2024 11:55:09 +0400 Subject: [PATCH 3/8] fix: lint --- .../protocols/characterization/readout_characterization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index 735026c7e..98e57b1a6 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -59,7 +59,7 @@ class ReadoutCharacterizationData(Data): qubit_frequencies: dict[QubitId, float] = field(default_factory=dict) """Qubit frequencies.""" - delay: float + delay: float = 0 """Delay between readouts [ns].""" data: dict[tuple, npt.NDArray[ReadoutCharacterizationType]] = field( default_factory=dict From e9715af5c9034b237471940bd5c10f391c2f39ac Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Wed, 8 May 2024 14:00:02 +0400 Subject: [PATCH 4/8] feat: plot both measurament statisitcs with plot titles --- .../readout_characterization.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index 98e57b1a6..05feaab1b 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -40,7 +40,9 @@ class ReadoutCharacterizationResults(Results): effective_temperature: dict[QubitId, tuple[float, float]] """Effective qubit temperature.""" Lambda_M: dict[QubitId, float] - "Mapping between a given initial state to an outcome adter the measurement" + "Mapping between a given initial state to an outcome after the measurement" + Lambda_M2: dict[QubitId, float] + "Mapping between the outcome after the measurement and it still being that outcame after another measurement" ReadoutCharacterizationType = np.dtype( @@ -147,6 +149,7 @@ def _fit(data: ReadoutCharacterizationData) -> ReadoutCharacterizationResults: effective_temperature = {} qnd = {} Lambda_M = {} + Lambda_M2 = {} for qubit in qubits: # 1st measurement (m=1) m1_state_1 = data.samples[qubit, 1, 0] @@ -177,6 +180,12 @@ def _fit(data: ReadoutCharacterizationData) -> ReadoutCharacterizationResults: [state1_count_0_m1 / nshots, state1_count_1_m1 / nshots], ] + # Repeat Lambda and fidelity for each measurement ? + Lambda_M2[qubit] = [ + [state0_count_0_m2 / nshots, state0_count_1_m2 / nshots], + [state1_count_0_m2 / nshots, state1_count_1_m2 / nshots], + ] + assignment_fidelity[qubit] = ( 1 - (state1_count_0_m1 / nshots + state0_count_1_m1 / nshots) / 2 ) @@ -201,7 +210,7 @@ def _fit(data: ReadoutCharacterizationData) -> ReadoutCharacterizationResults: ) return ReadoutCharacterizationResults( - fidelity, assignment_fidelity, qnd, effective_temperature, Lambda_M + fidelity, assignment_fidelity, qnd, effective_temperature, Lambda_M, Lambda_M2 ) @@ -235,12 +244,23 @@ def _plot( figures.append(fig) if fit is not None: fig2 = go.Figure() - fig2.add_trace( go.Heatmap( z=fit.Lambda_M[target], ) ) + fig2.update_layout(title="1st measurement statistics") + figures.append(fig2) + + fig3 = go.Figure() + fig3.add_trace( + go.Heatmap( + z=fit.Lambda_M2[target], + ) + ) + fig3.update_layout(title="2nd measurement statistics") + + figures.append(fig3) fitting_report = table_html( table_dict( target, @@ -262,7 +282,7 @@ def _plot( ], ) ) - figures.append(fig2) + return figures, fitting_report From 2995bc5b2e9b292ff17e088e38393823a7e7e90b Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Thu, 9 May 2024 15:40:00 +0400 Subject: [PATCH 5/8] feat: Improve plotting --- .../readout_characterization.py | 54 +++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index 05feaab1b..f69e401ec 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -3,6 +3,7 @@ import numpy as np import numpy.typing as npt import plotly.graph_objects as go +from plotly.subplots import make_subplots from qibolab import AcquisitionType, ExecutionParameters from qibolab.platform import Platform from qibolab.pulses import PulseSequence @@ -241,26 +242,59 @@ def _plot( marker=dict(size=3), ) ) + fig.update_layout( + title={ + "text": "IQ Plane", + "y": 0.9, + "x": 0.5, + "xanchor": "center", + "yanchor": "top", + }, + xaxis_title="I", + yaxis_title="Q", + ) + figures.append(fig) if fit is not None: - fig2 = go.Figure() - fig2.add_trace( + + fig = make_subplots( + rows=1, + cols=2, + subplot_titles=( + "1st measurement statistics", + "2nd measurement statistics", + ), + ) + + fig.add_trace( go.Heatmap( z=fit.Lambda_M[target], - ) + x=["0", "1"], + y=["0", "1"], + coloraxis="coloraxis", + ), + row=1, + col=1, ) - fig2.update_layout(title="1st measurement statistics") - figures.append(fig2) - fig3 = go.Figure() - fig3.add_trace( + fig.add_trace( go.Heatmap( z=fit.Lambda_M2[target], - ) + x=["0", "1"], + y=["0", "1"], + coloraxis="coloraxis", + ), + row=1, + col=2, ) - fig3.update_layout(title="2nd measurement statistics") - figures.append(fig3) + fig.update_xaxes(title_text="Measured state", row=1, col=1) + fig.update_xaxes(title_text="Measured state", row=1, col=2) + fig.update_yaxes(title_text="Prepared state", row=1, col=1) + fig.update_yaxes(title_text="Prepared state", row=1, col=2) + + figures.append(fig) + fitting_report = table_html( table_dict( target, From b1a4e07deabba437e57bd974a231b4e9d960020e Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Mon, 13 May 2024 13:30:15 +0400 Subject: [PATCH 6/8] fix: clearer legend --- .../protocols/characterization/readout_characterization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index f69e401ec..dc4329d21 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -235,7 +235,7 @@ def _plot( go.Scatter( x=shots.i, y=shots.q, - name=f"state {state} measure {measure}", + name=f"state {state} measurent number {measure}", mode="markers", showlegend=True, opacity=0.7, From e984aaa1775af0dd045f88a2edbd12cf2e944b4d Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Mon, 13 May 2024 13:32:02 +0400 Subject: [PATCH 7/8] fix: even clearer legend --- .../protocols/characterization/readout_characterization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index dc4329d21..702d38edf 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -235,7 +235,7 @@ def _plot( go.Scatter( x=shots.i, y=shots.q, - name=f"state {state} measurent number {measure}", + name=f"Prepared state {state} measurent {measure}", mode="markers", showlegend=True, opacity=0.7, From 4789ef48fa44b2e69d2585cd909ee36e41da5174 Mon Sep 17 00:00:00 2001 From: Jacfomg Date: Mon, 13 May 2024 13:32:27 +0400 Subject: [PATCH 8/8] fix: typo --- .../protocols/characterization/readout_characterization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qibocal/protocols/characterization/readout_characterization.py b/src/qibocal/protocols/characterization/readout_characterization.py index 702d38edf..b662c1c6f 100644 --- a/src/qibocal/protocols/characterization/readout_characterization.py +++ b/src/qibocal/protocols/characterization/readout_characterization.py @@ -235,7 +235,7 @@ def _plot( go.Scatter( x=shots.i, y=shots.q, - name=f"Prepared state {state} measurent {measure}", + name=f"Prepared state {state} measurement {measure}", mode="markers", showlegend=True, opacity=0.7,