forked from PPPLDeepLearning/plasma-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconf_parser.py
More file actions
252 lines (218 loc) · 16 KB
/
conf_parser.py
File metadata and controls
252 lines (218 loc) · 16 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import plasma.models.targets as t
from plasma.primitives.shots import ShotListFiles
from data.signals import *
import getpass
import uuid
import yaml
import hashlib
def parameters(input_file):
"""Parse yaml file of configuration parameters."""
with open(input_file, 'r') as yaml_file:
params = yaml.load(yaml_file)
params['user_name'] = getpass.getuser()
output_path = params['fs_path'] + "/" + params['user_name']
base_path = output_path
params['paths']['base_path'] = base_path
params['paths']['signal_prepath'] = base_path + params['paths']['signal_prepath']
params['paths']['shot_list_dir'] = base_path + params['paths']['shot_list_dir']
params['paths']['output_path'] = output_path
h = get_unique_signal_hash(all_signals.values())
params['paths']['global_normalizer_path'] = output_path + '/normalization/normalization_signal_group_{}.npz'.format(h)
if params['training']['hyperparam_tuning']:
# params['paths']['saved_shotlist_path'] = './normalization/shot_lists.npz'
params['paths']['normalizer_path'] = './normalization/normalization_signal_group_{}.npz'.format(h)
params['paths']['model_save_path'] = './model_checkpoints/'
params['paths']['csvlog_save_path'] = './csv_logs/'
params['paths']['results_prepath'] = './results/'
else:
# params['paths']['saved_shotlist_path'] = output_path +'/normalization/shot_lists.npz'
params['paths']['normalizer_path'] = params['paths']['global_normalizer_path']
params['paths']['model_save_path'] = output_path + '/model_checkpoints/'
params['paths']['csvlog_save_path'] = output_path + '/csv_logs/'
params['paths']['results_prepath'] = output_path + '/results/'
params['paths']['tensorboard_save_path'] = output_path + params['paths']['tensorboard_save_path']
params['paths']['saved_shotlist_path'] = params['paths']['base_path'] + '/processed_shotlists/' + params['paths']['data'] + '/shot_lists_signal_group_{}.npz'.format(h)
params['paths']['processed_prepath'] = output_path +'/processed_shots/' + 'signal_group_{}/'.format(h)
#ensure shallow model has +1 -1 target.
if params['model']['shallow'] or params['target'] == 'hinge':
params['data']['target'] = t.HingeTarget
elif params['target'] == 'maxhinge':
t.MaxHingeTarget.fac = params['data']['positive_example_penalty']
params['data']['target'] = t.MaxHingeTarget
elif params['target'] == 'binary':
params['data']['target'] = t.BinaryTarget
elif params['target'] == 'ttd':
params['data']['target'] = t.TTDTarget
elif params['target'] == 'ttdinv':
params['data']['target'] = t.TTDInvTarget
elif params['target'] == 'ttdlinear':
params['data']['target'] = t.TTDLinearTarget
else:
print('Unkown type of target. Exiting')
exit(1)
#params['model']['output_activation'] = params['data']['target'].activation
#binary crossentropy performs slightly better?
#params['model']['loss'] = params['data']['target'].loss
#signals
params['paths']['all_signals_dict'] = all_signals
#assert order q95,li,ip,lm,betan,energy,dens,pradcore,pradedge,pin,pechin,torquein,ipdirect,etemp_profile,edens_profile
#shot lists
jet_carbon_wall = ShotListFiles(jet,params['paths']['shot_list_dir'],['CWall_clear.txt','CFC_unint.txt'],'jet carbon wall data')
jet_iterlike_wall = ShotListFiles(jet,params['paths']['shot_list_dir'],['ILW_unint.txt','BeWall_clear.txt'],'jet iter like wall data')
jet_iterlike_wall_late = ShotListFiles(jet,params['paths']['shot_list_dir'],['ILW_unint_late.txt','ILW_clear_late.txt'],'Late jet iter like wall data')
jet_iterlike_wall_full = ShotListFiles(jet,params['paths']['shot_list_dir'],['ILW_unint_full.txt','ILW_clear_full.txt'],'Full jet iter like wall data')
jenkins_jet_carbon_wall = ShotListFiles(jet,params['paths']['shot_list_dir'],['jenkins_CWall_clear.txt','jenkins_CFC_unint.txt'],'Subset of jet carbon wall data for Jenkins tests')
jenkins_jet_iterlike_wall = ShotListFiles(jet,params['paths']['shot_list_dir'],['jenkins_ILW_unint.txt','jenkins_BeWall_clear.txt'],'Subset of jet iter like wall data for Jenkins tests')
jet_full = ShotListFiles(jet,params['paths']['shot_list_dir'],['ILW_unint.txt','BeWall_clear.txt','CWall_clear.txt','CFC_unint.txt'],'jet full data')
d3d_10000 = ShotListFiles(d3d,params['paths']['shot_list_dir'],['d3d_clear_10000.txt','d3d_disrupt_10000.txt'],'d3d data 10000 ND and D shots')
d3d_1000 = ShotListFiles(d3d,params['paths']['shot_list_dir'],['d3d_clear_1000.txt','d3d_disrupt_1000.txt'],'d3d data 1000 ND and D shots')
d3d_100 = ShotListFiles(d3d,params['paths']['shot_list_dir'],['d3d_clear_100.txt','d3d_disrupt_100.txt'],'d3d data 100 ND and D shots')
d3d_full = ShotListFiles(d3d,params['paths']['shot_list_dir'],['d3d_clear_data_avail.txt','d3d_disrupt_data_avail.txt'],'d3d data since shot 125500')
d3d_jenkins = ShotListFiles(d3d,params['paths']['shot_list_dir'],['jenkins_d3d_clear.txt','jenkins_d3d_disrupt.txt'],'Subset of d3d data for Jenkins test')
d3d_jb_full = ShotListFiles(d3d,params['paths']['shot_list_dir'],['shotlist_JaysonBarr_clear.txt','shotlist_JaysonBarr_disrupt.txt'],'d3d shots since 160000-170000')
nstx_full = ShotListFiles(nstx,params['paths']['shot_list_dir'],['disrupt_nstx.txt'],'nstx shots (all are disruptive')
if params['paths']['data'] == 'jet_data':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = jet_signals
elif params['paths']['data'] == 'jet_data_0D':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = jet_signals_0D
elif params['paths']['data'] == 'jet_data_1D':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = jet_signals_1D
elif params['paths']['data'] == 'jet_data_late':
params['paths']['shot_files'] = [jet_iterlike_wall_late]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = jet_signals
elif params['paths']['data'] == 'jet_data_carbon_to_late_0D':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall_late]
params['paths']['use_signals_dict'] = jet_signals_0D
elif params['paths']['data'] == 'jet_data_temp_profile':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = {'etemp_profile' : etemp_profile}
elif params['paths']['data'] == 'jet_data_dens_profile':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = {'edens_profile' : edens_profile}
elif params['paths']['data'] == 'jet_carbon_data':
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = jet_signals
elif params['paths']['data'] == 'jet_mixed_data':
params['paths']['shot_files'] = [jet_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = jet_signals
elif params['paths']['data'] == 'jenkins_jet':
params['paths']['shot_files'] = [jenkins_jet_carbon_wall]
params['paths']['shot_files_test'] = [jenkins_jet_iterlike_wall]
params['paths']['use_signals_dict'] = jet_signals
elif params['paths']['data'] == 'jet_data_fully_defined': #jet data but with fully defined signals
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = fully_defined_signals
elif params['paths']['data'] == 'jet_data_fully_defined_0D': #jet data but with fully defined signals
params['paths']['shot_files'] = [jet_carbon_wall]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = fully_defined_signals_0D
elif params['paths']['data'] == 'd3d_data':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'q95':q95,'li':li,'ip':ip,'lm':lm,'betan':betan,'energy':energy,'dens':dens,'pradcore':pradcore,'pradedge':pradedge,'pin':pin,'torquein':torquein,'ipdirect':ipdirect,'iptarget':iptarget,'iperr':iperr,
'etemp_profile':etemp_profile ,'edens_profile':edens_profile}
elif params['paths']['data'] == 'd3d_data_1D':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'ipdirect':ipdirect,'etemp_profile':etemp_profile ,'edens_profile':edens_profile}
elif params['paths']['data'] == 'd3d_data_all_profiles':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'ipdirect':ipdirect,'etemp_profile':etemp_profile ,'edens_profile':edens_profile,'itemp_profile':itemp_profile,'zdens_profile':zdens_profile,'trot_profile':trot_profile,'pthm_profile':pthm_profile,'neut_profile':neut_profile,'q_profile':q_profile,'bootstrap_current_profile':bootstrap_current_profile,'q_psi_profile':q_psi_profile}
elif params['paths']['data'] == 'd3d_data_0D':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'q95':q95,'li':li,'ip':ip,'lm':lm,'betan':betan,'energy':energy,'dens':dens,'pradcore':pradcore,'pradedge':pradedge,'pin':pin,'torquein':torquein,'ipdirect':ipdirect,'iptarget':iptarget,'iperr':iperr}
elif params['paths']['data'] == 'd3d_data_all':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = d3d_signals
elif params['paths']['data'] == 'jenkins_d3d':
params['paths']['shot_files'] = [d3d_jenkins]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'q95':q95,'li':li,'ip':ip,'lm':lm,'betan':betan,'energy':energy,'dens':dens,'pradcore':pradcore,'pradedge':pradedge,'pin':pin,'torquein':torquein,'ipdirect':ipdirect,'iptarget':iptarget,'iperr':iperr,
'etemp_profile':etemp_profile ,'edens_profile':edens_profile}
elif params['paths']['data'] == 'd3d_data_fully_defined': #jet data but with fully defined signals
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = fully_defined_signals
elif params['paths']['data'] == 'd3d_data_fully_defined_0D': #jet data but with fully defined signals
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = fully_defined_signals_0D
elif params['paths']['data'] == 'd3d_data_temp_profile': #jet data but with fully defined signals
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'etemp_profile' : etemp_profile}#fully_defined_signals_0D
elif params['paths']['data'] == 'd3d_data_dens_profile': #jet data but with fully defined signals
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = []
params['paths']['use_signals_dict'] = {'edens_profile' : edens_profile}#fully_defined_signals_0D
#cross-machine
elif params['paths']['data'] == 'jet_to_d3d_data':
params['paths']['shot_files'] = [jet_full]
params['paths']['shot_files_test'] = [d3d_full]
params['paths']['use_signals_dict'] = fully_defined_signals
elif params['paths']['data'] == 'd3d_to_jet_data':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = fully_defined_signals
elif params['paths']['data'] == 'd3d_to_late_jet_data':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = [jet_iterlike_wall_late]
params['paths']['use_signals_dict'] = fully_defined_signals
elif params['paths']['data'] == 'jet_to_d3d_data_0D':
params['paths']['shot_files'] = [jet_full]
params['paths']['shot_files_test'] = [d3d_full]
params['paths']['use_signals_dict'] = fully_defined_signals_0D
elif params['paths']['data'] == 'd3d_to_jet_data_0D':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = fully_defined_signals_0D
elif params['paths']['data'] == 'jet_to_d3d_data_1D':
params['paths']['shot_files'] = [jet_full]
params['paths']['shot_files_test'] = [d3d_full]
params['paths']['use_signals_dict'] = fully_defined_signals_1D
elif params['paths']['data'] == 'd3d_to_jet_data_1D':
params['paths']['shot_files'] = [d3d_full]
params['paths']['shot_files_test'] = [jet_iterlike_wall]
params['paths']['use_signals_dict'] = fully_defined_signals_1D
else:
print("Unkown data set {}".format(params['paths']['data']))
exit(1)
if len(params['paths']['specific_signals']):
for sig in params['paths']['specific_signals']:
if sig not in params['paths']['use_signals_dict'].keys():
print("Signal {} is not fully defined for {} machine. Skipping...".format(sig,params['paths']['data'].split("_")[0]))
params['paths']['specific_signals'] = list(filter(lambda x: x in params['paths']['use_signals_dict'].keys(), params['paths']['specific_signals']))
selected_signals = {k: params['paths']['use_signals_dict'][k] for k in params['paths']['specific_signals']}
params['paths']['use_signals'] = sort_by_channels(list(selected_signals.values()))
else:
#default case
params['paths']['use_signals'] = sort_by_channels(list(params['paths']['use_signals_dict'].values()))
params['paths']['all_signals'] = sort_by_channels(list(params['paths']['all_signals_dict'].values()))
print("Selected signals (determines which signals training is run on):\n{}".format(params['paths']['use_signals']))
params['paths']['shot_files_all'] = params['paths']['shot_files']+params['paths']['shot_files_test']
params['paths']['all_machines'] = list(set([file.machine for file in params['paths']['shot_files_all']]))
#type assertations
assert type(params['data']['signal_to_augment']) == str or type(params['data']['signal_to_augment']) == None
assert type(params['data']['augment_during_training']) == bool
return params
def get_unique_signal_hash(signals):
return int(hashlib.md5(''.join(tuple(map(lambda x: "{}".format(x.__hash__()), sorted(signals)))).encode('utf-8')).hexdigest(),16)
#make sure 1D signals come last! This is necessary for model builder.
def sort_by_channels(list_of_signals):
return sorted(list_of_signals,key = lambda x: x.num_channels)