QuLab 2.10.10__cp313-cp313-macosx_10_13_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 (107) hide show
  1. qulab/__init__.py +33 -0
  2. qulab/__main__.py +4 -0
  3. qulab/cli/__init__.py +0 -0
  4. qulab/cli/commands.py +30 -0
  5. qulab/cli/config.py +170 -0
  6. qulab/cli/decorators.py +28 -0
  7. qulab/dicttree.py +523 -0
  8. qulab/executor/__init__.py +5 -0
  9. qulab/executor/analyze.py +188 -0
  10. qulab/executor/cli.py +434 -0
  11. qulab/executor/load.py +563 -0
  12. qulab/executor/registry.py +185 -0
  13. qulab/executor/schedule.py +543 -0
  14. qulab/executor/storage.py +615 -0
  15. qulab/executor/template.py +259 -0
  16. qulab/executor/utils.py +194 -0
  17. qulab/expression.py +827 -0
  18. qulab/fun.cpython-313-darwin.so +0 -0
  19. qulab/monitor/__init__.py +1 -0
  20. qulab/monitor/__main__.py +8 -0
  21. qulab/monitor/config.py +41 -0
  22. qulab/monitor/dataset.py +77 -0
  23. qulab/monitor/event_queue.py +54 -0
  24. qulab/monitor/mainwindow.py +234 -0
  25. qulab/monitor/monitor.py +115 -0
  26. qulab/monitor/ploter.py +123 -0
  27. qulab/monitor/qt_compat.py +16 -0
  28. qulab/monitor/toolbar.py +265 -0
  29. qulab/scan/__init__.py +2 -0
  30. qulab/scan/curd.py +221 -0
  31. qulab/scan/models.py +554 -0
  32. qulab/scan/optimize.py +76 -0
  33. qulab/scan/query.py +387 -0
  34. qulab/scan/record.py +603 -0
  35. qulab/scan/scan.py +1166 -0
  36. qulab/scan/server.py +450 -0
  37. qulab/scan/space.py +213 -0
  38. qulab/scan/utils.py +234 -0
  39. qulab/storage/__init__.py +0 -0
  40. qulab/storage/__main__.py +51 -0
  41. qulab/storage/backend/__init__.py +0 -0
  42. qulab/storage/backend/redis.py +204 -0
  43. qulab/storage/base_dataset.py +352 -0
  44. qulab/storage/chunk.py +60 -0
  45. qulab/storage/dataset.py +127 -0
  46. qulab/storage/file.py +273 -0
  47. qulab/storage/models/__init__.py +22 -0
  48. qulab/storage/models/base.py +4 -0
  49. qulab/storage/models/config.py +28 -0
  50. qulab/storage/models/file.py +89 -0
  51. qulab/storage/models/ipy.py +58 -0
  52. qulab/storage/models/models.py +88 -0
  53. qulab/storage/models/record.py +161 -0
  54. qulab/storage/models/report.py +22 -0
  55. qulab/storage/models/tag.py +93 -0
  56. qulab/storage/storage.py +95 -0
  57. qulab/sys/__init__.py +2 -0
  58. qulab/sys/chat.py +688 -0
  59. qulab/sys/device/__init__.py +3 -0
  60. qulab/sys/device/basedevice.py +255 -0
  61. qulab/sys/device/loader.py +86 -0
  62. qulab/sys/device/utils.py +79 -0
  63. qulab/sys/drivers/FakeInstrument.py +68 -0
  64. qulab/sys/drivers/__init__.py +0 -0
  65. qulab/sys/ipy_events.py +125 -0
  66. qulab/sys/net/__init__.py +0 -0
  67. qulab/sys/net/bencoder.py +205 -0
  68. qulab/sys/net/cli.py +169 -0
  69. qulab/sys/net/dhcp.py +543 -0
  70. qulab/sys/net/dhcpd.py +176 -0
  71. qulab/sys/net/kad.py +1142 -0
  72. qulab/sys/net/kcp.py +192 -0
  73. qulab/sys/net/nginx.py +194 -0
  74. qulab/sys/progress.py +190 -0
  75. qulab/sys/rpc/__init__.py +0 -0
  76. qulab/sys/rpc/client.py +0 -0
  77. qulab/sys/rpc/exceptions.py +96 -0
  78. qulab/sys/rpc/msgpack.py +1052 -0
  79. qulab/sys/rpc/msgpack.pyi +41 -0
  80. qulab/sys/rpc/router.py +35 -0
  81. qulab/sys/rpc/rpc.py +412 -0
  82. qulab/sys/rpc/serialize.py +139 -0
  83. qulab/sys/rpc/server.py +29 -0
  84. qulab/sys/rpc/socket.py +29 -0
  85. qulab/sys/rpc/utils.py +25 -0
  86. qulab/sys/rpc/worker.py +0 -0
  87. qulab/sys/rpc/zmq_socket.py +227 -0
  88. qulab/tools/__init__.py +0 -0
  89. qulab/tools/connection_helper.py +39 -0
  90. qulab/typing.py +2 -0
  91. qulab/utils.py +95 -0
  92. qulab/version.py +1 -0
  93. qulab/visualization/__init__.py +188 -0
  94. qulab/visualization/__main__.py +71 -0
  95. qulab/visualization/_autoplot.py +464 -0
  96. qulab/visualization/plot_circ.py +319 -0
  97. qulab/visualization/plot_layout.py +408 -0
  98. qulab/visualization/plot_seq.py +242 -0
  99. qulab/visualization/qdat.py +152 -0
  100. qulab/visualization/rot3d.py +23 -0
  101. qulab/visualization/widgets.py +86 -0
  102. qulab-2.10.10.dist-info/METADATA +110 -0
  103. qulab-2.10.10.dist-info/RECORD +107 -0
  104. qulab-2.10.10.dist-info/WHEEL +5 -0
  105. qulab-2.10.10.dist-info/entry_points.txt +2 -0
  106. qulab-2.10.10.dist-info/licenses/LICENSE +21 -0
  107. qulab-2.10.10.dist-info/top_level.txt +1 -0
@@ -0,0 +1,319 @@
1
+ import numpy as np
2
+ from matplotlib.patches import Circle, FancyArrow, PathPatch
3
+ from matplotlib.path import Path
4
+ from waveforms import *
5
+
6
+
7
+ def make_path(fx, fy, dfx, dfy, t):
8
+
9
+ def p(fx, fy, dfx, dfy, t0, t1):
10
+ x1, x2 = fx(t0), fx(t1)
11
+ y1, y2 = fy(t0), fy(t1)
12
+ dx1, dx2 = dfx(t0), dfx(t1)
13
+ dy1, dy2 = dfy(t0), dfy(t1)
14
+
15
+ xp = (dy1 * dx2 * x1 - dy2 * dx1 * x2 - dx1 * dx2 *
16
+ (y1 - y2)) / (dy1 * dx2 - dy2 * dx1)
17
+
18
+ yp = (dy1 * dx2 * y2 - dy2 * dx1 * y1 + dy1 * dy2 *
19
+ (x1 - x2)) / (dy1 * dx2 - dy2 * dx1)
20
+
21
+ return xp, yp
22
+
23
+ path = [(fx(t[0]), fy(t[0]))]
24
+ codes = [Path.MOVETO]
25
+
26
+ for i in range(1, len(t)):
27
+ x, y = p(fx, fy, dfx, dfy, t[i - 1], t[i])
28
+ path.append((x, y))
29
+ codes.append(Path.CURVE3)
30
+ path.append((fx(t[i]), fy(t[i])))
31
+ codes.append(Path.CURVE3)
32
+ return path, codes
33
+
34
+
35
+ def plot_square(ax,
36
+ x=0,
37
+ y=0,
38
+ width=1,
39
+ hight=1,
40
+ radius=0.2,
41
+ ls='-',
42
+ lw=2,
43
+ fc='none',
44
+ ec='black'):
45
+ r = radius
46
+ path = np.array([(0, 1), (1 - 2 * r, 1), (1, 1), (1, 1 - 2 * r),
47
+ (1, -1 + 2 * r), (1, -1), (1 - 2 * r, -1),
48
+ (-1 + 2 * r, -1), (-1, -1), (-1, -1 + 2 * r),
49
+ (-1, 1 - 2 * r), (-1, 1), (-1 + 2 * r, 1), (0, 1)])
50
+ path[:, 0] = path[:, 0] * width / 2 + x
51
+ path[:, 1] = path[:, 1] * hight / 2 + y
52
+ codes = [
53
+ Path.MOVETO,
54
+ Path.LINETO,
55
+ Path.CURVE3,
56
+ Path.CURVE3,
57
+ Path.LINETO,
58
+ Path.CURVE3,
59
+ Path.CURVE3,
60
+ Path.LINETO,
61
+ Path.CURVE3,
62
+ Path.CURVE3,
63
+ Path.LINETO,
64
+ Path.CURVE3,
65
+ Path.CURVE3,
66
+ Path.CLOSEPOLY,
67
+ ]
68
+ pp1 = PathPatch(Path(path, codes),
69
+ ls=ls,
70
+ lw=lw,
71
+ fc=fc,
72
+ ec=ec,
73
+ transform=ax.transData)
74
+
75
+ ax.add_artist(pp1)
76
+
77
+
78
+ def plot_measure(ax,
79
+ x=0,
80
+ y=0,
81
+ size=1,
82
+ ratio=0.8,
83
+ radius=0.2,
84
+ ls='-',
85
+ lw=2,
86
+ fc='none',
87
+ ec='black'):
88
+ width = size
89
+ hight = ratio * size
90
+ plot_square(ax, x, y, width, hight, radius, ls, lw, fc, ec)
91
+
92
+ fx = lambda t: 0.5 * width * np.cos(t) + x
93
+ fy = lambda t: 0.5 * hight * np.sin(t) + y - 0.2 * hight
94
+ dfx = lambda t: -0.5 * width * np.sin(t)
95
+ dfy = lambda t: 0.5 * hight * np.cos(t)
96
+ t = np.linspace(1 / 6, 5 / 6, 5) * np.pi
97
+ path, codes = make_path(fx, fy, dfx, dfy, t)
98
+
99
+ pp1 = PathPatch(Path(path, codes),
100
+ ls=ls,
101
+ lw=lw,
102
+ fc=fc,
103
+ ec=ec,
104
+ transform=ax.transData)
105
+
106
+ ax.add_artist(pp1)
107
+
108
+ angle = np.pi / 6
109
+
110
+ arr = FancyArrow(x,
111
+ y - 0.25 * width,
112
+ 0.55 * width * np.sin(angle),
113
+ 0.55 * width * np.cos(angle),
114
+ head_length=0.1 * width,
115
+ head_width=0.07 * width,
116
+ lw=lw,
117
+ color=ec)
118
+
119
+ ax.add_artist(arr)
120
+
121
+ return (x - width / 2, x + width / 2)
122
+
123
+
124
+ def plot_cnot(ax, x=0, ctr=1, tgt=0, size=0.5, lw=2, fc='none', ec='k'):
125
+ c = Circle((x, tgt), radius=size / 2, lw=lw, fc=fc, ec=ec)
126
+ ax.add_artist(c)
127
+
128
+ c = Circle((x, ctr), radius=0.1 * size, lw=lw, fc=ec, ec=ec)
129
+ ax.add_artist(c)
130
+
131
+ path, codes = [(x - size / 2, tgt), (
132
+ x + size / 2,
133
+ tgt,
134
+ )], [Path.MOVETO, Path.LINETO]
135
+
136
+ p = PathPatch(Path(path, codes),
137
+ ls='-',
138
+ lw=lw,
139
+ ec=ec,
140
+ transform=ax.transData)
141
+ ax.add_artist(p)
142
+
143
+ if ctr > tgt:
144
+ up, down = ctr, tgt - size / 2
145
+ else:
146
+ up, down = tgt + size / 2, ctr
147
+ path, codes = [(x, up), (x, down)], [Path.MOVETO, Path.LINETO]
148
+
149
+ p = PathPatch(Path(path, codes),
150
+ ls='-',
151
+ lw=lw,
152
+ ec=ec,
153
+ transform=ax.transData)
154
+ ax.add_artist(p)
155
+
156
+ return (x - 0.1 * size, x + 0.1 * size), (x - 0.5 * size, x + 0.5 * size)
157
+
158
+
159
+ def plot_cz(ax, x=0, ctr=1, tgt=0, size=0.5, lw=2, fc='none', ec='k'):
160
+ c = Circle((x, ctr), radius=0.1 * size, lw=lw, fc=ec, ec=ec)
161
+ ax.add_artist(c)
162
+
163
+ c = Circle((x, tgt), radius=0.1 * size, lw=lw, fc=ec, ec=ec)
164
+ ax.add_artist(c)
165
+
166
+ path, codes = [(x, ctr), (x, tgt)], [Path.MOVETO, Path.LINETO]
167
+
168
+ p = PathPatch(Path(path, codes),
169
+ ls='-',
170
+ lw=lw,
171
+ ec=ec,
172
+ transform=ax.transData)
173
+ ax.add_artist(p)
174
+
175
+ return (x - 0.1 * size, x + 0.1 * size), (x - 0.1 * size, x + 0.1 * size)
176
+
177
+
178
+ def plot_iswap(ax, x=0, ctr=1, tgt=0, size=0.2, lw=2, fc='none', ec='k'):
179
+ path, codes = [(x - size / 2, ctr - size / 2),
180
+ (x + size / 2, ctr + size / 2)], [Path.MOVETO, Path.LINETO]
181
+ p = PathPatch(Path(path, codes),
182
+ ls='-',
183
+ lw=lw,
184
+ ec=ec,
185
+ transform=ax.transData)
186
+ ax.add_artist(p)
187
+
188
+ path, codes = [(x - size / 2, ctr + size / 2),
189
+ (x + size / 2, ctr - size / 2)], [Path.MOVETO, Path.LINETO]
190
+ p = PathPatch(Path(path, codes),
191
+ ls='-',
192
+ lw=lw,
193
+ ec=ec,
194
+ transform=ax.transData)
195
+ ax.add_artist(p)
196
+
197
+ path, codes = [(x - size / 2, tgt - size / 2),
198
+ (x + size / 2, tgt + size / 2)], [Path.MOVETO, Path.LINETO]
199
+ p = PathPatch(Path(path, codes),
200
+ ls='-',
201
+ lw=lw,
202
+ ec=ec,
203
+ transform=ax.transData)
204
+ ax.add_artist(p)
205
+
206
+ path, codes = [(x - size / 2, tgt + size / 2),
207
+ (x + size / 2, tgt - size / 2)], [Path.MOVETO, Path.LINETO]
208
+ p = PathPatch(Path(path, codes),
209
+ ls='-',
210
+ lw=lw,
211
+ ec=ec,
212
+ transform=ax.transData)
213
+ ax.add_artist(p)
214
+
215
+ path, codes = [(x, ctr), (x, tgt)], [Path.MOVETO, Path.LINETO]
216
+ p = PathPatch(Path(path, codes),
217
+ ls='-',
218
+ lw=lw,
219
+ ec=ec,
220
+ transform=ax.transData)
221
+ ax.add_artist(p)
222
+
223
+ return (x, x), (x, x)
224
+
225
+
226
+ def plot_gate(ax,
227
+ x=0,
228
+ y=0,
229
+ size=1,
230
+ ratio=0.8,
231
+ radius=0.2,
232
+ text="$U$",
233
+ ls='-',
234
+ lw=2,
235
+ fc='none',
236
+ ec='black',
237
+ fontsize=16):
238
+ width = size
239
+ hight = ratio * size
240
+ plot_square(ax,
241
+ x,
242
+ y,
243
+ width,
244
+ hight,
245
+ radius=radius,
246
+ ls=ls,
247
+ lw=lw,
248
+ fc=fc,
249
+ ec=ec)
250
+ ax.text(x, y, text, ha='center', va='center', color=ec, fontsize=fontsize)
251
+
252
+ return (x - width / 2, x + width / 2)
253
+
254
+
255
+ def plot_waveform(ax,
256
+ wav,
257
+ offset,
258
+ gaps=[],
259
+ ec='black',
260
+ fc='none',
261
+ ls='-',
262
+ lw=2):
263
+ t = np.linspace(wav.start, wav.stop, 1001)
264
+ points = wav(t) + offset
265
+ for a, b in gaps:
266
+ points[(t > a) * (t < b)] = np.nan
267
+ ax.plot(t, points, ls=ls, color=ec, lw=lw)
268
+ if fc != 'none':
269
+ ax.fill_between(t, points, offset, color=fc)
270
+
271
+
272
+ def _max_ticks(table, *qubits):
273
+ ticks = []
274
+ for q in qubits:
275
+ ticks.append(len(table.get(q, [])))
276
+ return max(ticks)
277
+
278
+
279
+ def _extend_table(table, q, ticks):
280
+ table[q] = table.get(q, []) + [None] * (ticks - len(table.get(q, [])))
281
+
282
+
283
+ def _barrier(table, *qubits):
284
+ ticks = _max_ticks(table, *qubits)
285
+ for q in qubits:
286
+ _extend_table(table, q, ticks)
287
+
288
+
289
+ def qlisp_to_table(circ):
290
+ table = {}
291
+ for gate, *qubits in circ:
292
+ _barrier(table, *qubits)
293
+ if isinstance(gate, str) and gate == 'Barrier':
294
+ continue
295
+ for q in qubits:
296
+ table[q].append((gate, *qubits))
297
+ _barrier(table, *table.keys())
298
+ return table
299
+
300
+
301
+ def table_to_layers(table):
302
+ layers = []
303
+ for q, gates in table.items():
304
+ for i, gate in enumerate(gates):
305
+ if len(layers) <= i:
306
+ layers.append({})
307
+ layers[i][q] = gate
308
+ return layers
309
+
310
+
311
+ def _plot_layer(ax, layer, qubit_mapping=None):
312
+ gaps = {}
313
+ if qubit_mapping is None:
314
+ qubit_mapping = sorted(layer.keys())
315
+ return gaps
316
+
317
+
318
+ def plot_qlisp(ax, circ, qubit_mapping=None):
319
+ layers = table_to_layers(qlisp_to_table(circ))