-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path01_generate_initial.py
52 lines (34 loc) · 1.25 KB
/
01_generate_initial.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
from autoax import Config
import argparse
import numpy as np
import uuid
import json, gzip
def generate_initial(config : Config, count : int, seed = None):
res_path = config.block_on_result("random.json.gz")
if seed:
np.random.seed(seed)
print("Possible assignments: ")
possible = 1
for k, library in config.components().items():
p = len(library.possible())
print(f" - {k} (lib: {library}) - {p}")
possible *= p
print("=== Total possible: ", possible)
configs = {}
for i in np.arange(count):
uid = "random_" + str(uuid.uuid4().hex[:6].upper())
r = {}
for k, library in config.components().items():
r[k] = np.random.choice(library.possible())
configs[uid] = r
json.dump(configs, gzip.open(res_path, "wt"), indent=4)
print("Generated ", len(configs), " random configurations to ", res_path)
def main():
p = argparse.ArgumentParser()
p.add_argument('config', help='Config file (yaml)')
p.add_argument('--count', help='Number of random confiurations to generate', default=5000, type=int)
args = p.parse_args()
c = Config(args.config)
generate_initial(c, args.count)
if __name__ == '__main__':
main()