QuLab 2.0.0__py3-none-any.whl → 2.10.11__py3-none-any.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 (69) hide show
  1. qulab/__init__.py +33 -1
  2. qulab/__main__.py +4 -0
  3. qulab/cli/commands.py +31 -0
  4. qulab/cli/config.py +170 -0
  5. qulab/cli/decorators.py +28 -0
  6. qulab/executor/__init__.py +5 -0
  7. qulab/executor/analyze.py +188 -0
  8. qulab/executor/cli.py +447 -0
  9. qulab/executor/load.py +563 -0
  10. qulab/executor/registry.py +185 -0
  11. qulab/executor/schedule.py +543 -0
  12. qulab/executor/storage.py +615 -0
  13. qulab/executor/template.py +259 -0
  14. qulab/executor/utils.py +194 -0
  15. qulab/monitor/__init__.py +1 -93
  16. qulab/monitor/__main__.py +8 -0
  17. qulab/monitor/monitor.py +115 -0
  18. qulab/scan/__init__.py +2 -4
  19. qulab/scan/curd.py +221 -0
  20. qulab/scan/models.py +554 -0
  21. qulab/scan/optimize.py +76 -0
  22. qulab/scan/query.py +387 -0
  23. qulab/scan/record.py +603 -0
  24. qulab/scan/scan.py +1166 -0
  25. qulab/scan/server.py +450 -0
  26. qulab/scan/space.py +213 -0
  27. qulab/scan/utils.py +230 -34
  28. qulab/sys/__init__.py +2 -0
  29. qulab/sys/device/basedevice.py +50 -16
  30. qulab/sys/device/loader.py +1 -1
  31. qulab/sys/device/utils.py +46 -13
  32. qulab/sys/drivers/FakeInstrument.py +36 -20
  33. qulab/sys/net/nginx.py +16 -14
  34. qulab/sys/rpc/router.py +35 -0
  35. qulab/sys/rpc/zmq_socket.py +227 -0
  36. qulab/tools/__init__.py +0 -0
  37. qulab/tools/connection_helper.py +39 -0
  38. qulab/typing.py +2 -0
  39. qulab/utils.py +95 -0
  40. qulab/version.py +1 -1
  41. qulab/visualization/__init__.py +188 -0
  42. qulab/visualization/__main__.py +71 -0
  43. qulab/visualization/_autoplot.py +464 -0
  44. qulab/visualization/plot_circ.py +319 -0
  45. qulab/visualization/plot_layout.py +408 -0
  46. qulab/visualization/plot_seq.py +242 -0
  47. qulab/visualization/qdat.py +152 -0
  48. qulab/visualization/rot3d.py +23 -0
  49. qulab/visualization/widgets.py +86 -0
  50. {QuLab-2.0.0.dist-info → qulab-2.10.11.dist-info}/METADATA +28 -12
  51. qulab-2.10.11.dist-info/RECORD +104 -0
  52. {QuLab-2.0.0.dist-info → qulab-2.10.11.dist-info}/WHEEL +1 -1
  53. qulab-2.10.11.dist-info/entry_points.txt +2 -0
  54. QuLab-2.0.0.dist-info/RECORD +0 -71
  55. qulab/monitor/multiploter/__init__.py +0 -1
  56. qulab/scan/base.py +0 -544
  57. qulab/scan/expression.py +0 -360
  58. qulab/scan/scanner.py +0 -244
  59. qulab/scan/transforms.py +0 -16
  60. /qulab/{scan/dataset.py → cli/__init__.py} +0 -0
  61. /qulab/monitor/{multiploter/config.py → config.py} +0 -0
  62. /qulab/monitor/{multiploter/dataset.py → dataset.py} +0 -0
  63. /qulab/monitor/{multiploter/event_queue.py → event_queue.py} +0 -0
  64. /qulab/monitor/{multiploter/main.py → mainwindow.py} +0 -0
  65. /qulab/monitor/{multiploter/ploter.py → ploter.py} +0 -0
  66. /qulab/monitor/{multiploter/qt_compat.py → qt_compat.py} +0 -0
  67. /qulab/monitor/{multiploter/toolbar.py → toolbar.py} +0 -0
  68. {QuLab-2.0.0.dist-info → qulab-2.10.11.dist-info/licenses}/LICENSE +0 -0
  69. {QuLab-2.0.0.dist-info → qulab-2.10.11.dist-info}/top_level.txt +0 -0
qulab/scan/expression.py DELETED
@@ -1,360 +0,0 @@
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
-
12
- LPAREN, RPAREN, LBRACK, RBRACK, LBRACE, RBRACE, DOT, TILDE, BANG, PLUS, MINUS = map(
13
- Suppress, "()[]{}.~!+-")
14
-
15
- INT = Combine(srange("[1-9]") +
16
- Optional(Word(nums))).set_parse_action(lambda t: int(t[0]))
17
- OCT = Combine("0" + Word("01234567")).set_parse_action(lambda t: int(t[0], 8))
18
- HEX = Combine("0x" + Word("0123456789abcdefABCDEF")).set_parse_action(
19
- lambda t: int(t[0], 16))
20
- FLOAT = Combine(Word(nums) + DOT + Word(nums)) | \
21
- Combine(DOT + Word(nums)) | \
22
- Combine(Word(nums) + DOT) | \
23
- Combine(Word(nums) + DOT + Word(nums) + CaselessKeyword("e") + Word("+-") + Word(nums)) | \
24
- Combine(Word(nums) + DOT + CaselessKeyword("e") + Word("+-") + Word(nums)) | \
25
- Combine(DOT + Word(nums) + CaselessKeyword("e") + Word("+-") + Word(nums)) | \
26
- Combine(Word(nums) + CaselessKeyword("e") + Word("+-") + Word(nums))
27
- FLOAT.set_parse_action(lambda t: float(t[0]))
28
- SYMBOL = Word(alphas, alphanums + "_")
29
- SYMBOL.set_parse_action(lambda t: Symbol(t[0]))
30
-
31
- expr = Forward()
32
- unary = Forward()
33
- binary = Forward()
34
- atom = Forward()
35
-
36
- atom << (INT | OCT | HEX | FLOAT | SYMBOL | (LPAREN + expr + RPAREN) |
37
- (LBRACK + expr + RBRACK) | (LBRACE + expr + RBRACE) | (MINUS + atom) |
38
- (PLUS + atom) | (TILDE + atom) | (BANG + atom) | (nums + DOT + nums))
39
-
40
- unary << (atom | (MINUS + unary) | (PLUS + unary) | (TILDE + unary) |
41
- (BANG + unary))
42
-
43
- ConstType = (int, float, complex)
44
- _empty = object()
45
-
46
-
47
- class Ref():
48
- __slots__ = ['name']
49
-
50
- def __init__(self, name):
51
- self.name = name
52
-
53
- def __repr__(self) -> str:
54
- return f"Ref({self.name!r})"
55
-
56
-
57
- class Env():
58
-
59
- def __init__(self):
60
- self.consts = {}
61
- self.variables = {}
62
- self.refs = {}
63
-
64
- def __contains__(self, key):
65
- return key in self.consts or key in self.variables or key in self.refs
66
-
67
- def __getitem__(self, key):
68
- if key in self.consts:
69
- return self.consts[key]
70
- if key in self.variables:
71
- return self.variables[key]
72
- if key in self.refs:
73
- return self[self.refs[key]]
74
- raise KeyError(f"Key {key} not found")
75
-
76
- def __setitem__(self, key, value):
77
- if key in self.consts:
78
- raise KeyError(f"Key {key:r} is const")
79
- elif isinstance(value, Ref):
80
- self.create_ref(key, value.name)
81
- elif key in self.refs:
82
- self[self.refs[key]] = value
83
- else:
84
- self.variables[key] = value
85
-
86
- def __delitem__(self, key):
87
- if key in self.consts:
88
- raise KeyError(f"Key {key:r} is const")
89
- elif key in self.refs:
90
- del self[self.refs[key]]
91
- else:
92
- del self.variables[key]
93
-
94
- def ref(self, key):
95
- if key in self:
96
- return Ref(key)
97
- else:
98
- raise KeyError(f"Key {key!r} not found")
99
-
100
- def create_ref(self, key, name):
101
- if name in self.refs:
102
- if key in self.refs[name]:
103
- raise ValueError(f"Key {key!r} already exists in ref {name!r}")
104
- else:
105
- self.refs[key] = [name, *self.refs[name]]
106
- else:
107
- self.refs[key] = [name]
108
-
109
- def is_const(self, key):
110
- return key in self.consts
111
-
112
-
113
- class Expression():
114
-
115
- def __init__(self):
116
- self.cache = _empty
117
-
118
- def d(self, x: str | Symbol):
119
- if isinstance(x, Symbol):
120
- x = x.name
121
- if x in self.symbols():
122
- return self.derivative(x)
123
- else:
124
- return 0
125
-
126
- def derivative(self, x):
127
- raise NotImplementedError
128
-
129
- def __add__(self, other):
130
- return BinaryExpression(self, other, operator.add)
131
-
132
- def __radd__(self, other):
133
- return BinaryExpression(other, self, operator.add)
134
-
135
- def __sub__(self, other):
136
- return BinaryExpression(self, other, operator.sub)
137
-
138
- def __rsub__(self, other):
139
- return BinaryExpression(other, self, operator.sub)
140
-
141
- def __mul__(self, other):
142
- return BinaryExpression(self, other, operator.mul)
143
-
144
- def __rmul__(self, other):
145
- return BinaryExpression(other, self, operator.mul)
146
-
147
- def __truediv__(self, other):
148
- return BinaryExpression(self, other, operator.truediv)
149
-
150
- def __rtruediv__(self, other):
151
- return BinaryExpression(other, self, operator.truediv)
152
-
153
- def __pow__(self, other):
154
- return BinaryExpression(self, other, operator.pow)
155
-
156
- def __rpow__(self, other):
157
- return BinaryExpression(other, self, operator.pow)
158
-
159
- def __neg__(self):
160
- return UnaryExpression(self, operator.neg)
161
-
162
- def __pos__(self):
163
- return UnaryExpression(self, operator.pos)
164
-
165
- def __eq__(self, other):
166
- return BinaryExpression(self, other, operator.eq)
167
-
168
- def __ne__(self, other):
169
- return BinaryExpression(self, other, operator.ne)
170
-
171
- def __lt__(self, other):
172
- return BinaryExpression(self, other, operator.lt)
173
-
174
- def __le__(self, other):
175
- return BinaryExpression(self, other, operator.le)
176
-
177
- def __gt__(self, other):
178
- return BinaryExpression(self, other, operator.gt)
179
-
180
- def __ge__(self, other):
181
- return BinaryExpression(self, other, operator.ge)
182
-
183
- def __getitem__(self, other):
184
- return ObjectMethod(self, '__getitem__', other)
185
-
186
- def __getattr__(self, other):
187
- return ObjectMethod(self, '__getattr__', other)
188
-
189
- def __call__(self, *args):
190
- return ObjectMethod(self, '__call__', *args)
191
-
192
- def __round__(self, n=None):
193
- return self
194
-
195
- def eval(self, env):
196
- raise NotImplementedError
197
-
198
- def symbols(self) -> list[str]:
199
- raise NotImplementedError
200
-
201
- def changed(self, env) -> bool:
202
- return True
203
-
204
- def is_const(self, env) -> bool:
205
- return False
206
-
207
- def value(self, env):
208
- if self.changed(env):
209
- self.cache = self.eval(env)
210
- return self.cache
211
-
212
-
213
- class UnaryExpression(Expression):
214
-
215
- def __init__(self, a, op):
216
- super().__init__()
217
- self.a = a
218
- self.op = op
219
-
220
- def symbols(self) -> list[str]:
221
- if isinstance(self.a, Expression):
222
- return self.a.symbols()
223
- else:
224
- return []
225
-
226
- def changed(self, env) -> bool:
227
- if isinstance(self.a, ConstType):
228
- return False
229
- return self.cache is _empty or isinstance(
230
- self.a, Expression) and self.a.changed(env)
231
-
232
- def is_const(self, env) -> bool:
233
- return isinstance(self.a,
234
- Expression) and self.a.is_const(env) or isinstance(
235
- self.a, ConstType)
236
-
237
- def eval(self, env):
238
- a = self.a.value(env) if isinstance(self.a, Expression) else self.a
239
- return self.op(a)
240
-
241
- def derivative(self, x):
242
- if isinstance(self.a, Expression):
243
- return self.op(self.a.d(x))
244
- else:
245
- return 0
246
-
247
- def __repr__(self) -> str:
248
- return f"{self.op.__name__}({self.a!r})"
249
-
250
-
251
- class BinaryExpression(Expression):
252
-
253
- def __init__(self, a, b, op):
254
- super().__init__()
255
- self.a = a
256
- self.b = b
257
- self.op = op
258
-
259
- def symbols(self) -> list[str]:
260
- symbs = set()
261
- if isinstance(self.a, Expression):
262
- symbs.update(self.a.symbols())
263
- if isinstance(self.b, Expression):
264
- symbs.update(self.b.symbols())
265
- return list(symbs)
266
-
267
- def eval(self, env):
268
- a = self.a.value(env) if isinstance(self.a, Expression) else self.a
269
- b = self.b.value(env) if isinstance(self.b, Expression) else self.b
270
- return self.op(a, b)
271
-
272
- def derivative(self, x):
273
- if isinstance(self.a, Expression):
274
- da = self.a.d(x)
275
- else:
276
- da = 0
277
- if isinstance(self.b, Expression):
278
- db = self.b.d(x)
279
- else:
280
- db = 0
281
-
282
- if self.op is operator.add:
283
- return da + db
284
- elif self.op is operator.sub:
285
- return da - db
286
- elif self.op is operator.mul:
287
- return self.a * db + da * self.b
288
- elif self.op is operator.truediv:
289
- return (da * self.b - self.a * db) / self.b**2
290
- elif self.op is operator.pow:
291
- if isinstance(self.a, Expression) and isinstance(
292
- self.b, Expression):
293
- return self.a**self.b * (self.b * da / self.a +
294
- ObjectMethod(np, 'log', self.a) * db)
295
- elif isinstance(self.a, Expression):
296
- return self.b * self.a**(self.b - 1) * da
297
- elif isinstance(self.b, Expression):
298
- return np.log(self.a) * db * self.a**self.b
299
- else:
300
- return 0
301
- else:
302
- return 0
303
-
304
- def __repr__(self) -> str:
305
- return f"({self.a!r} {self.op.__name__} {self.b!r})"
306
-
307
-
308
- class ObjectMethod(Expression):
309
-
310
- def __init__(self, obj, method: str, *args):
311
- super().__init__()
312
- self.obj = obj
313
- self.method = method
314
- self.args = args
315
-
316
- def symbols(self) -> list[str]:
317
- symbs = set()
318
- if isinstance(self.obj, Expression):
319
- symbs.update(self.obj.symbols())
320
- for a in self.args:
321
- if isinstance(a, Expression):
322
- symbs.update(a.symbols())
323
- return list(symbs)
324
-
325
- def eval(self, env):
326
- obj = self.obj.value(env) if isinstance(self.obj,
327
- Expression) else self.obj
328
- args = [
329
- a.value(env) if isinstance(a, Expression) else a for a in self.args
330
- ]
331
- if isinstance(obj, Expression) or any(
332
- isinstance(x, Expression) for x in args):
333
- return ObjectMethod(obj, self.method, *args)
334
- else:
335
- return getattr(obj, self.method)(*args)
336
-
337
-
338
- class Symbol(Expression):
339
-
340
- def __init__(self, name):
341
- super().__init__()
342
- self.name = name
343
-
344
- def symbols(self) -> list[str]:
345
- return [self.name]
346
-
347
- def eval(self, env):
348
- if self.name in env:
349
- return env[self.name]
350
- else:
351
- return self
352
-
353
- def derivative(self, x):
354
- if x == self.name:
355
- return 1
356
- else:
357
- return 0
358
-
359
- def __repr__(self) -> str:
360
- return self.name
qulab/scan/scanner.py DELETED
@@ -1,244 +0,0 @@
1
- import ast
2
-
3
- import numpy as np
4
-
5
- from .base import scan_iters
6
- from .expression import Env, Expression, Symbol, _empty
7
-
8
-
9
- def is_valid_identifier(s: str) -> bool:
10
- try:
11
- ast.parse(f"f({s}=0)")
12
- return True
13
- except SyntaxError:
14
- return False
15
-
16
-
17
- class Atom():
18
- __slots__ = ('value', )
19
-
20
- def __init__(self, value):
21
- self.value = value
22
-
23
-
24
- class MappedSymbol(Symbol):
25
- pass
26
-
27
-
28
- class OptimizeSpace():
29
-
30
- def __init__(self, optimizer, space):
31
- self.optimizer = optimizer
32
- self.space = space
33
- self.name = None
34
-
35
-
36
- class Optimizer():
37
-
38
- def __init__(self, cls, *args, **kwds):
39
- self.cls = cls
40
- self.args = args
41
- self.kwds = kwds
42
- self.dimensions = {}
43
- self.function = None
44
-
45
- def Categorical(self, *args, **kwds):
46
- from skopt.space import Categorical
47
- return OptimizeSpace(self, Categorical(*args, **kwds))
48
-
49
- def Integer(self, *args, **kwds):
50
- from skopt.space import Integer
51
- return OptimizeSpace(self, Integer(*args, **kwds))
52
-
53
- def Real(self, *args, **kwds):
54
- from skopt.space import Real
55
- return OptimizeSpace(self, Real(*args, **kwds))
56
-
57
- @property
58
- def target(self):
59
- return None
60
-
61
- @target.setter
62
- def target(self, fun):
63
- if isinstance(fun, Symbol):
64
- self.function = fun.name
65
- elif isinstance(fun, Expression):
66
- self.function = fun
67
- else:
68
- raise ValueError("Invalid function")
69
-
70
- def create_optimizer(self):
71
- dimensions = list(self.dimensions.values())
72
- return tuple(self.dimensions.keys()), self.cls(dimensions, *self.args,
73
- **self.kwds)
74
-
75
-
76
- class Scan():
77
-
78
- def __new__(cls, *args, mixin=None, **kwds):
79
- if mixin is None:
80
- return super().__new__(cls)
81
- for k in dir(mixin):
82
- if not hasattr(cls, k):
83
- try:
84
- setattr(cls, k, getattr(mixin, k))
85
- except:
86
- pass
87
- return super().__new__(cls)
88
-
89
- def __init__(self, name, *args, env=None, mixin=None, **kwds):
90
- super().__init__(*args, **kwds)
91
- self._name = name.replace(' ', '_')
92
- self.env = Env() if env is None else env
93
- self.functions = {}
94
- self.consts = {}
95
- self.loops = {}
96
- self.mapping = {}
97
- self.optimizers = {}
98
- self._mapping_i = 0
99
- self.filter = None
100
- self.scan_info = {'loops': {}}
101
- self._tmp = {}
102
-
103
- @property
104
- def name(self):
105
- return f"Scan.{self._name}"
106
-
107
- def get(self, key, default=_empty):
108
- if key in self.consts:
109
- return self.consts[key]
110
- if key in self.functions:
111
- return self.functions[key]
112
- if default is _empty:
113
- raise KeyError(f"Key {key} not found")
114
- return default
115
-
116
- def set(self, key, value):
117
- print(f"Set {key} to {value}")
118
-
119
- def _mapping(self, key, value):
120
- tmpkey = f"__tmp_{self._mapping_i}__"
121
- self._mapping_i += 1
122
- self[tmpkey] = value
123
- self.mapping[key] = tmpkey
124
-
125
- def __setitem__(self, key, value):
126
- if is_valid_identifier(key):
127
- if isinstance(value, Atom):
128
- self.consts[key] = value.value
129
- return
130
- elif isinstance(value, (str, int, float, complex, tuple)):
131
- self.consts[key] = value
132
- return
133
-
134
- if isinstance(value, Expression):
135
- env = Env()
136
- env.consts = self.consts
137
- value = value.value(env)
138
- if not isinstance(value, Expression):
139
- self.__setitem__(key, value)
140
- return
141
-
142
- self._tmp[key] = value
143
-
144
- def __setitem(self, key, value):
145
- if not is_valid_identifier(key):
146
- self._mapping(key, value)
147
- return
148
- if isinstance(value, Expression) or callable(value):
149
- self.functions[key] = value
150
- elif isinstance(value, OptimizeSpace):
151
- self.optimizers[key] = value.optimizer
152
- value.name = key
153
- value.optimizer.dimensions[key] = value.space
154
- self.loops[key] = value.optimizer
155
- elif isinstance(value, (np.ndarray, list, range)):
156
- self.loops[key] = value
157
- elif isinstance(value, Atom):
158
- self.consts[key] = value.value
159
- else:
160
- self.consts[key] = value
161
-
162
- def __getitem__(self, key):
163
- if key in self.consts:
164
- return self.consts[key]
165
- if is_valid_identifier(key):
166
- return Symbol(key)
167
- else:
168
- if key in self.mapping:
169
- return Symbol(self.mapping[key])
170
- return MappedSymbol(key)
171
-
172
- def assemble(self):
173
- for key, value in self._tmp.items():
174
- self.__setitem(key, value)
175
-
176
- variables = {}
177
- loops = {}
178
-
179
- for k, v in self.functions.items():
180
- if isinstance(v, MappedSymbol):
181
- variables[k] = eval(
182
- f"lambda {self.mapping[k]}: {self.mapping[k]}")
183
- elif isinstance(v, Expression):
184
- args = v.symbols()
185
- for x in args:
186
- if x in self.mapping:
187
- args.remove(x)
188
- v = v.value({x: Symbol(self.mapping[x])})
189
- x = self.mapping[x]
190
- if x in self.consts:
191
- args.remove(x)
192
- v = v.value({x: self.consts[x]})
193
- if args:
194
- variables[k] = eval(
195
- f"lambda {','.join(args)}: expr.value({{{','.join([f'{x!r}:{x}' for x in args])}}})",
196
- {'expr': v})
197
- else:
198
- self.consts[k] = v
199
- else:
200
- variables[k] = v
201
-
202
- for key, value in self.loops.items():
203
- if isinstance(value, Optimizer):
204
- #variables[key] = value.create_optimizer()
205
- pass
206
- else:
207
- loops[key] = value
208
-
209
- self.scan_info = {
210
- 'loops': loops,
211
- 'functions': variables,
212
- 'constants': self.consts
213
- }
214
-
215
- if self.filter is not None:
216
- self.scan_info['filter'] = self.filter
217
-
218
- def main(self):
219
- self.assemble()
220
- for step in self.scan():
221
- for k, v in self.mapping.items():
222
- self.set(k, step.kwds[v])
223
- self.process(step)
224
-
225
- def process(self, step):
226
- print(step.kwds)
227
-
228
- def scan(self):
229
- for step in scan_iters(**self.scan_info):
230
- for k, v in self.mapping.items():
231
- step.kwds[k] = step.kwds[v]
232
- yield step
233
-
234
- def run(self, dry_run=False):
235
- pass
236
-
237
- def plot(self,
238
- result=None,
239
- fig=None,
240
- axis=None,
241
- data='population',
242
- T=False,
243
- **kwds):
244
- pass
qulab/scan/transforms.py DELETED
@@ -1,16 +0,0 @@
1
- class Aggregation():
2
-
3
- def __init__(self):
4
- pass
5
-
6
- def __call__(self, data):
7
- raise NotImplementedError()
8
-
9
-
10
- class Transform():
11
-
12
- def __init__(self):
13
- pass
14
-
15
- def __call__(self, data):
16
- raise NotImplementedError()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes