QuLab 2.9.5__cp310-cp310-macosx_10_9_universal2.whl → 2.9.7__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.
qulab/cli/commands.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import click
2
2
 
3
- from ..executor.cli import create, get, maintain, run, set
3
+ from ..executor.cli import create, get, maintain, reproduce, run, set
4
4
  from ..monitor.__main__ import main as monitor
5
5
  from ..scan.server import server
6
6
  from ..sys.net.cli import dht
@@ -24,6 +24,7 @@ cli.add_command(dht)
24
24
  cli.add_command(server)
25
25
  cli.add_command(maintain)
26
26
  cli.add_command(run)
27
+ cli.add_command(reproduce)
27
28
  cli.add_command(create)
28
29
  cli.add_command(set)
29
30
  cli.add_command(get)
qulab/executor/cli.py CHANGED
@@ -126,7 +126,8 @@ def set(key, value, api):
126
126
  from . import transform
127
127
  if api is not None:
128
128
  api = importlib.import_module(api)
129
- set_config_api(api.query_config, api.update_config, api.export_config)
129
+ set_config_api(api.query_config, api.update_config, api.delete_config,
130
+ api.export_config, api.clear_config)
130
131
  try:
131
132
  value = eval(value)
132
133
  except:
@@ -148,7 +149,8 @@ def get(key, api):
148
149
  from . import transform
149
150
  if api is not None:
150
151
  api = importlib.import_module(api)
151
- set_config_api(api.query_config, api.update_config, api.export_config)
152
+ set_config_api(api.query_config, api.update_config, api.delete_config,
153
+ api.export_config, api.clear_config)
152
154
  click.echo(transform.query_config(key))
153
155
 
154
156
 
@@ -184,7 +186,8 @@ def run(workflow, code, data, api, plot, no_dependents, retry, freeze):
184
186
  f'{" --freeze " if freeze else ""}')
185
187
  if api is not None:
186
188
  api = importlib.import_module(api)
187
- set_config_api(api.query_config, api.update_config, api.export_config)
189
+ set_config_api(api.query_config, api.update_config, api.delete_config,
190
+ api.export_config, api.clear_config)
188
191
  if code is None:
189
192
  code = Path.cwd()
190
193
  if data is None:
@@ -255,7 +258,8 @@ def maintain(workflow, code, data, api, retry, plot):
255
258
  f'{" --plot" if plot else ""}')
256
259
  if api is not None:
257
260
  api = importlib.import_module(api)
258
- set_config_api(api.query_config, api.update_config, api.export_config)
261
+ set_config_api(api.query_config, api.update_config, api.delete_config,
262
+ api.export_config, api.clear_config)
259
263
  if code is None:
260
264
  code = Path.cwd()
261
265
  if data is None:
@@ -290,3 +294,47 @@ def maintain(workflow, code, data, api, retry, plot):
290
294
  raise e
291
295
  logger.warning(f'Calibration failed, retrying ({i + 1}/{retry})')
292
296
  continue
297
+
298
+
299
+ @click.command()
300
+ @click.argument('report_id')
301
+ @click.option('--plot', '-p', is_flag=True, help='Plot the report.')
302
+ @log_options
303
+ @command_option('reproduce')
304
+ def reproduce(report_id, code, data, api, plot):
305
+ """
306
+ Reproduce a report.
307
+
308
+ If `--plot` is set, plot the report.
309
+ If `--api` is set, use the api to get and update the config table.
310
+ If `--code` is not set, use the current working directory.
311
+ If `--data` is not set, use the `logs` directory in the code path.
312
+ """
313
+ logger.info(
314
+ f'[CMD]: reproduce {report_id} --code {code} --data {data} --api {api}'
315
+ f'{" --plot" if plot else ""}')
316
+ if api is not None:
317
+ api = importlib.import_module(api)
318
+ set_config_api(api.query_config, api.update_config, api.delete_config,
319
+ api.export_config, api.clear_config)
320
+ if code is None:
321
+ code = Path.cwd()
322
+ if data is None:
323
+ data = Path(code) / 'logs'
324
+
325
+ code = Path(os.path.expanduser(code))
326
+ data = Path(os.path.expanduser(data))
327
+
328
+ from . import transform
329
+ from .load import load_workflow_from_source_code
330
+ from .storage import get_report_by_index
331
+
332
+ r = get_report_by_index(int(report_id), data)
333
+
334
+ wf = load_workflow_from_source_code(r.workflow, r.script)
335
+ cfg = transform.export_config()
336
+ transform.clear_config()
337
+ transform.update_config(r.config)
338
+ run_workflow(wf, code, data, plot=plot, freeze=True)
339
+ transform.clear_config()
340
+ transform.update_config(cfg)
qulab/executor/load.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import graphlib
2
2
  import inspect
3
3
  import pickle
4
+ import sys
4
5
  import warnings
5
6
  from importlib.util import module_from_spec, spec_from_file_location
6
7
  from pathlib import Path
@@ -329,6 +330,34 @@ def load_workflow_from_file(file_name: str,
329
330
  return module
330
331
 
331
332
 
333
+ def load_workflow_from_source_code(workflow_id: str,
334
+ source_code: str,
335
+ package='workflows') -> WorkflowType:
336
+ path = Path(workflow_id)
337
+ module_name = f"{package}.{'.'.join([*path.parts[:-1], path.stem])}"
338
+
339
+ # 创建一个新的模块对象
340
+ module = ModuleType(module_name)
341
+ # 将模块注册到sys.modules中
342
+ sys.modules[module_name] = module
343
+ # 将源代码编译成字节码
344
+ code = compile(source_code, '<string>', 'exec')
345
+ # 在模块的命名空间中执行字节码
346
+ exec(code, module.__dict__)
347
+
348
+ module.__source__ = source_code
349
+ module.__mtime__ = 0
350
+ module.__workflow_id__ = workflow_id
351
+
352
+ if not hasattr(module, '__timeout__'):
353
+ module.__timeout__ = None
354
+
355
+ if not hasattr(module, 'depends'):
356
+ module.depends = lambda: []
357
+
358
+ return module
359
+
360
+
332
361
  def _generate_target_file_path(template_path: str | Path, hash_str: str,
333
362
  content: str, base_path: str | Path) -> Path:
334
363
  path = Path(template_path)
@@ -31,6 +31,22 @@ def _update_config(updates):
31
31
  pickle.dump(parameters, f)
32
32
 
33
33
 
34
+ def _delete_config(name: str):
35
+ import pickle
36
+
37
+ try:
38
+ with open('parameters.pkl', 'rb') as f:
39
+ parameters = pickle.load(f)
40
+ except:
41
+ parameters = {}
42
+
43
+ if name in parameters:
44
+ del parameters[name]
45
+
46
+ with open('parameters.pkl', 'wb') as f:
47
+ pickle.dump(parameters, f)
48
+
49
+
34
50
  def _export_config() -> dict:
35
51
  import pickle
36
52
 
@@ -43,6 +59,21 @@ def _export_config() -> dict:
43
59
  return parameters
44
60
 
45
61
 
62
+ def _clear_config():
63
+ import pickle
64
+
65
+ try:
66
+ with open('parameters.pkl', 'rb') as f:
67
+ parameters = pickle.load(f)
68
+ except:
69
+ parameters = {}
70
+
71
+ parameters.clear()
72
+
73
+ with open('parameters.pkl', 'wb') as f:
74
+ pickle.dump(parameters, f)
75
+
76
+
46
77
  def obey_the_oracle(report: Report, data_path):
47
78
  global __current_config_id
48
79
  update_config(report.oracle)
@@ -67,10 +98,16 @@ def current_config(data_path):
67
98
 
68
99
  query_config = _query_config
69
100
  update_config = _update_config
101
+ delete_config = _delete_config
70
102
  export_config = _export_config
103
+ clear_config = _clear_config
71
104
 
72
105
 
73
- def set_config_api(query_method, update_method, export_method):
106
+ def set_config_api(query_method,
107
+ update_method,
108
+ delete_method,
109
+ export_method,
110
+ clear_method=None):
74
111
  """
75
112
  Set the query and update methods for the config.
76
113
 
@@ -79,13 +116,19 @@ def set_config_api(query_method, update_method, export_method):
79
116
  the method should take a key and return the value.
80
117
  update_method: The update method.
81
118
  the method should take a dict of updates.
119
+ delete_method: The delete method.
120
+ the method should take a key and delete it.
82
121
  export_method: The export method.
83
122
  the method should return a dict of the config.
123
+ clear_method: The clear method.
124
+ the method should clear the config.
84
125
  """
85
- global query_config, update_config, export_config
126
+ global query_config, update_config, delete_config, export_config, clear_config
86
127
 
87
128
  query_config = query_method
88
129
  update_config = update_method
130
+ delete_config = delete_method
89
131
  export_config = export_method
132
+ clear_config = clear_method
90
133
 
91
- return query_config, update_config, export_config
134
+ return query_config, update_config, delete_config, export_config, clear_config
Binary file
qulab/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2.9.5"
1
+ __version__ = "2.9.7"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: QuLab
3
- Version: 2.9.5
3
+ Version: 2.9.7
4
4
  Summary: contral instruments and manage data
5
5
  Author-email: feihoo87 <feihoo87@gmail.com>
6
6
  Maintainer-email: feihoo87 <feihoo87@gmail.com>
@@ -1,20 +1,20 @@
1
1
  qulab/__init__.py,sha256=JZ3bn_kTVlnY-P8JXQ5xEdViieFXqfxX8ReLuiiXIpo,321
2
2
  qulab/__main__.py,sha256=fjaRSL_uUjNIzBGNgjlGswb9TJ2VD5qnkZHW3hItrD4,68
3
3
  qulab/dicttree.py,sha256=tRRMpGZYVOLw0TEByE3_2Ss8FdOmzuGL9e1DWbs8qoY,13684
4
- qulab/fun.cpython-310-darwin.so,sha256=0oZlyaFkXVaQlIiEJZpziCS0EAx4eUCqlrnZj5RuqR0,126864
4
+ qulab/fun.cpython-310-darwin.so,sha256=VrUlHJ1pFO5oNrnp2dTPjzK0QA-z2vCrZbhevORa26o,126864
5
5
  qulab/typing.py,sha256=vg62sGqxuD9CI5677ejlzAmf2fVdAESZCQjAE_xSxPg,69
6
6
  qulab/utils.py,sha256=BdLdlfjpe6m6gSeONYmpAKTTqxDaYHNk4exlz8kZxTg,2982
7
- qulab/version.py,sha256=w1TrLnI1WG1RnKU5vN73-FD1f7CJlGfGd4-SplmrIUE,21
7
+ qulab/version.py,sha256=YMyATiSQWC8XaFTG2e9YghQWC6WcAk1_57Et_fYwGVs,21
8
8
  qulab/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- qulab/cli/commands.py,sha256=tgDIkkeIoasQXAifJZ6NU8jDgpNgb2a-B0C4nF0evrE,559
9
+ qulab/cli/commands.py,sha256=F1LATmSC9lOAdnrOTMK7DRjETCEcOmMsocovWRyjWTc,597
10
10
  qulab/cli/config.py,sha256=Ei7eSYnbwPPlluDnm8YmWONYiI4g7WtvlZGQdr1Z6vo,3688
11
11
  qulab/executor/__init__.py,sha256=LosPzOMaljSZY1thy_Fxtbrgq7uubJszMABEB7oM7tU,101
12
- qulab/executor/cli.py,sha256=8d-8bRWZ5lmsMtjASsl1zu1rV-syeAESMNVthvIQxlo,10018
13
- qulab/executor/load.py,sha256=GBd0FZHO7kLvwzcXAnChStgeaMKJBNVjUi_Yh43PABA,17736
12
+ qulab/executor/cli.py,sha256=xceK6XNLnNpAVtqvs0_wOAuG0sgS9jg1iTFYmxVUMWY,11795
13
+ qulab/executor/load.py,sha256=qI-3b3xvsjZMCthRO3hlzHA0BZI-tH9Y_L0XLBcyWV8,18657
14
14
  qulab/executor/schedule.py,sha256=XRimchHYCgnMAOtCvNLjwMv9IkcTAyBAUCHKQs5RBRw,18745
15
15
  qulab/executor/storage.py,sha256=PWQIDYjQaoyLGgAKh0X1tlNQTgDWR8bI-HVie4hSkyA,21075
16
16
  qulab/executor/template.py,sha256=_HEtsUQ5_jSujCw8FBDAK1PRTMRCa4iD4DduHIpjo3c,10569
17
- qulab/executor/transform.py,sha256=ABrnD0l53NI2y2e8ETYO7lmqGtyiE6EAY965kFRqme0,2311
17
+ qulab/executor/transform.py,sha256=rk4CLIKVjGRaFzi5FVSgadUxAKKVLSopEHZCaAzDwDg,3435
18
18
  qulab/executor/utils.py,sha256=l_b0y2kMwYKyyXeFtoblPYwKNU-wiFQ9PMo9QlWl9wE,6213
19
19
  qulab/monitor/__init__.py,sha256=nTHelnDpxRS_fl_B38TsN0njgq8eVTEz9IAnN3NbDlM,42
20
20
  qulab/monitor/__main__.py,sha256=w3yUcqq195LzSnXTkQcuC1RSFRhy4oQ_PEBmucXguME,97
@@ -97,9 +97,9 @@ qulab/visualization/plot_seq.py,sha256=UWTS6p9nfX_7B8ehcYo6UnSTUCjkBsNU9jiOeW2ca
97
97
  qulab/visualization/qdat.py,sha256=ZeevBYWkzbww4xZnsjHhw7wRorJCBzbG0iEu-XQB4EA,5735
98
98
  qulab/visualization/rot3d.py,sha256=lMrEJlRLwYe6NMBlGkKYpp_V9CTipOAuDy6QW_cQK00,734
99
99
  qulab/visualization/widgets.py,sha256=6KkiTyQ8J-ei70LbPQZAK35wjktY47w2IveOa682ftA,3180
100
- qulab-2.9.5.dist-info/licenses/LICENSE,sha256=PRzIKxZtpQcH7whTG6Egvzl1A0BvnSf30tmR2X2KrpA,1065
101
- qulab-2.9.5.dist-info/METADATA,sha256=xn8Dpztq6tzs5vOqrGhRlFyHAUYdO1PRY-3R3jSKtqo,3720
102
- qulab-2.9.5.dist-info/WHEEL,sha256=qnIvK8L8kOW9FTrzifubcmNsZckgNfGDNKzGG7FMEdE,114
103
- qulab-2.9.5.dist-info/entry_points.txt,sha256=b0v1GXOwmxY-nCCsPN_rHZZvY9CtTbWqrGj8u1m8yHo,45
104
- qulab-2.9.5.dist-info/top_level.txt,sha256=3T886LbAsbvjonu_TDdmgxKYUn939BVTRPxPl9r4cEg,6
105
- qulab-2.9.5.dist-info/RECORD,,
100
+ qulab-2.9.7.dist-info/licenses/LICENSE,sha256=PRzIKxZtpQcH7whTG6Egvzl1A0BvnSf30tmR2X2KrpA,1065
101
+ qulab-2.9.7.dist-info/METADATA,sha256=R4asNQDngbtrmIQiaHPnNBGubf76IoqxnODjnKx8GEw,3720
102
+ qulab-2.9.7.dist-info/WHEEL,sha256=qnIvK8L8kOW9FTrzifubcmNsZckgNfGDNKzGG7FMEdE,114
103
+ qulab-2.9.7.dist-info/entry_points.txt,sha256=b0v1GXOwmxY-nCCsPN_rHZZvY9CtTbWqrGj8u1m8yHo,45
104
+ qulab-2.9.7.dist-info/top_level.txt,sha256=3T886LbAsbvjonu_TDdmgxKYUn939BVTRPxPl9r4cEg,6
105
+ qulab-2.9.7.dist-info/RECORD,,
File without changes