QuLab 2.0.2__cp310-cp310-macosx_10_9_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. QuLab-2.0.2.dist-info/LICENSE +21 -0
  2. QuLab-2.0.2.dist-info/METADATA +98 -0
  3. QuLab-2.0.2.dist-info/RECORD +84 -0
  4. QuLab-2.0.2.dist-info/WHEEL +5 -0
  5. QuLab-2.0.2.dist-info/entry_points.txt +2 -0
  6. QuLab-2.0.2.dist-info/top_level.txt +1 -0
  7. qulab/__init__.py +1 -0
  8. qulab/__main__.py +26 -0
  9. qulab/fun.cpython-310-darwin.so +0 -0
  10. qulab/monitor/__init__.py +1 -0
  11. qulab/monitor/__main__.py +8 -0
  12. qulab/monitor/config.py +41 -0
  13. qulab/monitor/dataset.py +77 -0
  14. qulab/monitor/event_queue.py +54 -0
  15. qulab/monitor/mainwindow.py +234 -0
  16. qulab/monitor/monitor.py +93 -0
  17. qulab/monitor/ploter.py +123 -0
  18. qulab/monitor/qt_compat.py +16 -0
  19. qulab/monitor/toolbar.py +265 -0
  20. qulab/scan/__init__.py +3 -0
  21. qulab/scan/curd.py +144 -0
  22. qulab/scan/expression.py +505 -0
  23. qulab/scan/models.py +540 -0
  24. qulab/scan/optimize.py +69 -0
  25. qulab/scan/query_record.py +361 -0
  26. qulab/scan/recorder.py +447 -0
  27. qulab/scan/scan.py +701 -0
  28. qulab/scan/utils.py +37 -0
  29. qulab/storage/__init__.py +0 -0
  30. qulab/storage/__main__.py +51 -0
  31. qulab/storage/backend/__init__.py +0 -0
  32. qulab/storage/backend/redis.py +204 -0
  33. qulab/storage/base_dataset.py +352 -0
  34. qulab/storage/chunk.py +60 -0
  35. qulab/storage/dataset.py +127 -0
  36. qulab/storage/file.py +273 -0
  37. qulab/storage/models/__init__.py +22 -0
  38. qulab/storage/models/base.py +4 -0
  39. qulab/storage/models/config.py +28 -0
  40. qulab/storage/models/file.py +89 -0
  41. qulab/storage/models/ipy.py +58 -0
  42. qulab/storage/models/models.py +88 -0
  43. qulab/storage/models/record.py +161 -0
  44. qulab/storage/models/report.py +22 -0
  45. qulab/storage/models/tag.py +93 -0
  46. qulab/storage/storage.py +95 -0
  47. qulab/sys/__init__.py +0 -0
  48. qulab/sys/chat.py +688 -0
  49. qulab/sys/device/__init__.py +3 -0
  50. qulab/sys/device/basedevice.py +221 -0
  51. qulab/sys/device/loader.py +86 -0
  52. qulab/sys/device/utils.py +46 -0
  53. qulab/sys/drivers/FakeInstrument.py +52 -0
  54. qulab/sys/drivers/__init__.py +0 -0
  55. qulab/sys/ipy_events.py +125 -0
  56. qulab/sys/net/__init__.py +0 -0
  57. qulab/sys/net/bencoder.py +205 -0
  58. qulab/sys/net/cli.py +169 -0
  59. qulab/sys/net/dhcp.py +543 -0
  60. qulab/sys/net/dhcpd.py +176 -0
  61. qulab/sys/net/kad.py +1142 -0
  62. qulab/sys/net/kcp.py +192 -0
  63. qulab/sys/net/nginx.py +192 -0
  64. qulab/sys/progress.py +190 -0
  65. qulab/sys/rpc/__init__.py +0 -0
  66. qulab/sys/rpc/client.py +0 -0
  67. qulab/sys/rpc/exceptions.py +96 -0
  68. qulab/sys/rpc/msgpack.py +1052 -0
  69. qulab/sys/rpc/msgpack.pyi +41 -0
  70. qulab/sys/rpc/rpc.py +412 -0
  71. qulab/sys/rpc/serialize.py +139 -0
  72. qulab/sys/rpc/server.py +29 -0
  73. qulab/sys/rpc/socket.py +29 -0
  74. qulab/sys/rpc/utils.py +25 -0
  75. qulab/sys/rpc/worker.py +0 -0
  76. qulab/sys/rpc/zmq_socket.py +209 -0
  77. qulab/version.py +1 -0
  78. qulab/visualization/__init__.py +188 -0
  79. qulab/visualization/__main__.py +71 -0
  80. qulab/visualization/_autoplot.py +463 -0
  81. qulab/visualization/plot_layout.py +408 -0
  82. qulab/visualization/plot_seq.py +90 -0
  83. qulab/visualization/qdat.py +152 -0
  84. qulab/visualization/widgets.py +86 -0
@@ -0,0 +1,463 @@
1
+ import math
2
+
3
+ import matplotlib.pyplot as plt
4
+ import numpy as np
5
+ from matplotlib.colors import LogNorm, Normalize, SymLogNorm
6
+ from matplotlib.ticker import EngFormatter, LogFormatterSciNotation
7
+ from scipy.interpolate import griddata
8
+
9
+
10
+ def good_for_logscale(x, threshold=4):
11
+ if np.any(x <= 0):
12
+ return False
13
+ mid = (np.nanmin(x) + np.nanmax(x)) / 2
14
+ a = np.count_nonzero(np.nan_to_num(x <= mid, nan=0))
15
+ b = np.count_nonzero(np.nan_to_num(x >= mid, nan=0))
16
+ if a / b > threshold:
17
+ return True
18
+ return False
19
+
20
+
21
+ def equal_logspace(x):
22
+ logx = np.logspace(np.log10(x[0]), np.log10(x[-1]), len(x))
23
+ return np.allclose(x, logx)
24
+
25
+
26
+ def equal_linspace(x):
27
+ linearx = np.linspace(x[0], x[-1], len(x))
28
+ return np.allclose(x, linearx)
29
+
30
+
31
+ def as_1d_data(x, y, z):
32
+ x = np.asarray(x)
33
+ y = np.asarray(y)
34
+ z = np.asarray(z)
35
+ if z.ndim == 1:
36
+ return x, y, z
37
+
38
+ if z.ndim == 2:
39
+ x, y = np.meshgrid(x, y)
40
+ return x.ravel(), y.ravel(), z.ravel()
41
+
42
+ raise ValueError("z must be 1D or 2D")
43
+
44
+
45
+ def griddata_logx_logy(x, y, z, shape=(401, 401)):
46
+ x, y, z = as_1d_data(x, y, z)
47
+ xspace = np.logspace(np.log10(x.min()), np.log10(x.max()), shape[0])
48
+ yspace = np.logspace(np.log10(y.min()), np.log10(y.max()), shape[1])
49
+ xgrid, ygrid = np.meshgrid(xspace, yspace)
50
+ zgrid = griddata((x, y), z, (xgrid, ygrid), method='nearest')
51
+ return xspace, yspace, zgrid
52
+
53
+
54
+ def griddata_logx_linear_y(x, y, z, shape=(401, 401)):
55
+ x, y, z = as_1d_data(x, y, z)
56
+ xspace = np.logspace(np.log10(x.min()), np.log10(x.max()), shape[0])
57
+ yspace = np.linspace(y.min(), y.max(), shape[1])
58
+ xgrid, ygrid = np.meshgrid(xspace, yspace)
59
+ zgrid = griddata((x, y), z, (xgrid, ygrid), method='nearest')
60
+ return xspace, yspace, zgrid
61
+
62
+
63
+ def griddata_linear_x_logy(x, y, z, shape=(401, 401)):
64
+ x, y, z = as_1d_data(x, y, z)
65
+ xspace = np.linspace(x.min(), x.max(), shape[0])
66
+ yspace = np.logspace(np.log10(y.min()), np.log10(y.max()), shape[1])
67
+ xgrid, ygrid = np.meshgrid(xspace, yspace)
68
+ zgrid = griddata((x, y), z, (xgrid, ygrid), method='nearest')
69
+ return xspace, yspace, zgrid
70
+
71
+
72
+ def griddata_linear_x_linear_y(x, y, z, shape=(401, 401)):
73
+ x, y, z = as_1d_data(x, y, z)
74
+ xspace = np.linspace(x.min(), x.max(), shape[0])
75
+ yspace = np.linspace(y.min(), y.max(), shape[1])
76
+ xgrid, ygrid = np.meshgrid(xspace, yspace)
77
+ zgrid = griddata((x, y), z, (xgrid, ygrid), method='nearest')
78
+ return xspace, yspace, zgrid
79
+
80
+
81
+ def _get_log_ticks(x):
82
+ log10x = np.log10(x)
83
+
84
+ major_ticks = np.array(
85
+ range(math.floor(log10x[0]) - 1,
86
+ math.ceil(log10x[-1]) + 1))
87
+ minor_ticks = np.hstack([
88
+ np.log10(np.linspace(2, 10, 9, endpoint=False)) + x
89
+ for x in major_ticks
90
+ ])
91
+
92
+ major_ticks = major_ticks[(major_ticks >= log10x[0]) *
93
+ (major_ticks <= log10x[-1])]
94
+ minor_ticks = minor_ticks[(minor_ticks >= log10x[0]) *
95
+ (minor_ticks <= log10x[-1])]
96
+
97
+ return log10x, major_ticks, minor_ticks
98
+
99
+
100
+ class MyLogFormatter(EngFormatter):
101
+
102
+ def format_ticks(self, values):
103
+ if self.unit is None or self.unit == '':
104
+ fmt = LogFormatterSciNotation()
105
+ return [f"${fmt.format_data(10.0**x)}$" for x in values]
106
+ else:
107
+ return super().format_ticks(values)
108
+
109
+ def format_eng(self, x):
110
+ if self.unit is None or self.unit == '':
111
+ self.unit = ''
112
+ return f"{10.0**x:g}"
113
+ else:
114
+ return super().format_eng(10.0**x)
115
+
116
+
117
+ def imshow_logx(x, y, z, x_unit=None, ax=None, **kwargs):
118
+ if ax is None:
119
+ ax = plt.gca()
120
+
121
+ log10x, major_ticks, minor_ticks = _get_log_ticks(x)
122
+
123
+ dlogx, dy = log10x[1] - log10x[0], y[1] - y[0]
124
+ extent = (log10x[0] - dlogx / 2, log10x[-1] + dlogx / 2, y[0] - dy / 2,
125
+ y[-1] + dy / 2)
126
+
127
+ img = ax.imshow(z, extent=extent, **kwargs)
128
+
129
+ ax.set_xticks(major_ticks, minor=False)
130
+ ax.xaxis.set_major_formatter(MyLogFormatter(x_unit))
131
+ ax.set_xticks(minor_ticks, minor=True)
132
+
133
+ return img
134
+
135
+
136
+ def imshow_logy(x, y, z, y_unit=None, ax=None, **kwargs):
137
+ if ax is None:
138
+ ax = plt.gca()
139
+
140
+ log10y, major_ticks, minor_ticks = _get_log_ticks(y)
141
+
142
+ dlogy, dx = log10y[1] - log10y[0], x[1] - x[0]
143
+ extent = (x[0] - dx / 2, x[-1] + dx / 2, log10y[0] - dlogy / 2,
144
+ log10y[-1] + dlogy / 2)
145
+
146
+ img = ax.imshow(z, extent=extent, **kwargs)
147
+
148
+ ax.set_yticks(major_ticks, minor=False)
149
+ ax.yaxis.set_major_formatter(MyLogFormatter(y_unit))
150
+ ax.set_yticks(minor_ticks, minor=True)
151
+
152
+ return img
153
+
154
+
155
+ def imshow_loglog(x, y, z, x_unit=None, y_unit=None, ax=None, **kwargs):
156
+ if ax is None:
157
+ ax = plt.gca()
158
+
159
+ log10x, x_major_ticks, x_minor_ticks = _get_log_ticks(x)
160
+ log10y, y_major_ticks, y_minor_ticks = _get_log_ticks(y)
161
+
162
+ dlogx, dlogy = log10x[1] - log10x[0], log10y[1] - log10y[0]
163
+ extent = (log10x[0] - dlogx / 2, log10x[-1] + dlogx / 2,
164
+ log10y[0] - dlogy / 2, log10y[-1] + dlogy / 2)
165
+
166
+ img = ax.imshow(z, extent=extent, **kwargs)
167
+
168
+ ax.set_xticks(x_major_ticks, minor=False)
169
+ ax.xaxis.set_major_formatter(MyLogFormatter(x_unit))
170
+ ax.set_xticks(x_minor_ticks, minor=True)
171
+
172
+ ax.set_yticks(y_major_ticks, minor=False)
173
+ ax.yaxis.set_major_formatter(MyLogFormatter(y_unit))
174
+ ax.set_yticks(y_minor_ticks, minor=True)
175
+
176
+ return img
177
+
178
+
179
+ def plot_lines(x,
180
+ y,
181
+ z,
182
+ xlabel,
183
+ ylabel,
184
+ zlabel,
185
+ x_unit,
186
+ y_unit,
187
+ z_unit,
188
+ ax,
189
+ xscale='linear',
190
+ yscale='linear',
191
+ zscale='linear',
192
+ index=None,
193
+ **kwds):
194
+ z = np.asarray(z)
195
+ if len(y) > len(x):
196
+ x, y = y, x
197
+ xlabel, ylabel = ylabel, xlabel
198
+ xscale, yscale = yscale, xscale
199
+ z = z.T
200
+ if index is not None:
201
+ y = y[index]
202
+ z = z[index, :]
203
+
204
+ for i, l in enumerate(y):
205
+ if y_unit:
206
+ label = f"{ylabel}={l:.3} [{y_unit}]"
207
+ else:
208
+ if isinstance(l, float):
209
+ label = f"{ylabel}={l:.3}"
210
+ else:
211
+ label = f"{ylabel}={l}"
212
+ ax.plot(x, z[i, :], label=label, **kwds)
213
+ ax.legend()
214
+ xlabel = f"{xlabel} [{x_unit}]" if x_unit else xlabel
215
+ zlabel = f"{zlabel} [{z_unit}]" if z_unit else zlabel
216
+ ax.set_xlabel(xlabel)
217
+ ax.set_ylabel(zlabel)
218
+ ax.set_xscale(xscale)
219
+ ax.set_yscale(zscale)
220
+
221
+
222
+ def plot_img(x,
223
+ y,
224
+ z,
225
+ xlabel,
226
+ ylabel,
227
+ zlabel,
228
+ x_unit,
229
+ y_unit,
230
+ z_unit,
231
+ fig,
232
+ ax,
233
+ xscale='linear',
234
+ yscale='linear',
235
+ zscale='linear',
236
+ resolution=None,
237
+ **kwds):
238
+ kwds.setdefault('origin', 'lower')
239
+ kwds.setdefault('aspect', 'auto')
240
+ kwds.setdefault('interpolation', 'nearest')
241
+
242
+ vmin = kwds.get('vmin', np.nanmin(z))
243
+ vmax = kwds.get('vmax', np.nanmax(z))
244
+ if zscale == 'log':
245
+ kwds.setdefault('norm', LogNorm(vmax=vmax, vmin=vmin))
246
+ elif zscale == 'symlog':
247
+ kwds.setdefault('norm', SymLogNorm(vmax=vmax,
248
+ vmin=vmin,
249
+ linthresh=1e-5))
250
+ else:
251
+ kwds.setdefault('norm', Normalize(vmin=vmin, vmax=vmax))
252
+ zlabel = f"{zlabel} [{z_unit}]" if z_unit else zlabel
253
+
254
+ band_area = False
255
+ if x.ndim == 1 and y.ndim == 2 and y.shape[1] == x.shape[0]:
256
+ x = np.asarray([x] * y.shape[0])
257
+ band_area = True
258
+ elif x.ndim == 2 and y.ndim == 1 and x.shape[0] == y.shape[0]:
259
+ y = np.asarray([y] * x.shape[1]).T
260
+ band_area = True
261
+ if band_area:
262
+ kwds.pop('origin', None)
263
+ kwds.pop('aspect', None)
264
+ kwds.pop('interpolation', None)
265
+ pc = ax.pcolormesh(x, y, z, **kwds)
266
+ xlabel = f"{xlabel} [{x_unit}]" if x_unit else xlabel
267
+ ylabel = f"{ylabel} [{y_unit}]" if y_unit else ylabel
268
+ ax.set_xlabel(xlabel)
269
+ ax.set_ylabel(ylabel)
270
+ cb = fig.colorbar(pc, ax=ax)
271
+ ax.set_xscale(xscale)
272
+ ax.set_yscale(yscale)
273
+ cb.set_label(zlabel)
274
+ return
275
+
276
+ if resolution is None:
277
+ resolution = (401, 401)
278
+ elif isinstance(resolution, int):
279
+ resolution = (resolution, resolution)
280
+
281
+ if (z.ndim == 1 or (xscale == 'linear' and not equal_linspace(x))
282
+ or (yscale == 'linear' and not equal_linspace(y))
283
+ or (xscale == 'log' and not equal_logspace(x))
284
+ or (yscale == 'log' and not equal_logspace(y))):
285
+ griddata = {
286
+ ('log', 'log'): griddata_logx_logy,
287
+ ('log', 'linear'): griddata_logx_linear_y,
288
+ ('linear', 'log'): griddata_linear_x_logy,
289
+ ('linear', 'linear'): griddata_linear_x_linear_y,
290
+ }[(xscale, yscale)]
291
+ x, y, z = griddata(x, y, z, resolution)
292
+
293
+ if (xscale, yscale) == ('linear', 'linear'):
294
+ dx, dy = x[1] - x[0], y[1] - y[0]
295
+ extent = (x[0] - dx / 2, x[-1] + dx / 2, y[0] - dy / 2, y[-1] + dy / 2)
296
+ kwds.setdefault('extent', extent)
297
+ img = ax.imshow(np.asarray(z), **kwds)
298
+ xlabel = f"{xlabel} [{x_unit}]" if x_unit else xlabel
299
+ ylabel = f"{ylabel} [{y_unit}]" if y_unit else ylabel
300
+ elif (xscale, yscale) == ('log', 'linear'):
301
+ ylabel = f"{ylabel} [{y_unit}]" if y_unit else ylabel
302
+ img = imshow_logx(x, y, z, x_unit, ax, **kwds)
303
+ elif (xscale, yscale) == ('linear', 'log'):
304
+ xlabel = f"{xlabel} [{x_unit}]" if x_unit else xlabel
305
+ img = imshow_logy(x, y, z, y_unit, ax, **kwds)
306
+ elif (xscale, yscale) == ('log', 'log'):
307
+ img = imshow_loglog(x, y, z, x_unit, y_unit, ax, **kwds)
308
+ else:
309
+ pass
310
+ ax.set_xlabel(xlabel)
311
+ ax.set_ylabel(ylabel)
312
+ cb = fig.colorbar(img, ax=ax, norm=kwds.get('norm', None))
313
+ cb.set_label(zlabel)
314
+
315
+
316
+ def plot_scatter(x,
317
+ y,
318
+ z,
319
+ xlabel,
320
+ ylabel,
321
+ zlabel,
322
+ x_unit,
323
+ y_unit,
324
+ z_unit,
325
+ fig,
326
+ ax,
327
+ xscale='linear',
328
+ yscale='linear',
329
+ zscale='linear',
330
+ **kwds):
331
+ if np.any(np.iscomplex(z)):
332
+ s = np.abs(z)
333
+ c = np.angle(z)
334
+ else:
335
+ s = np.abs(z)
336
+ c = z.real
337
+ ax.scatter(x, y, s=s, c=c, **kwds)
338
+ xlabel = f"{xlabel} [{x_unit}]" if x_unit else xlabel
339
+ ylabel = f"{ylabel} [{y_unit}]" if y_unit else ylabel
340
+ ax.set_xlabel(xlabel)
341
+ ax.set_ylabel(ylabel)
342
+ ax.set_xscale(xscale)
343
+ ax.set_yscale(yscale)
344
+
345
+
346
+ def autoplot(x,
347
+ y,
348
+ z,
349
+ xlabel='x',
350
+ ylabel='y',
351
+ zlabel='z',
352
+ x_unit='',
353
+ y_unit='',
354
+ z_unit='',
355
+ fig=None,
356
+ ax=None,
357
+ index=None,
358
+ xscale='auto',
359
+ yscale='auto',
360
+ zscale='auto',
361
+ max_lines=3,
362
+ scatter_lim=1000,
363
+ resolution=None,
364
+ **kwds):
365
+ """
366
+ Plot a 2D array as a line plot or an image.
367
+
368
+ Parameters:
369
+ x (array): x values
370
+ y (array): y values
371
+ z (array): z values
372
+ xlabel (str): x label
373
+ ylabel (str): y label
374
+ zlabel (str): z label
375
+ x_unit (str): x unit
376
+ y_unit (str): y unit
377
+ z_unit (str): z unit
378
+ fig (Figure): figure to plot on
379
+ ax (Axes): axes to plot on
380
+ index (int): index of the line to plot
381
+ xscale (str): x scale 'auto', 'linear' or 'log'
382
+ yscale (str): y scale 'auto', 'linear' or 'log'
383
+ zscale (str): z scale 'auto', 'linear' or 'log'
384
+ max_lines (int): maximum number of lines to plot
385
+ **kwds: keyword arguments passed to plot_img or plot_lines
386
+ """
387
+ if ax is not None:
388
+ fig = ax.figure
389
+ if fig is None:
390
+ fig = plt.gcf()
391
+ if ax is None:
392
+ ax = fig.add_subplot(111)
393
+
394
+ x = np.asarray(x)
395
+ y = np.asarray(y)
396
+ z = np.asarray(z)
397
+
398
+ if xscale == 'auto':
399
+ if good_for_logscale(x):
400
+ xscale = 'log'
401
+ else:
402
+ xscale = 'linear'
403
+ if yscale == 'auto':
404
+ if good_for_logscale(y):
405
+ yscale = 'log'
406
+ else:
407
+ yscale = 'linear'
408
+ if zscale == 'auto':
409
+ if good_for_logscale(z):
410
+ zscale = 'log'
411
+ else:
412
+ zscale = 'linear'
413
+
414
+ if x.shape == y.shape == z.shape and z.size < scatter_lim:
415
+ plot_scatter(x,
416
+ y,
417
+ z,
418
+ xlabel,
419
+ ylabel,
420
+ zlabel,
421
+ x_unit,
422
+ y_unit,
423
+ z_unit,
424
+ fig,
425
+ ax,
426
+ xscale=xscale,
427
+ yscale=yscale,
428
+ zscale=zscale,
429
+ **kwds)
430
+ elif z.ndim == 2 and (len(y) <= max_lines or len(x) <= max_lines
431
+ or index is not None):
432
+ plot_lines(x,
433
+ y,
434
+ z,
435
+ xlabel,
436
+ ylabel,
437
+ zlabel,
438
+ x_unit=x_unit,
439
+ y_unit=y_unit,
440
+ z_unit=z_unit,
441
+ xscale=xscale,
442
+ yscale=yscale,
443
+ zscale=zscale,
444
+ ax=ax,
445
+ index=index,
446
+ **kwds)
447
+ else:
448
+ plot_img(x,
449
+ y,
450
+ z,
451
+ xlabel,
452
+ ylabel,
453
+ zlabel,
454
+ x_unit=x_unit,
455
+ y_unit=y_unit,
456
+ z_unit=z_unit,
457
+ xscale=xscale,
458
+ yscale=yscale,
459
+ zscale=zscale,
460
+ fig=fig,
461
+ ax=ax,
462
+ resolution=resolution,
463
+ **kwds)