Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live plotting alternative to quantify #132

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/qibolab/calibration/live.py
Original file line number Diff line number Diff line change
@@ -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()


8 changes: 6 additions & 2 deletions src/qibolab/calibration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down