forked from yunshengtian/AutoOED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharguments.py
127 lines (98 loc) · 3.81 KB
/
arguments.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
from argparse import ArgumentParser, Namespace
import yaml
from multiprocessing import cpu_count
'''
Get argument values from command line
Here we speficy different argument parsers to avoid argument conflict between initializing each components
'''
def get_general_args(args=None):
'''
General arguments: problem and algorithm description, experiment settings
'''
parser = ArgumentParser()
parser.add_argument('--problem', type=str, default='DTLZ1',
help='optimization problem')
parser.add_argument('--algo', type=str, default='tsemo',
help='type of algorithm to use with some predefined arguments, or custom arguments')
parser.add_argument('--seed', type=int, default=0,
help='the specific seed to run')
parser.add_argument('--batch-size', type=int, default=10,
help='size of the batch in optimization')
parser.add_argument('--n-init-sample', type=int, default=20,
help='number of initial design samples')
parser.add_argument('--n-total-sample', type=int, default=100,
help='number of total design samples (budget)')
args, _ = parser.parse_known_args(args)
return args
def get_surroagte_args(args=None):
'''
Arguments for fitting the surrogate model
'''
parser = ArgumentParser()
parser.add_argument('--surrogate', type=str,
choices=['gp', 'nn', 'bnn'], default='gp',
help='type of the surrogate model')
args, _ = parser.parse_known_args(args)
return args
def get_acquisition_args(args=None):
'''
Arguments for acquisition function
'''
parser = ArgumentParser()
parser.add_argument('--acquisition', type=str,
choices=['identity', 'pi', 'ei', 'ucb', 'ts'], default='identity',
help='type of the acquisition function')
args, _ = parser.parse_known_args(args)
return args
def get_solver_args(args=None):
'''
Arguments for multi-objective solver
'''
parser = ArgumentParser()
# general solver
parser.add_argument('--solver', type=str,
choices=['nsga2', 'moead', 'parego', 'discovery', 'ga', 'cmaes'], default='nsga2',
help='type of the multiobjective solver')
parser.add_argument('--n-process', type=int, default=cpu_count(),
help='number of processes to be used for parallelization')
args, _ = parser.parse_known_args(args)
return args
def get_selection_args(args=None):
'''
Arguments for sample selection
'''
parser = ArgumentParser()
parser.add_argument('--selection', type=str,
choices=['direct', 'hvi', 'random', 'uncertainty'], default='hvi',
help='type of selection method for new batch')
args, _ = parser.parse_known_args(args)
return args
def get_args():
'''
Get arguments from all components
You can specify args-path argument to directly load arguments from specified yaml file
'''
parser = ArgumentParser()
parser.add_argument('--args-path', type=str, default=None,
help='used for directly loading arguments from path of argument file')
args, _ = parser.parse_known_args()
if args.args_path is None:
general_args = get_general_args()
surroagte_args = get_surroagte_args()
acquisition_args = get_acquisition_args()
solver_args = get_solver_args()
selection_args = get_selection_args()
module_cfg = {
'surrogate': vars(surroagte_args),
'acquisition': vars(acquisition_args),
'solver': vars(solver_args),
'selection': vars(selection_args),
}
else:
with open(args.args_path, 'r') as f:
all_args = yaml.load(f)
general_args = Namespace(**all_args['general'])
module_cfg = all_args.copy()
module_cfg.pop('general')
return general_args, module_cfg