-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_version_4a.py
80 lines (59 loc) · 2.52 KB
/
generate_version_4a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Generate a version 4a database file for qcodes' test suite to consume.
Version 4a accidentally serialised the RunDescriber with an InterDependencies_
object instead of an InterDependencies object
"""
import os
import numpy as np
# NB: it's important that we do not import anything from qcodes before we
# do the git magic (which we do below), hence the relative import here
import utils as utils
def generate_DB_file_with_some_runs():
"""
Generate a .db-file with a handful of runs with some interdependent
parameters
"""
# This function will run often on CI and re-generate the .db-files
# That should ideally be a deterministic action
# (although this hopefully plays no role)
np.random.seed(0)
v4afixturepath = os.path.join(utils.fixturepath, 'version4a')
os.makedirs(v4afixturepath, exist_ok=True)
path = os.path.join(v4afixturepath, 'some_runs.db')
if os.path.exists(path):
os.remove(path)
from qcodes.dataset.sqlite_base import connect
from qcodes.dataset.measurements import Measurement
from qcodes.dataset.experiment_container import Experiment
from qcodes import Parameter
connect(path)
exp = Experiment(path_to_db=path,
name='experiment_1',
sample_name='no_sample_1')
# Now make some parameters to use in measurements
params = []
for n in range(5):
params.append(Parameter(f'p{n}', label=f'Parameter {n}',
unit=f'unit {n}', set_cmd=None, get_cmd=None))
# Set up an experiment
meas = Measurement(exp)
meas.register_parameter(params[0])
meas.register_parameter(params[1])
meas.register_parameter(params[2], basis=(params[0],))
meas.register_parameter(params[3], basis=(params[1],))
meas.register_parameter(params[4], setpoints=(params[2], params[3]))
# Make a number of identical runs
for _ in range(10):
with meas.run() as datasaver:
for x in np.random.rand(10):
for y in np.random.rand(10):
z = np.random.rand()
datasaver.add_result((params[0], 0),
(params[1], 1),
(params[2], x),
(params[3], y),
(params[4], z))
if __name__ == '__main__':
gens = (generate_DB_file_with_some_runs,)
# pylint: disable=E1101
utils.checkout_to_old_version_and_run_generators(version='4a', gens=gens)