QuLab 2.10.10__cp313-cp313-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.
- qulab/__init__.py +33 -0
- qulab/__main__.py +4 -0
- qulab/cli/__init__.py +0 -0
- qulab/cli/commands.py +30 -0
- qulab/cli/config.py +170 -0
- qulab/cli/decorators.py +28 -0
- qulab/dicttree.py +523 -0
- qulab/executor/__init__.py +5 -0
- qulab/executor/analyze.py +188 -0
- qulab/executor/cli.py +434 -0
- qulab/executor/load.py +563 -0
- qulab/executor/registry.py +185 -0
- qulab/executor/schedule.py +543 -0
- qulab/executor/storage.py +615 -0
- qulab/executor/template.py +259 -0
- qulab/executor/utils.py +194 -0
- qulab/expression.py +827 -0
- qulab/fun.cp313-win_amd64.pyd +0 -0
- qulab/monitor/__init__.py +1 -0
- qulab/monitor/__main__.py +8 -0
- qulab/monitor/config.py +41 -0
- qulab/monitor/dataset.py +77 -0
- qulab/monitor/event_queue.py +54 -0
- qulab/monitor/mainwindow.py +234 -0
- qulab/monitor/monitor.py +115 -0
- qulab/monitor/ploter.py +123 -0
- qulab/monitor/qt_compat.py +16 -0
- qulab/monitor/toolbar.py +265 -0
- qulab/scan/__init__.py +2 -0
- qulab/scan/curd.py +221 -0
- qulab/scan/models.py +554 -0
- qulab/scan/optimize.py +76 -0
- qulab/scan/query.py +387 -0
- qulab/scan/record.py +603 -0
- qulab/scan/scan.py +1166 -0
- qulab/scan/server.py +450 -0
- qulab/scan/space.py +213 -0
- qulab/scan/utils.py +234 -0
- qulab/storage/__init__.py +0 -0
- qulab/storage/__main__.py +51 -0
- qulab/storage/backend/__init__.py +0 -0
- qulab/storage/backend/redis.py +204 -0
- qulab/storage/base_dataset.py +352 -0
- qulab/storage/chunk.py +60 -0
- qulab/storage/dataset.py +127 -0
- qulab/storage/file.py +273 -0
- qulab/storage/models/__init__.py +22 -0
- qulab/storage/models/base.py +4 -0
- qulab/storage/models/config.py +28 -0
- qulab/storage/models/file.py +89 -0
- qulab/storage/models/ipy.py +58 -0
- qulab/storage/models/models.py +88 -0
- qulab/storage/models/record.py +161 -0
- qulab/storage/models/report.py +22 -0
- qulab/storage/models/tag.py +93 -0
- qulab/storage/storage.py +95 -0
- qulab/sys/__init__.py +2 -0
- qulab/sys/chat.py +688 -0
- qulab/sys/device/__init__.py +3 -0
- qulab/sys/device/basedevice.py +255 -0
- qulab/sys/device/loader.py +86 -0
- qulab/sys/device/utils.py +79 -0
- qulab/sys/drivers/FakeInstrument.py +68 -0
- qulab/sys/drivers/__init__.py +0 -0
- qulab/sys/ipy_events.py +125 -0
- qulab/sys/net/__init__.py +0 -0
- qulab/sys/net/bencoder.py +205 -0
- qulab/sys/net/cli.py +169 -0
- qulab/sys/net/dhcp.py +543 -0
- qulab/sys/net/dhcpd.py +176 -0
- qulab/sys/net/kad.py +1142 -0
- qulab/sys/net/kcp.py +192 -0
- qulab/sys/net/nginx.py +194 -0
- qulab/sys/progress.py +190 -0
- qulab/sys/rpc/__init__.py +0 -0
- qulab/sys/rpc/client.py +0 -0
- qulab/sys/rpc/exceptions.py +96 -0
- qulab/sys/rpc/msgpack.py +1052 -0
- qulab/sys/rpc/msgpack.pyi +41 -0
- qulab/sys/rpc/router.py +35 -0
- qulab/sys/rpc/rpc.py +412 -0
- qulab/sys/rpc/serialize.py +139 -0
- qulab/sys/rpc/server.py +29 -0
- qulab/sys/rpc/socket.py +29 -0
- qulab/sys/rpc/utils.py +25 -0
- qulab/sys/rpc/worker.py +0 -0
- qulab/sys/rpc/zmq_socket.py +227 -0
- qulab/tools/__init__.py +0 -0
- qulab/tools/connection_helper.py +39 -0
- qulab/typing.py +2 -0
- qulab/utils.py +95 -0
- qulab/version.py +1 -0
- qulab/visualization/__init__.py +188 -0
- qulab/visualization/__main__.py +71 -0
- qulab/visualization/_autoplot.py +464 -0
- qulab/visualization/plot_circ.py +319 -0
- qulab/visualization/plot_layout.py +408 -0
- qulab/visualization/plot_seq.py +242 -0
- qulab/visualization/qdat.py +152 -0
- qulab/visualization/rot3d.py +23 -0
- qulab/visualization/widgets.py +86 -0
- qulab-2.10.10.dist-info/METADATA +110 -0
- qulab-2.10.10.dist-info/RECORD +107 -0
- qulab-2.10.10.dist-info/WHEEL +5 -0
- qulab-2.10.10.dist-info/entry_points.txt +2 -0
- qulab-2.10.10.dist-info/licenses/LICENSE +21 -0
- qulab-2.10.10.dist-info/top_level.txt +1 -0
qulab/scan/models.py
ADDED
@@ -0,0 +1,554 @@
|
|
1
|
+
import hashlib
|
2
|
+
import pickle
|
3
|
+
from datetime import datetime, timezone
|
4
|
+
from functools import singledispatchmethod
|
5
|
+
|
6
|
+
from sqlalchemy import (Column, DateTime, Float, ForeignKey, Integer,
|
7
|
+
LargeBinary, String, Table, Text, create_engine)
|
8
|
+
from sqlalchemy.orm import (backref, declarative_base, relationship,
|
9
|
+
sessionmaker)
|
10
|
+
from sqlalchemy.orm.session import Session
|
11
|
+
|
12
|
+
|
13
|
+
def utcnow():
|
14
|
+
return datetime.now(timezone.utc)
|
15
|
+
|
16
|
+
|
17
|
+
Base = declarative_base()
|
18
|
+
|
19
|
+
# association table
|
20
|
+
user_roles = Table('user_roles', Base.metadata,
|
21
|
+
Column('user_id', ForeignKey('users.id'), primary_key=True),
|
22
|
+
Column('role_id', ForeignKey('roles.id'), primary_key=True))
|
23
|
+
|
24
|
+
record_reports = Table(
|
25
|
+
'record_reports', Base.metadata,
|
26
|
+
Column('record_id', ForeignKey('records.id'), primary_key=True),
|
27
|
+
Column('report_id', ForeignKey('reports.id'), primary_key=True))
|
28
|
+
|
29
|
+
comment_tags = Table(
|
30
|
+
'comment_tags', Base.metadata,
|
31
|
+
Column('comment_id', ForeignKey('comments.id'), primary_key=True),
|
32
|
+
Column('tag_id', ForeignKey('tags.id'), primary_key=True))
|
33
|
+
|
34
|
+
snapshot_tags = Table(
|
35
|
+
'snapshot_tags', Base.metadata,
|
36
|
+
Column('snapshot_id', ForeignKey('snapshots.id'), primary_key=True),
|
37
|
+
Column('tag_id', ForeignKey('tags.id'), primary_key=True))
|
38
|
+
|
39
|
+
record_tags = Table(
|
40
|
+
'record_tags', Base.metadata,
|
41
|
+
Column('record_id', ForeignKey('records.id'), primary_key=True),
|
42
|
+
Column('tag_id', ForeignKey('tags.id'), primary_key=True))
|
43
|
+
|
44
|
+
report_tags = Table(
|
45
|
+
'report_tags', Base.metadata,
|
46
|
+
Column('report_id', ForeignKey('reports.id'), primary_key=True),
|
47
|
+
Column('tag_id', ForeignKey('tags.id'), primary_key=True))
|
48
|
+
|
49
|
+
sample_tags = Table(
|
50
|
+
'sample_tags', Base.metadata,
|
51
|
+
Column('sample_id', ForeignKey('samples.id'), primary_key=True),
|
52
|
+
Column('tag_id', ForeignKey('tags.id'), primary_key=True))
|
53
|
+
|
54
|
+
sample_reports = Table(
|
55
|
+
'sample_reports', Base.metadata,
|
56
|
+
Column('sample_id', ForeignKey('samples.id'), primary_key=True),
|
57
|
+
Column('report_id', ForeignKey('reports.id'), primary_key=True))
|
58
|
+
|
59
|
+
sample_records = Table(
|
60
|
+
'sample_records', Base.metadata,
|
61
|
+
Column('sample_id', ForeignKey('samples.id'), primary_key=True),
|
62
|
+
Column('record_id', ForeignKey('records.id'), primary_key=True))
|
63
|
+
|
64
|
+
sample_comments = Table(
|
65
|
+
'sample_comments', Base.metadata,
|
66
|
+
Column('sample_id', ForeignKey('samples.id'), primary_key=True),
|
67
|
+
Column('comment_id', ForeignKey('comments.id'), primary_key=True))
|
68
|
+
|
69
|
+
sample_transfer_comments = Table(
|
70
|
+
'sample_transfer_comments', Base.metadata,
|
71
|
+
Column('transfer_id', ForeignKey('sample_transfer.id'), primary_key=True),
|
72
|
+
Column('comment_id', ForeignKey('comments.id'), primary_key=True))
|
73
|
+
|
74
|
+
report_comments = Table(
|
75
|
+
'report_comments', Base.metadata,
|
76
|
+
Column('report_id', ForeignKey('reports.id'), primary_key=True),
|
77
|
+
Column('comment_id', ForeignKey('comments.id'), primary_key=True))
|
78
|
+
|
79
|
+
record_comments = Table(
|
80
|
+
'record_comments', Base.metadata,
|
81
|
+
Column('record_id', ForeignKey('records.id'), primary_key=True),
|
82
|
+
Column('comment_id', ForeignKey('comments.id'), primary_key=True))
|
83
|
+
|
84
|
+
|
85
|
+
class Role(Base):
|
86
|
+
__tablename__ = 'roles'
|
87
|
+
|
88
|
+
id = Column(Integer, primary_key=True)
|
89
|
+
name = Column(String)
|
90
|
+
|
91
|
+
users = relationship('User', secondary=user_roles, back_populates='roles')
|
92
|
+
|
93
|
+
def __repr__(self):
|
94
|
+
return f"Role(name='{self.name}')"
|
95
|
+
|
96
|
+
|
97
|
+
class User(Base):
|
98
|
+
__tablename__ = 'users'
|
99
|
+
|
100
|
+
id = Column(Integer, primary_key=True)
|
101
|
+
name = Column(String, unique=True)
|
102
|
+
hashed_password = Column(LargeBinary(64))
|
103
|
+
fullname = Column(String)
|
104
|
+
|
105
|
+
roles = relationship('Role', secondary=user_roles, back_populates='users')
|
106
|
+
attachments = relationship('Attachment', back_populates='user')
|
107
|
+
comments = relationship('Comment', back_populates='user')
|
108
|
+
|
109
|
+
# def setPassword(self, password):
|
110
|
+
# self.hashed_password = encryptPassword(password)
|
111
|
+
|
112
|
+
# def verify(self, password):
|
113
|
+
# try:
|
114
|
+
# verifyPassword(password, self.hashed_password)
|
115
|
+
# return True
|
116
|
+
# except InvalidKey:
|
117
|
+
# return False
|
118
|
+
|
119
|
+
def __repr__(self):
|
120
|
+
return f"User(name='{self.name}')"
|
121
|
+
|
122
|
+
|
123
|
+
class ParameterEdge(Base):
|
124
|
+
__tablename__ = 'parameter_edges'
|
125
|
+
parent_id = Column(ForeignKey('parameters.id'), primary_key=True)
|
126
|
+
child_id = Column(ForeignKey('parameters.id'), primary_key=True)
|
127
|
+
key = Column(String(50), primary_key=True)
|
128
|
+
|
129
|
+
|
130
|
+
class Parameter(Base):
|
131
|
+
__tablename__ = 'parameters'
|
132
|
+
|
133
|
+
id = Column(Integer, primary_key=True)
|
134
|
+
type = Column(String)
|
135
|
+
unit = Column(String)
|
136
|
+
integer = Column(Integer)
|
137
|
+
real = Column(Float)
|
138
|
+
imag = Column(Float)
|
139
|
+
string = Column(String)
|
140
|
+
buff = Column(LargeBinary)
|
141
|
+
|
142
|
+
children = relationship("ParameterEdge",
|
143
|
+
foreign_keys=[ParameterEdge.parent_id],
|
144
|
+
backref="parent")
|
145
|
+
parents = relationship("ParameterEdge",
|
146
|
+
foreign_keys=[ParameterEdge.child_id],
|
147
|
+
backref="child")
|
148
|
+
|
149
|
+
@property
|
150
|
+
def value(self):
|
151
|
+
if self.type == 'integer':
|
152
|
+
return self.integer
|
153
|
+
elif self.type == 'real':
|
154
|
+
return self.real
|
155
|
+
elif self.type == 'complex':
|
156
|
+
return self.real + 1j * self.imag
|
157
|
+
elif self.type == 'string':
|
158
|
+
return self.string
|
159
|
+
elif self.type == 'buffer':
|
160
|
+
return self.buff
|
161
|
+
elif self.type == 'boolean':
|
162
|
+
return self.integer == 1
|
163
|
+
elif self.type is None or self.type == 'none':
|
164
|
+
return None
|
165
|
+
elif self.type == 'tree':
|
166
|
+
return self.export()
|
167
|
+
else:
|
168
|
+
return pickle.loads(self.buff)
|
169
|
+
|
170
|
+
@value.setter
|
171
|
+
def value(self, value):
|
172
|
+
self._set_value(value)
|
173
|
+
|
174
|
+
@singledispatchmethod
|
175
|
+
def _set_value(self, value):
|
176
|
+
self.buff = pickle.dumps(value)
|
177
|
+
self.type = 'pickle'
|
178
|
+
|
179
|
+
@_set_value.register
|
180
|
+
def _(self, value: int):
|
181
|
+
self.integer = value
|
182
|
+
self.type = 'integer'
|
183
|
+
|
184
|
+
@_set_value.register
|
185
|
+
def _(self, value: bool):
|
186
|
+
self.integer = int(value)
|
187
|
+
self.type = 'boolean'
|
188
|
+
|
189
|
+
@_set_value.register
|
190
|
+
def _(self, value: float):
|
191
|
+
self.real = value
|
192
|
+
self.type = 'real'
|
193
|
+
|
194
|
+
@_set_value.register
|
195
|
+
def _(self, value: complex):
|
196
|
+
self.real = value.real
|
197
|
+
self.imag = value.imag
|
198
|
+
self.type = 'complex'
|
199
|
+
|
200
|
+
@_set_value.register
|
201
|
+
def _(self, value: str):
|
202
|
+
self.string = value
|
203
|
+
self.type = 'string'
|
204
|
+
|
205
|
+
@_set_value.register
|
206
|
+
def _(self, value: bytes):
|
207
|
+
self.buff = value
|
208
|
+
self.type = 'buffer'
|
209
|
+
|
210
|
+
@_set_value.register
|
211
|
+
def _(self, value: None):
|
212
|
+
self.type = 'none'
|
213
|
+
|
214
|
+
def export(self):
|
215
|
+
if self.type == 'tree':
|
216
|
+
return {a.key: a.child.export() for a in self.children}
|
217
|
+
else:
|
218
|
+
return self.value
|
219
|
+
|
220
|
+
|
221
|
+
class Snapshot(Base):
|
222
|
+
__tablename__ = 'snapshots'
|
223
|
+
|
224
|
+
id = Column(Integer, primary_key=True)
|
225
|
+
root_id = Column(ForeignKey('parameters.id'))
|
226
|
+
previous_id = Column(Integer, ForeignKey('snapshots.id'))
|
227
|
+
|
228
|
+
followers = relationship("Snapshot",
|
229
|
+
backref=backref('previous', remote_side=[id]))
|
230
|
+
|
231
|
+
root = relationship('Parameter')
|
232
|
+
tags = relationship('Tag',
|
233
|
+
secondary=snapshot_tags,
|
234
|
+
back_populates='snapshots')
|
235
|
+
|
236
|
+
def export(self):
|
237
|
+
return self.root.export()
|
238
|
+
|
239
|
+
|
240
|
+
class ReportParameters(Base):
|
241
|
+
__tablename__ = 'report_parameters'
|
242
|
+
parent_id = Column(ForeignKey('reports.id'), primary_key=True)
|
243
|
+
child_id = Column(ForeignKey('parameters.id'), primary_key=True)
|
244
|
+
key = Column(String(50), primary_key=True)
|
245
|
+
|
246
|
+
parameter = relationship('Parameter')
|
247
|
+
|
248
|
+
@property
|
249
|
+
def value(self):
|
250
|
+
return self.parameter.value
|
251
|
+
|
252
|
+
|
253
|
+
class Tag(Base):
|
254
|
+
__tablename__ = 'tags'
|
255
|
+
|
256
|
+
id = Column(Integer, primary_key=True)
|
257
|
+
text = Column(String, unique=True)
|
258
|
+
|
259
|
+
comments = relationship('Comment',
|
260
|
+
secondary=comment_tags,
|
261
|
+
back_populates='tags')
|
262
|
+
records = relationship('Record',
|
263
|
+
secondary=record_tags,
|
264
|
+
back_populates='tags')
|
265
|
+
reports = relationship('Report',
|
266
|
+
secondary=report_tags,
|
267
|
+
back_populates='tags')
|
268
|
+
samples = relationship('Sample',
|
269
|
+
secondary=sample_tags,
|
270
|
+
back_populates='tags')
|
271
|
+
snapshots = relationship('Snapshot',
|
272
|
+
secondary=snapshot_tags,
|
273
|
+
back_populates='tags')
|
274
|
+
|
275
|
+
def __init__(self, text) -> None:
|
276
|
+
super().__init__()
|
277
|
+
self.text = text
|
278
|
+
|
279
|
+
def __repr__(self):
|
280
|
+
return f"Tag('{self.text}')"
|
281
|
+
|
282
|
+
|
283
|
+
class Comment(Base):
|
284
|
+
__tablename__ = 'comments'
|
285
|
+
|
286
|
+
id = Column(Integer, primary_key=True)
|
287
|
+
text = Column(String)
|
288
|
+
user_id = Column(Integer, ForeignKey('users.id'))
|
289
|
+
ctime = Column(DateTime, default=utcnow)
|
290
|
+
mtime = Column(DateTime, default=utcnow)
|
291
|
+
atime = Column(DateTime, default=utcnow)
|
292
|
+
parent_id = Column(Integer, ForeignKey('comments.id'))
|
293
|
+
|
294
|
+
replies = relationship("Comment", lazy="joined", join_depth=2)
|
295
|
+
user = relationship('User', back_populates='comments')
|
296
|
+
tags = relationship('Tag',
|
297
|
+
secondary=comment_tags,
|
298
|
+
back_populates='comments')
|
299
|
+
attachments = relationship('Attachment', back_populates='comment')
|
300
|
+
|
301
|
+
|
302
|
+
class Attachment(Base):
|
303
|
+
__tablename__ = 'attachments'
|
304
|
+
|
305
|
+
id = Column(Integer, primary_key=True)
|
306
|
+
filename = Column(String)
|
307
|
+
mime_type = Column(String, default='application/octet-stream')
|
308
|
+
user_id = Column(Integer, ForeignKey('users.id'))
|
309
|
+
comment_id = Column(Integer, ForeignKey('comments.id'))
|
310
|
+
ctime = Column(DateTime, default=utcnow)
|
311
|
+
mtime = Column(DateTime, default=utcnow)
|
312
|
+
atime = Column(DateTime, default=utcnow)
|
313
|
+
size = Column(Integer)
|
314
|
+
sha1 = Column(String)
|
315
|
+
description = Column(Text)
|
316
|
+
|
317
|
+
user = relationship('User', back_populates='attachments')
|
318
|
+
comment = relationship('Comment', back_populates='attachments')
|
319
|
+
|
320
|
+
|
321
|
+
class InputText(Base):
|
322
|
+
__tablename__ = 'inputs'
|
323
|
+
|
324
|
+
id = Column(Integer, primary_key=True)
|
325
|
+
hash = Column(LargeBinary(20), index=True)
|
326
|
+
text_field = Column(Text, unique=True)
|
327
|
+
|
328
|
+
@property
|
329
|
+
def text(self):
|
330
|
+
return self.text_field
|
331
|
+
|
332
|
+
@text.setter
|
333
|
+
def text(self, text):
|
334
|
+
self.hash = hashlib.sha1(text.encode('utf-8')).digest()
|
335
|
+
self.text_field = text
|
336
|
+
|
337
|
+
def __repr__(self) -> str:
|
338
|
+
return self.text
|
339
|
+
|
340
|
+
|
341
|
+
class Cell(Base):
|
342
|
+
__tablename__ = 'cells'
|
343
|
+
|
344
|
+
id = Column(Integer, primary_key=True)
|
345
|
+
notebook_id = Column(Integer, ForeignKey("notebooks.id"))
|
346
|
+
index = Column(Integer)
|
347
|
+
ctime = Column(DateTime, default=utcnow)
|
348
|
+
ftime = Column(DateTime, default=utcnow)
|
349
|
+
input_id = Column(Integer, ForeignKey("inputs.id"))
|
350
|
+
|
351
|
+
notebook = relationship("Notebook", back_populates="cells")
|
352
|
+
input = relationship("InputText")
|
353
|
+
|
354
|
+
def __repr__(self) -> str:
|
355
|
+
return str(f"Cell(index={self.index}, input='{self.input}')")
|
356
|
+
|
357
|
+
|
358
|
+
class Notebook(Base):
|
359
|
+
__tablename__ = 'notebooks'
|
360
|
+
|
361
|
+
id = Column(Integer, primary_key=True)
|
362
|
+
name = Column(String)
|
363
|
+
ctime = Column(DateTime, default=utcnow)
|
364
|
+
atime = Column(DateTime, default=utcnow)
|
365
|
+
|
366
|
+
cells = relationship("Cell",
|
367
|
+
order_by=Cell.index,
|
368
|
+
back_populates="notebook")
|
369
|
+
|
370
|
+
|
371
|
+
class Sample(Base):
|
372
|
+
__tablename__ = 'samples'
|
373
|
+
|
374
|
+
id = Column(Integer, primary_key=True)
|
375
|
+
name = Column(String)
|
376
|
+
|
377
|
+
account_id = Column(Integer, ForeignKey("sample_accounts.id"))
|
378
|
+
|
379
|
+
tags = relationship("Tag", secondary=sample_tags, back_populates="samples")
|
380
|
+
records = relationship("Record",
|
381
|
+
secondary=sample_records,
|
382
|
+
back_populates="samples")
|
383
|
+
reports = relationship("Report",
|
384
|
+
secondary=sample_reports,
|
385
|
+
back_populates="samples")
|
386
|
+
transfers = relationship("SampleTransfer",
|
387
|
+
order_by="SampleTransfer.ctime",
|
388
|
+
back_populates="sample")
|
389
|
+
account = relationship("SampleAccount", back_populates="samples")
|
390
|
+
comments = relationship("Comment", secondary=sample_comments)
|
391
|
+
|
392
|
+
|
393
|
+
class SampleAccountType(Base):
|
394
|
+
__tablename__ = 'sample_account_types'
|
395
|
+
id = Column(Integer, primary_key=True)
|
396
|
+
name = Column(String)
|
397
|
+
description = Column(String)
|
398
|
+
|
399
|
+
accounts = relationship("SampleAccount", back_populates="type")
|
400
|
+
|
401
|
+
|
402
|
+
class SampleAccount(Base):
|
403
|
+
__tablename__ = 'sample_accounts'
|
404
|
+
|
405
|
+
id = Column(Integer, primary_key=True)
|
406
|
+
name = Column(String)
|
407
|
+
type_id = Column(Integer, ForeignKey("sample_account_types.id"))
|
408
|
+
description = Column(String)
|
409
|
+
|
410
|
+
type = relationship("SampleAccountType", back_populates="accounts")
|
411
|
+
|
412
|
+
samples = relationship("Sample", back_populates="account")
|
413
|
+
|
414
|
+
|
415
|
+
class SampleTransfer(Base):
|
416
|
+
__tablename__ = 'sample_transfer'
|
417
|
+
|
418
|
+
id = Column(Integer, primary_key=True)
|
419
|
+
sample_id = Column(Integer, ForeignKey("samples.id"))
|
420
|
+
user_id = Column(Integer, ForeignKey("users.id"))
|
421
|
+
ctime = Column(DateTime, default=utcnow)
|
422
|
+
debtor_id = Column(Integer, ForeignKey("sample_accounts.id"))
|
423
|
+
creditor_id = Column(Integer, ForeignKey("sample_accounts.id"))
|
424
|
+
|
425
|
+
user = relationship("User")
|
426
|
+
sample = relationship("Sample", back_populates="transfers")
|
427
|
+
debtor = relationship("SampleAccount", foreign_keys=[debtor_id])
|
428
|
+
creditor = relationship("SampleAccount", foreign_keys=[creditor_id])
|
429
|
+
comments = relationship("Comment", secondary=sample_transfer_comments)
|
430
|
+
|
431
|
+
|
432
|
+
class Config(Base):
|
433
|
+
__tablename__ = 'configs'
|
434
|
+
|
435
|
+
id = Column(Integer, primary_key=True)
|
436
|
+
hash = Column(LargeBinary(20), index=True)
|
437
|
+
file = Column(String)
|
438
|
+
content_type = Column(String, default='application/pickle')
|
439
|
+
ctime = Column(DateTime, default=utcnow)
|
440
|
+
atime = Column(DateTime, default=utcnow)
|
441
|
+
|
442
|
+
records = relationship("Record", back_populates="config")
|
443
|
+
|
444
|
+
def __init__(self, data: bytes) -> None:
|
445
|
+
self.hash = hashlib.sha1(data).digest()
|
446
|
+
|
447
|
+
|
448
|
+
class Record(Base):
|
449
|
+
__tablename__ = 'records'
|
450
|
+
|
451
|
+
id = Column(Integer, primary_key=True)
|
452
|
+
ctime = Column(DateTime, default=utcnow)
|
453
|
+
mtime = Column(DateTime, default=utcnow)
|
454
|
+
atime = Column(DateTime, default=utcnow)
|
455
|
+
user_id = Column(Integer, ForeignKey('users.id'))
|
456
|
+
config_id = Column(Integer, ForeignKey('configs.id'))
|
457
|
+
parent_id = Column(Integer, ForeignKey('records.id'))
|
458
|
+
cell_id = Column(Integer, ForeignKey('cells.id'))
|
459
|
+
|
460
|
+
app = Column(String)
|
461
|
+
file = Column(String)
|
462
|
+
content_type = Column(String, default='application/pickle')
|
463
|
+
key = Column(String)
|
464
|
+
|
465
|
+
parent = relationship("Record",
|
466
|
+
remote_side=[id],
|
467
|
+
back_populates="children")
|
468
|
+
children = relationship("Record",
|
469
|
+
remote_side=[parent_id],
|
470
|
+
back_populates="parent")
|
471
|
+
|
472
|
+
config = relationship("Config", back_populates="records")
|
473
|
+
user = relationship("User")
|
474
|
+
samples = relationship("Sample",
|
475
|
+
secondary=sample_records,
|
476
|
+
back_populates="records")
|
477
|
+
cell = relationship("Cell")
|
478
|
+
|
479
|
+
reports = relationship('Report',
|
480
|
+
secondary=record_reports,
|
481
|
+
back_populates='records')
|
482
|
+
tags = relationship('Tag', secondary=record_tags, back_populates='records')
|
483
|
+
comments = relationship('Comment', secondary=record_comments)
|
484
|
+
|
485
|
+
|
486
|
+
class Report(Base):
|
487
|
+
__tablename__ = 'reports'
|
488
|
+
|
489
|
+
id = Column(Integer, primary_key=True)
|
490
|
+
ctime = Column(DateTime, default=utcnow)
|
491
|
+
mtime = Column(DateTime, default=utcnow)
|
492
|
+
atime = Column(DateTime, default=utcnow)
|
493
|
+
user_id = Column(Integer, ForeignKey('users.id'))
|
494
|
+
|
495
|
+
category = Column(String)
|
496
|
+
title = Column(String)
|
497
|
+
content = Column(Text)
|
498
|
+
file = Column(String)
|
499
|
+
key = Column(String)
|
500
|
+
task_hash = Column(LargeBinary(32))
|
501
|
+
|
502
|
+
user = relationship("User")
|
503
|
+
samples = relationship("Sample",
|
504
|
+
secondary=sample_reports,
|
505
|
+
back_populates="reports")
|
506
|
+
|
507
|
+
records = relationship('Record',
|
508
|
+
secondary=record_reports,
|
509
|
+
back_populates='reports')
|
510
|
+
|
511
|
+
tags = relationship('Tag', secondary=report_tags, back_populates='reports')
|
512
|
+
comments = relationship('Comment', secondary=report_comments)
|
513
|
+
_parameters = relationship('ReportParameters')
|
514
|
+
|
515
|
+
|
516
|
+
def create_tables(engine, tables_only=False):
|
517
|
+
Base.metadata.create_all(engine)
|
518
|
+
if tables_only:
|
519
|
+
return
|
520
|
+
|
521
|
+
sys_role = Role(name='sys')
|
522
|
+
kernel = User(name='BIG BROTHER')
|
523
|
+
kernel.roles.append(sys_role)
|
524
|
+
|
525
|
+
root_role = Role(name='root')
|
526
|
+
admin_role = Role(name='admin')
|
527
|
+
root_user = User(name='root')
|
528
|
+
# root_user.setPassword('123')
|
529
|
+
root_user.roles.append(root_role)
|
530
|
+
root_user.roles.append(admin_role)
|
531
|
+
|
532
|
+
guest_role = Role(name='guest')
|
533
|
+
guest_user = User(name='guest')
|
534
|
+
# guest_user.setPassword('')
|
535
|
+
guest_user.roles.append(guest_role)
|
536
|
+
|
537
|
+
t1 = SampleAccountType(name='factory')
|
538
|
+
t2 = SampleAccountType(name='destroyed')
|
539
|
+
t3 = SampleAccountType(name='storage')
|
540
|
+
t4 = SampleAccountType(name='fridge')
|
541
|
+
a = SampleAccount(name='destroyed')
|
542
|
+
a.type = t2
|
543
|
+
|
544
|
+
Session = sessionmaker(bind=engine)
|
545
|
+
session = Session()
|
546
|
+
|
547
|
+
session.add(root_user)
|
548
|
+
session.add(guest_user)
|
549
|
+
session.add(kernel)
|
550
|
+
session.add_all([t1, t2, t3, t4, a])
|
551
|
+
try:
|
552
|
+
session.commit()
|
553
|
+
except:
|
554
|
+
session.rollback()
|
qulab/scan/optimize.py
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
from typing import Any, Sequence
|
2
|
+
|
3
|
+
import nevergrad as ng
|
4
|
+
import numpy as np
|
5
|
+
from scipy.optimize import OptimizeResult
|
6
|
+
|
7
|
+
|
8
|
+
class NgOptimizer():
|
9
|
+
|
10
|
+
def __init__(self, variables, **kwds):
|
11
|
+
self._all_x, self._all_y = [], []
|
12
|
+
self.config = {
|
13
|
+
'method': 'TBPSA',
|
14
|
+
'budget': 100,
|
15
|
+
}
|
16
|
+
self.config.update(kwds)
|
17
|
+
instrum = []
|
18
|
+
self.dimensions = variables
|
19
|
+
for space in variables:
|
20
|
+
|
21
|
+
if space.transform_ == "normalize":
|
22
|
+
instrum.append(ng.p.Scalar(init=0.5, lower=0, upper=1))
|
23
|
+
else:
|
24
|
+
if space.prior == "log-uniform":
|
25
|
+
instrum.append(
|
26
|
+
ng.p.Log(init=None,
|
27
|
+
exponent=space.base,
|
28
|
+
lower=space.low,
|
29
|
+
upper=space.high))
|
30
|
+
else:
|
31
|
+
instrum.append(
|
32
|
+
ng.p.Scalar(init=None,
|
33
|
+
lower=space.low,
|
34
|
+
upper=space.high))
|
35
|
+
self.instrum = ng.p.Instrumentation(*instrum)
|
36
|
+
self.opt = getattr(ng.optimizers,
|
37
|
+
self.config['method'])(self.instrum,
|
38
|
+
budget=self.config['budget'])
|
39
|
+
|
40
|
+
def suggest(self, *suggested):
|
41
|
+
suggested = [
|
42
|
+
space.transform(x) for x, space in zip(suggested, self.dimensions)
|
43
|
+
]
|
44
|
+
self.opt.suggest(*suggested)
|
45
|
+
|
46
|
+
def ask(self):
|
47
|
+
tmp = self.opt.ask()
|
48
|
+
return [
|
49
|
+
space.inverse_transform(x)
|
50
|
+
for x, space in zip(tmp.args, self.dimensions)
|
51
|
+
]
|
52
|
+
|
53
|
+
def tell(self, suggested: Sequence, value: Any):
|
54
|
+
self._all_x.append(suggested)
|
55
|
+
self._all_y.append(value)
|
56
|
+
suggested = tuple([
|
57
|
+
space.transform(x) for x, space in zip(suggested, self.dimensions)
|
58
|
+
])
|
59
|
+
# self.opt.suggest(*suggested)
|
60
|
+
# x = self.opt.ask()
|
61
|
+
x = self.instrum.spawn_child(new_value=(suggested, {}))
|
62
|
+
self.opt.tell(x, value)
|
63
|
+
|
64
|
+
def get_result(self, history: bool = False) -> OptimizeResult:
|
65
|
+
recommendation = self.opt.provide_recommendation()
|
66
|
+
ret = OptimizeResult({
|
67
|
+
'x': [
|
68
|
+
space.inverse_transform(x)
|
69
|
+
for x, space in zip(recommendation.args, self.dimensions)
|
70
|
+
]
|
71
|
+
})
|
72
|
+
if history:
|
73
|
+
ret.x_iters = self._all_x
|
74
|
+
ret.func_vals = self._all_y
|
75
|
+
# ret.fun = recommendation.value
|
76
|
+
return ret
|