Skip to content

Commit

Permalink
Merge pull request #546 from qiboteam/report_table
Browse files Browse the repository at this point in the history
html table generator
  • Loading branch information
Edoardo-Pedicillo authored Oct 11, 2023
2 parents 7aeb3c7 + dfb4642 commit e8774fd
Show file tree
Hide file tree
Showing 30 changed files with 382 additions and 289 deletions.
2 changes: 1 addition & 1 deletion doc/source/tutorials/protocol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Here is the plotting function for the protocol that we are coding:
figures = []
fig = go.Figure()
fitting_report = None
fitting_report = ""
qubit_data = data[qubit]
fig.add_trace(
Expand Down
2 changes: 1 addition & 1 deletion src/qibocal/protocols/characterization/allxy/allxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _plot(data: AllXYData, qubit, fit: AllXYResults = None):
"""Plotting function for allXY."""

figures = []
fitting_report = None
fitting_report = ""
fig = go.Figure()

qubit_data = data[qubit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _plot(data: AllXYDragData, qubit, fit: AllXYDragResults = None):
"""Plotting function for allXYDrag."""

figures = []
fitting_report = None
fitting_report = ""

fig = go.Figure()
beta_params = data.beta_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from qibocal.auto.operation import Data, Qubits, Results, Routine
from qibocal.config import log

from ..utils import V_TO_UV
from ..utils import V_TO_UV, table_dict, table_html
from . import allxy_drag_pulse_tuning


Expand Down Expand Up @@ -205,7 +205,7 @@ def _plot(data: DragPulseTuningData, qubit, fit: DragPulseTuningResults):
"""Plotting function for DragPulseTuning."""

figures = []
fitting_report = None
fitting_report = ""

fig = make_subplots(
rows=1,
Expand Down Expand Up @@ -247,7 +247,9 @@ def _plot(data: DragPulseTuningData, qubit, fit: DragPulseTuningResults):
line=go.scatter.Line(dash="dot"),
),
)
fitting_report = f"{qubit} | Optimal Beta Param: {fit.betas[qubit]:.4f}<br><br>"
fitting_report = table_html(
table_dict(qubit, "Optimal Beta Param", np.round(fit.betas[qubit], 4))
)

fig.update_layout(
showlegend=True,
Expand Down
37 changes: 27 additions & 10 deletions src/qibocal/protocols/characterization/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
)
from qibocal.auto.serialize import serialize
from qibocal.fitting.classifier import run
from qibocal.protocols.characterization.utils import get_color_state0, get_color_state1
from qibocal.protocols.characterization.utils import (
get_color_state0,
get_color_state1,
table_dict,
table_html,
)

MESH_SIZE = 50
MARGIN = 0
Expand Down Expand Up @@ -314,7 +319,7 @@ def _plot(
data: SingleShotClassificationData, qubit, fit: SingleShotClassificationResults
):
figures = []
fitting_report = None
fitting_report = ""
models_name = data.classifiers_list
qubit_data = data.data[qubit]
state0_data = qubit_data[qubit_data["state"] == 0]
Expand Down Expand Up @@ -523,15 +528,27 @@ def _plot(
)

if models_name[i] == "qubit_fit":
fitting_report = ""
fitting_report += f"{qubit} | average state 0: {np.round(fit.mean_gnd_states[qubit], 3)}<br>"
fitting_report += f"{qubit} | average state 1: {np.round(fit.mean_exc_states[qubit], 3)}<br>"
fitting_report += (
f"{qubit} | rotation angle: {fit.rotation_angle[qubit]:.3f}<br>"
fitting_report = table_html(
table_dict(
qubit,
[
"Average State 0",
"Average State 1",
"Rotational Angle",
"Threshold",
"Readout Fidelity",
"Assignment Fidelity",
],
[
np.round(fit.mean_gnd_states[qubit], 3),
np.round(fit.mean_exc_states[qubit], 3),
np.round(fit.rotation_angle[qubit], 3),
np.round(fit.threshold[qubit], 6),
np.round(fit.fidelity[qubit], 3),
np.round(fit.assignment_fidelity[qubit], 3),
],
)
)
fitting_report += f"{qubit} | threshold: {fit.threshold[qubit]:.6f}<br>"
fitting_report += f"{qubit} | fidelity: {fit.fidelity[qubit]:.3f}<br>"
fitting_report += f"{qubit} | assignment fidelity: {fit.assignment_fidelity[qubit]:.3f}<br>"

fig.update_layout(
uirevision="0", # ``uirevision`` allows zooming while live plotting
Expand Down
12 changes: 8 additions & 4 deletions src/qibocal/protocols/characterization/coherence/spin_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from qibocal import update
from qibocal.auto.operation import Parameters, Qubits, Results, Routine

from ..utils import V_TO_UV
from ..utils import V_TO_UV, table_dict, table_html
from .t1 import T1Data
from .utils import exp_decay, exponential_fit

Expand Down Expand Up @@ -127,7 +127,7 @@ def _plot(data: SpinEchoData, qubit, fit: SpinEchoResults = None):
fig = go.Figure()

# iterate over multiple data folders
fitting_report = None
fitting_report = ""

qubit_data = data[qubit]
waits = qubit_data.wait
Expand Down Expand Up @@ -161,8 +161,12 @@ def _plot(data: SpinEchoData, qubit, fit: SpinEchoResults = None):
),
)

fitting_report = (
f"{qubit} | T2 Spin Echo: {fit.t2_spin_echo[qubit]:,.0f} ns.<br><br>"
fitting_report = table_html(
table_dict(
qubit,
"T2 Spin Echo",
np.round(fit.t2_spin_echo[qubit]),
)
)

fig.update_layout(
Expand Down
7 changes: 3 additions & 4 deletions src/qibocal/protocols/characterization/coherence/t1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from qibocal import update
from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine

from ..utils import V_TO_UV
from ..utils import V_TO_UV, table_dict, table_html
from . import utils


Expand Down Expand Up @@ -161,7 +161,7 @@ def _plot(data: T1Data, qubit, fit: T1Results = None):
figures = []
fig = go.Figure()

fitting_report = None
fitting_report = ""
qubit_data = data[qubit]
waits = qubit_data.wait

Expand Down Expand Up @@ -192,8 +192,7 @@ def _plot(data: T1Data, qubit, fit: T1Results = None):
line=go.scatter.Line(dash="dot"),
)
)
fitting_report = f"{qubit} | t1: {fit.t1[qubit]:,.0f} ns.<br><br>"

fitting_report = table_html(table_dict(qubit, "t1", np.round(fit.t1[qubit])))
# last part
fig.update_layout(
showlegend=True,
Expand Down
7 changes: 3 additions & 4 deletions src/qibocal/protocols/characterization/coherence/t2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from qibocal import update
from qibocal.auto.operation import Parameters, Qubits, Results, Routine

from ..utils import V_TO_UV
from ..utils import V_TO_UV, table_dict, table_html
from . import t1, utils


Expand Down Expand Up @@ -124,7 +124,7 @@ def _plot(data: T2Data, qubit, fit: T2Results = None):

figures = []
fig = go.Figure()
fitting_report = None
fitting_report = ""

qubit_data = data[qubit]

Expand Down Expand Up @@ -159,8 +159,7 @@ def _plot(data: T2Data, qubit, fit: T2Results = None):
line=go.scatter.Line(dash="dot"),
)
)
fitting_report = f"{qubit} | T2: {fit.t2[qubit]:,.0f} ns.<br><br>"

fitting_report = table_html(table_dict(qubit, "T2", np.round(fit.t2[qubit])))
fig.update_layout(
showlegend=True,
uirevision="0", # ``uirevision`` allows zooming while live plotting
Expand Down
16 changes: 10 additions & 6 deletions src/qibocal/protocols/characterization/coherence/zeno.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from qibocal import update
from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine

from ..utils import V_TO_UV
from ..utils import V_TO_UV, table_dict, table_html
from . import utils


Expand Down Expand Up @@ -163,13 +163,17 @@ def _plot(data: ZenoData, fit: ZenoResults, qubit):
line=go.scatter.Line(dash="dot"),
)
)
fitting_report = fitting_report + (
f"{qubit} | readout pulses: {fit.zeno_t1[qubit]:,.0f} readout pulses.<br><br>"
fitting_report = table_html(
table_dict(
qubit,
["Readout Pulse", "T1"],
[
np.round(fit.zeno_t1[qubit]),
np.round(fit.zeno_t1[qubit] * data.readout_duration[qubit]),
],
)
)
# FIXME: Pulse duration (+ time of flight ?)
fitting_report = fitting_report + (
f"{qubit} | t1: {fit.zeno_t1[qubit]*data.readout_duration[qubit]:,.0f} ns.<br><br>"
)

# last part
fig.update_layout(
Expand Down
36 changes: 21 additions & 15 deletions src/qibocal/protocols/characterization/dispersive_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
V_TO_UV,
lorentzian,
lorentzian_fit,
table_dict,
table_html,
)


Expand Down Expand Up @@ -242,7 +244,7 @@ def _plot(data: DispersiveShiftData, qubit, fit: DispersiveShiftResults):
)
# iterate over multiple data folders

fitting_report = None
fitting_report = ""

data_0 = data[qubit, 0]
data_1 = data[qubit, 1]
Expand Down Expand Up @@ -306,8 +308,6 @@ def _plot(data: DispersiveShiftData, qubit, fit: DispersiveShiftResults):
)

if fit is not None:
fitting_report = ""

fig.add_trace(
go.Scatter(
x=[fit.best_freq[qubit], fit.best_freq[qubit]],
Expand All @@ -329,18 +329,24 @@ def _plot(data: DispersiveShiftData, qubit, fit: DispersiveShiftResults):
row=1,
col=1,
)

fitting_report = fitting_report + (
f"{qubit} | State zero freq : {fit_data_0['frequency_state_zero'][qubit]*GHZ_TO_HZ:,.0f} Hz.<br>"
)
fitting_report = fitting_report + (
f"{qubit} | State one freq : {fit_data_1['frequency_state_one'][qubit]*GHZ_TO_HZ:,.0f} Hz.<br>"
)
fitting_report = fitting_report + (
f"{qubit} | Chi : {(fit_data_0['frequency_state_zero'][qubit]*GHZ_TO_HZ - fit_data_1['frequency_state_one'][qubit]*GHZ_TO_HZ)/2:,.0f} Hz.<br>"
)
fitting_report = fitting_report + (
f"{qubit} | Best frequency : {fit.best_freq[qubit]*GHZ_TO_HZ:,.0f} Hz.<br>"
fitting_report = table_html(
table_dict(
qubit,
["State zero freq", "State one freq", "ChiBest", "Frequency"],
np.round(
[
fit_data_0["frequency_state_zero"][qubit],
fit_data_1["frequency_state_one"][qubit],
(
fit_data_0["frequency_state_zero"][qubit]
- fit_data_1["frequency_state_one"][qubit]
)
/ 2,
fit.best_freq[qubit],
]
)
* GHZ_TO_HZ,
)
)
fig.update_layout(
showlegend=True,
Expand Down
19 changes: 11 additions & 8 deletions src/qibocal/protocols/characterization/fast_reset/fast_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from qibolab.qubits import QubitId

from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine
from qibocal.protocols.characterization.utils import table_dict, table_html

# TODO: IBM Fast Reset until saturation loop
# https://quantum-computing.ibm.com/lab/docs/iql/manage/systems/reset/backend_reset
Expand Down Expand Up @@ -176,7 +177,7 @@ def _plot(data: FastResetData, fit: FastResetResults, qubit):
# Maybe the plot can just be something like a confusion matrix between 0s and 1s ???

figures = []
fitting_report = None
fitting_report = ""
fig = make_subplots(
rows=1,
cols=2,
Expand All @@ -189,7 +190,6 @@ def _plot(data: FastResetData, fit: FastResetResults, qubit):
)

if fit is not None:
fitting_report = ""
fig.add_trace(
go.Heatmap(
z=fit.Lambda_M_fr[qubit],
Expand All @@ -198,12 +198,15 @@ def _plot(data: FastResetData, fit: FastResetResults, qubit):
row=1,
col=1,
)

fitting_report += (
f"{qubit} | Fidelity [Fast Reset]: {fit.fidelity_fr[qubit]:.6f}<br>"
)
fitting_report += (
f"{qubit}| Fidelity [Relaxation Time]: {fit.fidelity_nfr[qubit]:.6f}<br>"
fitting_report = table_html(
table_dict(
qubit,
["Fidelity [Fast Reset]", "Fidelity [Relaxation Time]"],
[
np.round(fit.fidelity_fr[qubit], 6),
np.round(fit.fidelity_nfr[qubit], 6),
],
)
)

fig.add_trace(
Expand Down
16 changes: 11 additions & 5 deletions src/qibocal/protocols/characterization/flipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from qibocal import update
from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine
from qibocal.config import log
from qibocal.protocols.characterization.utils import table_dict, table_html

from .utils import V_TO_UV

Expand Down Expand Up @@ -226,7 +227,7 @@ def _plot(data: FlippingData, qubit, fit: FlippingResults = None):
figures = []
fig = go.Figure()

fitting_report = None
fitting_report = ""
qubit_data = data[qubit]

fig.add_trace(
Expand All @@ -241,7 +242,6 @@ def _plot(data: FlippingData, qubit, fit: FlippingResults = None):
)

if fit is not None:
fitting_report = ""
flips_range = np.linspace(
min(qubit_data.flips),
max(qubit_data.flips),
Expand All @@ -263,9 +263,15 @@ def _plot(data: FlippingData, qubit, fit: FlippingResults = None):
line=go.scatter.Line(dash="dot"),
),
)
fitting_report = fitting_report + (
f"{qubit} | Amplitude correction factor: {fit.amplitude_factors[qubit]:.4f}<br>"
+ f"{qubit} | Corrected amplitude: {fit.amplitude[qubit]:.4f}<br><br>"
fitting_report = table_html(
table_dict(
qubit,
["Amplitude correction factor", "Corrected amplitude"],
[
np.round(fit.amplitude_factors[qubit], 4),
np.round(fit.amplitude[qubit], 4),
],
)
)

# last part
Expand Down
Loading

0 comments on commit e8774fd

Please sign in to comment.