QuLab 2.0.1__cp312-cp312-win_amd64.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 (82) hide show
  1. QuLab-2.0.1.dist-info/LICENSE +21 -0
  2. QuLab-2.0.1.dist-info/METADATA +95 -0
  3. QuLab-2.0.1.dist-info/RECORD +82 -0
  4. QuLab-2.0.1.dist-info/WHEEL +5 -0
  5. QuLab-2.0.1.dist-info/entry_points.txt +2 -0
  6. QuLab-2.0.1.dist-info/top_level.txt +1 -0
  7. qulab/__init__.py +1 -0
  8. qulab/__main__.py +24 -0
  9. qulab/fun.cp312-win_amd64.pyd +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 +4 -0
  21. qulab/scan/base.py +548 -0
  22. qulab/scan/dataset.py +0 -0
  23. qulab/scan/expression.py +472 -0
  24. qulab/scan/optimize.py +0 -0
  25. qulab/scan/scanner.py +270 -0
  26. qulab/scan/transforms.py +16 -0
  27. qulab/scan/utils.py +37 -0
  28. qulab/storage/__init__.py +0 -0
  29. qulab/storage/__main__.py +51 -0
  30. qulab/storage/backend/__init__.py +0 -0
  31. qulab/storage/backend/redis.py +204 -0
  32. qulab/storage/base_dataset.py +352 -0
  33. qulab/storage/chunk.py +60 -0
  34. qulab/storage/dataset.py +127 -0
  35. qulab/storage/file.py +273 -0
  36. qulab/storage/models/__init__.py +22 -0
  37. qulab/storage/models/base.py +4 -0
  38. qulab/storage/models/config.py +28 -0
  39. qulab/storage/models/file.py +89 -0
  40. qulab/storage/models/ipy.py +58 -0
  41. qulab/storage/models/models.py +88 -0
  42. qulab/storage/models/record.py +161 -0
  43. qulab/storage/models/report.py +22 -0
  44. qulab/storage/models/tag.py +93 -0
  45. qulab/storage/storage.py +95 -0
  46. qulab/sys/__init__.py +0 -0
  47. qulab/sys/chat.py +688 -0
  48. qulab/sys/device/__init__.py +3 -0
  49. qulab/sys/device/basedevice.py +221 -0
  50. qulab/sys/device/loader.py +86 -0
  51. qulab/sys/device/utils.py +46 -0
  52. qulab/sys/drivers/FakeInstrument.py +52 -0
  53. qulab/sys/drivers/__init__.py +0 -0
  54. qulab/sys/ipy_events.py +125 -0
  55. qulab/sys/net/__init__.py +0 -0
  56. qulab/sys/net/bencoder.py +205 -0
  57. qulab/sys/net/cli.py +169 -0
  58. qulab/sys/net/dhcp.py +543 -0
  59. qulab/sys/net/dhcpd.py +176 -0
  60. qulab/sys/net/kad.py +1142 -0
  61. qulab/sys/net/kcp.py +192 -0
  62. qulab/sys/net/nginx.py +192 -0
  63. qulab/sys/progress.py +190 -0
  64. qulab/sys/rpc/__init__.py +0 -0
  65. qulab/sys/rpc/client.py +0 -0
  66. qulab/sys/rpc/exceptions.py +96 -0
  67. qulab/sys/rpc/msgpack.py +1052 -0
  68. qulab/sys/rpc/msgpack.pyi +41 -0
  69. qulab/sys/rpc/rpc.py +412 -0
  70. qulab/sys/rpc/serialize.py +139 -0
  71. qulab/sys/rpc/server.py +29 -0
  72. qulab/sys/rpc/socket.py +29 -0
  73. qulab/sys/rpc/utils.py +25 -0
  74. qulab/sys/rpc/worker.py +0 -0
  75. qulab/version.py +1 -0
  76. qulab/visualization/__init__.py +188 -0
  77. qulab/visualization/__main__.py +71 -0
  78. qulab/visualization/_autoplot.py +457 -0
  79. qulab/visualization/plot_layout.py +408 -0
  80. qulab/visualization/plot_seq.py +90 -0
  81. qulab/visualization/qdat.py +152 -0
  82. qulab/visualization/widgets.py +86 -0
@@ -0,0 +1,472 @@
1
+ from __future__ import annotations
2
+
3
+ import operator
4
+
5
+ import numpy as np
6
+ from pyparsing import (CaselessKeyword, Combine, Forward, Group, Keyword,
7
+ Literal, Optional, ParserElement, Suppress, Word,
8
+ alphanums, alphas, delimitedList, nums, oneOf, opAssoc,
9
+ pyparsing_common, restOfLine, srange, stringEnd,
10
+ stringStart)
11
+ from scipy import special
12
+
13
+ LPAREN, RPAREN, LBRACK, RBRACK, LBRACE, RBRACE, DOT, TILDE, BANG, PLUS, MINUS = map(
14
+ Suppress, "()[]{}.~!+-")
15
+
16
+ INT = Combine(srange("[1-9]") +
17
+ Optional(Word(nums))).set_parse_action(lambda t: int(t[0]))
18
+ OCT = Combine("0" + Word("01234567")).set_parse_action(lambda t: int(t[0], 8))
19
+ HEX = Combine("0x" + Word("0123456789abcdefABCDEF")).set_parse_action(
20
+ lambda t: int(t[0], 16))
21
+ FLOAT = Combine(Word(nums) + DOT + Word(nums)) | \
22
+ Combine(DOT + Word(nums)) | \
23
+ Combine(Word(nums) + DOT) | \
24
+ Combine(Word(nums) + DOT + Word(nums) + CaselessKeyword("e") + Word("+-") + Word(nums)) | \
25
+ Combine(Word(nums) + DOT + CaselessKeyword("e") + Word("+-") + Word(nums)) | \
26
+ Combine(DOT + Word(nums) + CaselessKeyword("e") + Word("+-") + Word(nums)) | \
27
+ Combine(Word(nums) + CaselessKeyword("e") + Word("+-") + Word(nums))
28
+ FLOAT.set_parse_action(lambda t: float(t[0]))
29
+ SYMBOL = Word(alphas, alphanums + "_")
30
+ SYMBOL.set_parse_action(lambda t: Symbol(t[0]))
31
+
32
+ expr = Forward()
33
+ unary = Forward()
34
+ binary = Forward()
35
+ atom = Forward()
36
+
37
+ atom << (INT | OCT | HEX | FLOAT | SYMBOL | (LPAREN + expr + RPAREN) |
38
+ (LBRACK + expr + RBRACK) | (LBRACE + expr + RBRACE) | (MINUS + atom) |
39
+ (PLUS + atom) | (TILDE + atom) | (BANG + atom) | (nums + DOT + nums))
40
+
41
+ unary << (atom | (MINUS + unary) | (PLUS + unary) | (TILDE + unary) |
42
+ (BANG + unary))
43
+
44
+ ConstType = (int, float, complex)
45
+ _empty = object()
46
+
47
+
48
+ class Ref():
49
+ __slots__ = ['name']
50
+
51
+ def __init__(self, name):
52
+ self.name = name
53
+
54
+ def __repr__(self) -> str:
55
+ return f"Ref({self.name!r})"
56
+
57
+
58
+ class Env():
59
+
60
+ def __init__(self):
61
+ self.consts = {}
62
+ self.variables = {}
63
+ self.refs = {}
64
+ self.functions = {
65
+ 'sin': np.sin,
66
+ 'cos': np.cos,
67
+ 'tan': np.tan,
68
+ 'pi': np.pi,
69
+ 'e': np.e,
70
+ 'log': np.log,
71
+ 'log2': np.log2,
72
+ 'log10': np.log10,
73
+ 'exp': np.exp,
74
+ 'sqrt': np.sqrt,
75
+ 'abs': np.abs,
76
+ 'sinh': np.sinh,
77
+ 'cosh': np.cosh,
78
+ 'tanh': np.tanh,
79
+ 'arcsin': np.arcsin,
80
+ 'arccos': np.arccos,
81
+ 'arctan': np.arctan,
82
+ 'arctan2': np.arctan2,
83
+ 'arcsinh': np.arcsinh,
84
+ 'arccosh': np.arccosh,
85
+ 'arctanh': np.arctanh,
86
+ 'sinc': np.sinc,
87
+ 'sign': np.sign,
88
+ 'heaviside': np.heaviside,
89
+ 'erf': special.erf,
90
+ 'erfc': special.erfc,
91
+ }
92
+
93
+ def __contains__(self, key):
94
+ return key in self.consts or key in self.variables or key in self.functions or key in self.refs
95
+
96
+ def __getitem__(self, key):
97
+ if key in self.consts:
98
+ return self.consts[key]
99
+ if key in self.variables:
100
+ return self.variables[key]
101
+ if key in self.functions:
102
+ return self.functions[key]
103
+ if key in self.refs:
104
+ return self[self.refs[key]]
105
+ raise KeyError(f"Key {key} not found")
106
+
107
+ def __setitem__(self, key, value):
108
+ if key in self.consts:
109
+ raise KeyError(f"Key {key:r} is const")
110
+ elif isinstance(value, Ref):
111
+ self.create_ref(key, value.name)
112
+ elif key in self.refs:
113
+ self[self.refs[key]] = value
114
+ else:
115
+ self.variables[key] = value
116
+
117
+ def __delitem__(self, key):
118
+ if key in self.consts:
119
+ raise KeyError(f"Key {key:r} is const")
120
+ elif key in self.refs:
121
+ del self[self.refs[key]]
122
+ else:
123
+ del self.variables[key]
124
+
125
+ def ref(self, key):
126
+ if key in self:
127
+ return Ref(key)
128
+ else:
129
+ raise KeyError(f"Key {key!r} not found")
130
+
131
+ def create_ref(self, key, name):
132
+ if name in self.refs:
133
+ if key in self.refs[name]:
134
+ raise ValueError(f"Key {key!r} already exists in ref {name!r}")
135
+ else:
136
+ self.refs[key] = [name, *self.refs[name]]
137
+ else:
138
+ self.refs[key] = [name]
139
+
140
+ def is_const(self, key):
141
+ return key in self.consts
142
+
143
+
144
+ _default_env = Env()
145
+
146
+
147
+ class Expression():
148
+
149
+ def __init__(self):
150
+ self.cache = _empty
151
+
152
+ def d(self, x: str | Symbol):
153
+ if isinstance(x, Symbol):
154
+ x = x.name
155
+ if x in self.symbols():
156
+ return self.derivative(x)
157
+ else:
158
+ return 0
159
+
160
+ def derivative(self, x):
161
+ raise NotImplementedError
162
+
163
+ def __add__(self, other):
164
+ if isinstance(other, Expression):
165
+ other = other.eval(_default_env)
166
+ if isinstance(other, ConstType) and other == 0:
167
+ return self
168
+ return BinaryExpression(self, other, operator.add)
169
+
170
+ def __radd__(self, other):
171
+ if isinstance(other, Expression):
172
+ other = other.eval(_default_env)
173
+ if isinstance(other, ConstType) and other == 0:
174
+ return self
175
+ return BinaryExpression(other, self, operator.add)
176
+
177
+ def __sub__(self, other):
178
+ if isinstance(other, Expression):
179
+ other = other.eval(_default_env)
180
+ if isinstance(other, ConstType) and other == 0:
181
+ return self
182
+ return BinaryExpression(self, other, operator.sub)
183
+
184
+ def __rsub__(self, other):
185
+ if isinstance(other, Expression):
186
+ other = other.eval(_default_env)
187
+ if isinstance(other, ConstType) and other == 0:
188
+ return -self
189
+ return BinaryExpression(other, self, operator.sub)
190
+
191
+ def __mul__(self, other):
192
+ if isinstance(other, Expression):
193
+ other = other.eval(_default_env)
194
+ if isinstance(other, ConstType) and other == 0:
195
+ return 0
196
+ if isinstance(other, ConstType) and other == 1:
197
+ return self
198
+ if isinstance(other, ConstType) and other == -1:
199
+ return -self
200
+ return BinaryExpression(self, other, operator.mul)
201
+
202
+ def __rmul__(self, other):
203
+ if isinstance(other, Expression):
204
+ other = other.eval(_default_env)
205
+ if isinstance(other, ConstType) and other == 0:
206
+ return 0
207
+ if isinstance(other, ConstType) and other == 1:
208
+ return self
209
+ if isinstance(other, ConstType) and other == -1:
210
+ return -self
211
+ return BinaryExpression(other, self, operator.mul)
212
+
213
+ def __truediv__(self, other):
214
+ if isinstance(other, Expression):
215
+ other = other.eval(_default_env)
216
+ if isinstance(other, ConstType) and other == 1:
217
+ return self
218
+ if isinstance(other, ConstType) and other == -1:
219
+ return -self
220
+ return BinaryExpression(self, other, operator.truediv)
221
+
222
+ def __rtruediv__(self, other):
223
+ if isinstance(other, Expression):
224
+ other = other.eval(_default_env)
225
+ if isinstance(other, ConstType) and other == 0:
226
+ return 0
227
+ return BinaryExpression(other, self, operator.truediv)
228
+
229
+ def __pow__(self, other):
230
+ if isinstance(other, Expression):
231
+ other = other.eval(_default_env)
232
+ if isinstance(other, ConstType) and other == 0:
233
+ return 1
234
+ if isinstance(other, ConstType) and other == 1:
235
+ return self
236
+ return BinaryExpression(self, other, operator.pow)
237
+
238
+ def __rpow__(self, other):
239
+ if isinstance(other, Expression):
240
+ other = other.eval(_default_env)
241
+ if isinstance(other, ConstType) and other == 0:
242
+ return 0
243
+ return BinaryExpression(other, self, operator.pow)
244
+
245
+ def __neg__(self):
246
+ return UnaryExpression(self, operator.neg)
247
+
248
+ def __pos__(self):
249
+ return UnaryExpression(self, operator.pos)
250
+
251
+ def __eq__(self, other):
252
+ if isinstance(other, Expression):
253
+ other = other.eval(_default_env)
254
+ return BinaryExpression(self, other, operator.eq)
255
+
256
+ def __ne__(self, other):
257
+ if isinstance(other, Expression):
258
+ other = other.eval(_default_env)
259
+ return BinaryExpression(self, other, operator.ne)
260
+
261
+ def __lt__(self, other):
262
+ if isinstance(other, Expression):
263
+ other = other.eval(_default_env)
264
+ return BinaryExpression(self, other, operator.lt)
265
+
266
+ def __le__(self, other):
267
+ if isinstance(other, Expression):
268
+ other = other.eval(_default_env)
269
+ return BinaryExpression(self, other, operator.le)
270
+
271
+ def __gt__(self, other):
272
+ if isinstance(other, Expression):
273
+ other = other.eval(_default_env)
274
+ return BinaryExpression(self, other, operator.gt)
275
+
276
+ def __ge__(self, other):
277
+ if isinstance(other, Expression):
278
+ other = other.eval(_default_env)
279
+ return BinaryExpression(self, other, operator.ge)
280
+
281
+ def __getitem__(self, other):
282
+ if isinstance(other, Expression):
283
+ other = other.eval(_default_env)
284
+ return ObjectMethod(self, '__getitem__', other)
285
+
286
+ def __getattr__(self, other):
287
+ if isinstance(other, Expression):
288
+ other = other.eval(_default_env)
289
+ return ObjectMethod(self, '__getattr__', other)
290
+
291
+ def __call__(self, *args):
292
+ args = [
293
+ o.eval(_default_env) if isinstance(o, Expression) else o
294
+ for o in args
295
+ ]
296
+ return ObjectMethod(self, '__call__', *args)
297
+
298
+ def __round__(self, n=None):
299
+ return self
300
+
301
+ def eval(self, env):
302
+ raise NotImplementedError
303
+
304
+ def symbols(self) -> list[str]:
305
+ raise NotImplementedError
306
+
307
+ def changed(self, env) -> bool:
308
+ return True
309
+
310
+ def is_const(self, env) -> bool:
311
+ return False
312
+
313
+ def value(self, env):
314
+ if self.changed(env):
315
+ self.cache = self.eval(env)
316
+ return self.cache
317
+
318
+
319
+ class UnaryExpression(Expression):
320
+
321
+ def __init__(self, a, op):
322
+ super().__init__()
323
+ self.a = a
324
+ self.op = op
325
+
326
+ def symbols(self) -> list[str]:
327
+ if isinstance(self.a, Expression):
328
+ return self.a.symbols()
329
+ else:
330
+ return []
331
+
332
+ def changed(self, env) -> bool:
333
+ if isinstance(self.a, ConstType):
334
+ return False
335
+ return self.cache is _empty or isinstance(
336
+ self.a, Expression) and self.a.changed(env)
337
+
338
+ def is_const(self, env) -> bool:
339
+ return isinstance(self.a,
340
+ Expression) and self.a.is_const(env) or isinstance(
341
+ self.a, ConstType)
342
+
343
+ def eval(self, env):
344
+ a = self.a.value(env) if isinstance(self.a, Expression) else self.a
345
+ return self.op(a)
346
+
347
+ def derivative(self, x):
348
+ if isinstance(self.a, Expression):
349
+ return self.op(self.a.d(x))
350
+ else:
351
+ return 0
352
+
353
+ def __repr__(self) -> str:
354
+ return f"{self.op.__name__}({self.a!r})"
355
+
356
+
357
+ class BinaryExpression(Expression):
358
+
359
+ def __init__(self, a, b, op):
360
+ super().__init__()
361
+ self.a = a
362
+ self.b = b
363
+ self.op = op
364
+
365
+ def symbols(self) -> list[str]:
366
+ symbs = set()
367
+ if isinstance(self.a, Expression):
368
+ symbs.update(self.a.symbols())
369
+ if isinstance(self.b, Expression):
370
+ symbs.update(self.b.symbols())
371
+ return list(symbs)
372
+
373
+ def eval(self, env):
374
+ a = self.a.value(env) if isinstance(self.a, Expression) else self.a
375
+ b = self.b.value(env) if isinstance(self.b, Expression) else self.b
376
+ return self.op(a, b)
377
+
378
+ def derivative(self, x):
379
+ if isinstance(self.a, Expression):
380
+ da = self.a.d(x)
381
+ else:
382
+ da = 0
383
+ if isinstance(self.b, Expression):
384
+ db = self.b.d(x)
385
+ else:
386
+ db = 0
387
+
388
+ if self.op is operator.add:
389
+ return da + db
390
+ elif self.op is operator.sub:
391
+ return da - db
392
+ elif self.op is operator.mul:
393
+ return self.a * db + da * self.b
394
+ elif self.op is operator.truediv:
395
+ return (da * self.b - self.a * db) / self.b**2
396
+ elif self.op is operator.pow:
397
+ if isinstance(self.a, Expression) and isinstance(
398
+ self.b, Expression):
399
+ return self.a**self.b * (self.b * da / self.a +
400
+ ObjectMethod(np, 'log', self.a) * db)
401
+ elif isinstance(self.a, Expression):
402
+ return self.b * self.a**(self.b - 1) * da
403
+ elif isinstance(self.b, Expression):
404
+ return np.log(self.a) * db * self.a**self.b
405
+ else:
406
+ return 0
407
+ else:
408
+ return 0
409
+
410
+ def __repr__(self) -> str:
411
+ return f"({self.a!r} {self.op.__name__} {self.b!r})"
412
+
413
+
414
+ class ObjectMethod(Expression):
415
+
416
+ def __init__(self, obj, method: str, *args):
417
+ super().__init__()
418
+ self.obj = obj
419
+ self.method = method
420
+ self.args = args
421
+
422
+ def symbols(self) -> list[str]:
423
+ symbs = set()
424
+ if isinstance(self.obj, Expression):
425
+ symbs.update(self.obj.symbols())
426
+ for a in self.args:
427
+ if isinstance(a, Expression):
428
+ symbs.update(a.symbols())
429
+ return list(symbs)
430
+
431
+ def eval(self, env):
432
+ obj = self.obj.value(env) if isinstance(self.obj,
433
+ Expression) else self.obj
434
+ args = [
435
+ a.value(env) if isinstance(a, Expression) else a for a in self.args
436
+ ]
437
+ if isinstance(obj, Expression) or any(
438
+ isinstance(x, Expression) for x in args):
439
+ return ObjectMethod(obj, self.method, *args)
440
+ else:
441
+ return getattr(obj, self.method)(*args)
442
+
443
+ def __repr__(self):
444
+ if self.method == '__call__':
445
+ return f"{self.obj!r}({', '.join(map(repr, self.args))})"
446
+ else:
447
+ return f"{self.obj!r}.{self.method}({', '.join(map(repr, self.args))})"
448
+
449
+
450
+ class Symbol(Expression):
451
+
452
+ def __init__(self, name):
453
+ super().__init__()
454
+ self.name = name
455
+
456
+ def symbols(self) -> list[str]:
457
+ return [self.name]
458
+
459
+ def eval(self, env):
460
+ if self.name in env:
461
+ return env[self.name]
462
+ else:
463
+ return self
464
+
465
+ def derivative(self, x):
466
+ if x == self.name:
467
+ return 1
468
+ else:
469
+ return 0
470
+
471
+ def __repr__(self) -> str:
472
+ return self.name
qulab/scan/optimize.py ADDED
File without changes