From ce7594e3a1a59e12cd614e49dc15b31630a16d05 Mon Sep 17 00:00:00 2001 From: aorgazf <55031026+aorgazf@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:01:01 +0400 Subject: [PATCH] live plotting alternative to quantify --- src/qibolab/calibration/live.py | 44 ++++++++++++++++++++++++++++++++ src/qibolab/calibration/utils.py | 8 ++++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/qibolab/calibration/live.py diff --git a/src/qibolab/calibration/live.py b/src/qibolab/calibration/live.py new file mode 100644 index 0000000000..ef1efee53c --- /dev/null +++ b/src/qibolab/calibration/live.py @@ -0,0 +1,44 @@ +import dash +from dash.dependencies import Output, Input +from dash import dcc +from dash import html +import plotly.graph_objs as go +import numpy as np +from qibolab.paths import qibolab_folder + +# data = np.load("./buffer.npy") +# X = data[0] +# Y = data[1] +# print(X) +# print(Y) + +app = dash.Dash(__name__) + +def live_plotting(path): + #path = qibolab_folder / 'calibration' / 'data' / 'buffer.npy' + print(path) + app.layout = html.Div([dcc.Graph(id = 'live-graph', animate = True), dcc.Interval(id = 'graph-update', interval = 1000, n_intervals = 0),]) + @app.callback(Output('live-graph', 'figure'), [Input('graph-update', 'n_intervals')]) + + def update_graph_scatter(n): + df = np.load(path) + X = df[0] + Y = df[1] + + if len(df) == 2: + data = go.Scatter(x=X,y=Y,name='Scatter',mode= 'lines+markers') + + elif len(df) == 3: + Z = df[2] + data = go.Heatmap(x=X,y=Y,z=Z,name='Scatter') + + else: + raise ValueError("Not plottable") + + return {'data': [data], 'layout' : go.Layout(xaxis=dict(range=[min(X),max(X)]),yaxis = dict(range = [min(Y),max(Y)]),)} + +def start_server(path): + live_plotting(path) + app.run_server() + + \ No newline at end of file diff --git a/src/qibolab/calibration/utils.py b/src/qibolab/calibration/utils.py index 73bcd4a955..322b9e4bb7 100644 --- a/src/qibolab/calibration/utils.py +++ b/src/qibolab/calibration/utils.py @@ -2,10 +2,8 @@ from qibolab.paths import qibolab_folder from quantify_core.measurement import MeasurementControl import numpy as np -import yaml import matplotlib.pyplot as plt import pathlib -import datetime script_folder = pathlib.Path(__file__).parent @@ -88,6 +86,12 @@ def create_measurement_control(name, debug=True): return mc, None, None # TODO: be able to choose which windows are opened and remember their sizes and dimensions +def start_live_plotting(path): + import threading + import qibolab.calibration.live as lp + dash = threading.Thread(target=lp.start_server, args=(path,)) + dash.setDaemon(True) + dash.start() def classify(point: complex, mean_gnd, mean_exc): import math