-
Notifications
You must be signed in to change notification settings - Fork 0
/
partitions_to_combischeme.py
executable file
·64 lines (53 loc) · 2.01 KB
/
partitions_to_combischeme.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
#!/usr/bin/env python3
import argparse
import numpy as np
from math import isclose
from icecream import ic
import combischeme_output
import combischeme_utils
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"partitioned_files",
nargs="*",
type=str,
)
parser.add_argument(
"--out_name",
nargs=1,
type=str,
default=None,
)
args = parser.parse_args()
first_scheme = combischeme_utils.CombinationSchemeFromFile(
args.partitioned_files[0])
# divide json-dictionary into assigned partitions
partition_dicts = []
for file in args.partitioned_files:
data = combischeme_output.read_data_from_json(file)
# collect all different process group numbers
group_numbers = set()
try:
for grid in data:
group_numbers.add(grid['group_no'])
if len(group_numbers) > 1:
for group_no in group_numbers:
combination_dictionary = {}
for grid in data:
if grid['group_no'] == group_no:
combination_dictionary[tuple(
grid['level'])] = grid['coeff']
partition_dicts.append(combination_dictionary)
except KeyError:
combination_dictionary = {}
for grid in data:
combination_dictionary[tuple(grid['level'])] = grid['coeff']
partition_dicts.append(combination_dictionary)
partitions = [combischeme_utils.CombinationSchemeFromCombinationDictionary(
dict) for dict in partition_dicts]
assignment = [p.get_combination_dictionary() for p in partitions]
if args.out_name is None:
args.out_name = "combined_"+args.partitioned_files[0]
combischeme_output.write_assignment_to_json(assignment, args.out_name)
# for testing, with checks?
# combined_scheme = combischeme_utils.CombinationSchemeFromPartitions(partitions)