-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgui.py
566 lines (462 loc) · 20 KB
/
gui.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 30 09:24:06 2019
@author: Davide Laghi
Copyright 2021, the JADE Development Team. All rights reserved.
This file is part of JADE.
JADE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JADE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JADE. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
import computational as cmp
import utilitiesgui as uty
import postprocess as pp
import testrun
from tqdm import tqdm
from status import EXP_TAG
date = '27/01/2022'
version = 'v2.0.1'
def clear_screen():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
exit_text = '\nSession concluded normally \n'
header = """
***********************************************
Welcome to JADE """+version+"""
A nuclear libraries V&V Test Suite
Release date: """+date+'\n'
principal_menu = header+"""
MAIN MENU
Powered by NIER, UNIBO, F4E
***********************************************
MAIN FUNCTIONS
* Open Quality check menu (qual)
* Open Computational Benchmark menu (comp)
* Open Experimental Benchmark menu (exp)
* Open Post-Processing menu (post)
-----------------------------------------------
UTILITIES
* Print available libraries (printlib)
* Restore default configurations (restore)
* Translate an MCNP input (trans)
* Print materials info (printmat)
* Generate material (generate)
* Switch fractions (switch)
* Change ACE lib suffix (acelib)
* Produce D1S Reaction file (react)
-----------------------------------------------
* Exit (exit)
"""
def mainloop(session):
"""
This handle the actions related to the main menu
session: (Session) object representing the current Jade session
"""
clear_screen()
print(principal_menu)
while True:
option = input(' Enter action: ')
if option == 'comp':
comploop(session)
elif option == 'exp':
exploop(session)
elif option == 'qual':
clear_screen()
print(principal_menu)
print(' Currently not developed. Please select another option')
elif option == 'post':
pploop(session)
elif option == 'printlib':
uty.print_libraries(session.lib_manager)
elif option == 'restore':
uty.restore_default_config(session)
elif option == 'trans':
newlib = session.lib_manager.select_lib()
inputfile = input(' Input to translate: ')
if newlib in session.lib_manager.libraries:
ans = uty.translate_input(session, newlib, inputfile)
if ans:
print(' Translation successfully completed!\n')
session.log.adjourn('file'+inputfile +
' successfully translated to ' + newlib)
else:
print('''
Error:
The file does not exist or can't be opened
''')
else:
print('''
Error:
The selected library is not available.
Check your available libraries using 'printlib'
''')
elif option == 'printmat':
inputfile = input(' MCNP Input file of interest: ')
ans = uty.print_material_info(session, inputfile)
if ans:
print(' Material infos printed')
else:
print('''
Error:
Either the input or output files do not exist or can't be opened
''')
elif option == 'generate':
inputfile = uty.select_inputfile(' Materials source file: ')
message = " Fraction type (either 'mass' or 'atom'): "
options = ['mass', 'atom']
fraction_type = uty.input_with_options(message, options)
materials = input(' Source materials (e.g. m1-m10): ')
percentages = input(' Materials percentages (e.g. 0.1-0.9): ')
lib = session.lib_manager.select_lib()
materials = materials.split('-')
percentages = percentages.split('-')
if len(materials) == len(percentages):
ans = uty.generate_material(session, inputfile,
materials, percentages, lib,
fractiontype=fraction_type)
if ans:
print(' Material generated')
else:
print('''
Error:
Either the input or output files can't be opened
''')
else:
print('''
Error:
The number of materials and percentages must be the same
''')
elif option == 'switch':
# Select MCNP input
inputfile = uty.select_inputfile(' MCNP input file: ')
# Select fraction type
options = ['mass', 'atom']
message = " Fraction to switch to (either 'mass' or 'atom'): "
fraction_type = uty.input_with_options(message, options)
# Switch fraction
ans = uty.switch_fractions(session, inputfile, fraction_type)
if ans:
print(' Fractions have been switched')
else:
print('''
Error:
Either the input or output files can't be opened''')
elif option == 'acelib':
uty.change_ACElib_suffix()
print('\n Suffix change was completed\n')
elif option == 'react':
uty.get_reaction_file(session)
print('\n Reaction file has been dumped\n')
elif option == 'exit':
session.log.adjourn('\nSession concluded normally \n')
sys.exit()
else:
clear_screen()
print(principal_menu)
print(' Please enter a valid option!')
computational_menu = header+"""
COMPUTATIONAL BENCHMARK MENU
Powered by NIER, UNIBO, F4E
***********************************************
* Print available libraries (printlib)
* Assess library (assess)
* Continue assessment (continue)
* Back to main menu (back)
* Exit (exit)
"""
def comploop(session):
"""
This handle the actions related to the computational benchmarck menu
session: (Session) object representing the current Jade session
"""
clear_screen()
print(computational_menu)
while True:
option = input(' Enter action: ')
if option == 'printlib':
uty.print_libraries(session.lib_manager)
elif option == 'assess':
# Select and check library
lib = session.lib_manager.select_lib()
ans = session.state.check_override_run(lib, session)
# If checks are ok perform assessment
if ans:
# Logging
bartext = 'Computational benchmark execution started'
session.log.bar_adjourn(bartext)
session.log.adjourn('Selected Library: '+lib,
spacing=False, time=True)
print(' ########################### COMPUTATIONAL BENCHMARKS EXECUTION ###########################\n')
cmp.executeBenchmarksRoutines(session, lib) # Core function
print(' ####################### COMPUTATIONAL BENCHMARKS RUN ENDED ###############################\n')
t = 'Computational benchmark execution ended'
session.log.bar_adjourn(t)
else:
clear_screen()
print(computational_menu)
print(' Assessment canceled.')
elif option == 'continue':
# Select and check library
# Warning: this is done only for sphere test at the moment
lib = session.lib_manager.select_lib()
try:
unfinished, motherdir = session.state.get_unfinished_zaids(lib)
except TypeError:
unfinished = None
if unfinished is None:
print(' The selected library was not assessed')
elif len(unfinished) == 0:
print(' The assessment is already completed')
else:
print(' Completing sphere assessment:')
session.log.adjourn('Assessment of: '+lib+' started',
spacing=False, time=True)
flagOk = True
for directory in tqdm(unfinished):
path = os.path.join(motherdir, directory)
name = directory+'_'
flag = testrun.Test._run(name, path, cpu=session.conf.cpu)
if flag:
flagOk = False
session.log.adjourn(name +
' reached timeout, eliminate folder')
if not flagOk:
print("""
Some MCNP run reached timeout, they are listed in the log file.
Please remove their folders before attempting to postprocess the library""")
print(' Assessment completed')
session.log.adjourn('Assessment of: '+lib+' completed',
spacing=True, time=True)
elif option == 'back':
mainloop(session)
elif option == 'exit':
session.log.adjourn(exit_text)
sys.exit()
else:
clear_screen()
print(computational_menu)
print(' Please enter a valid option!')
experimental_menu = header+"""
EXPERIMENTAL BENCHMARK MENU
Powered by NIER, UNIBO, F4E
***********************************************
* Print available libraries (printlib)
* Assess library (assess)
* Continue assessment (continue)
* Back to main menu (back)
* Exit (exit)
"""
def exploop(session):
"""
This handle the actions related to the experimental benchmarck menu
session: (Session) object representing the current Jade session
"""
clear_screen()
print(experimental_menu)
while True:
option = input(' Enter action: ')
if option == 'printlib':
uty.print_libraries(session.lib_manager)
elif option == 'assess':
# Update the configuration file
session.conf.read_settings()
# Select and check library
lib = session.lib_manager.select_lib()
# it may happen that lib are two but only the first is the assessed
pieces = lib.split('-')
if len(pieces) > 1:
libtocheck = pieces[0]
else:
libtocheck = lib
ans = session.state.check_override_run(libtocheck,
session, exp=True)
# If checks are ok perform assessment
if ans:
# Logging
bartext = 'Experimental benchmark execution started'
session.log.bar_adjourn(bartext)
session.log.adjourn('Selected Library: '+lib,
spacing=False, time=True)
print(' ########################### EXPERIMENTAL BENCHMARKS EXECUTION ###########################\n')
# Core function
cmp.executeBenchmarksRoutines(session, lib, exp=True)
print(' ####################### EXPERIMENTAL BENCHMARKS RUN ENDED ###############################\n')
t = 'Experimental benchmark execution ended'
session.log.bar_adjourn(t)
else:
clear_screen()
print(computational_menu)
print(' Assessment canceled.')
elif option == 'continue':
# Update the configuration file
session.conf.read_settings()
clear_screen()
print(principal_menu)
print(' Currently not developed. Please select another option')
elif option == 'back':
mainloop(session)
elif option == 'exit':
session.log.adjourn(exit_text)
sys.exit()
else:
clear_screen()
print(computational_menu)
print(' Please enter a valid option!')
pp_menu = header+"""
POST PROCESSING MENU
Powered by NIER, UNIBO, F4E
***********************************************
* Print tested libraries (printlib)
* Post-Process library (pp)
* Compare libraries (compare)
* Compare Vs Experiments (compexp)
* Back to main menu (back)
* Exit (exit)
"""
def pploop(session):
"""
This handle the actions related to the post-processing menu
session: (Session) object representing the current Jade session
"""
clear_screen()
print(pp_menu)
while True:
option = input(' Enter action: ')
if option == 'printlib':
lib_tested = list(session.state.run_tree.keys())
print(lib_tested)
elif option == 'pp':
# Update the configuration file
session.conf.read_settings()
# Select and check library
ans, to_single_pp, lib_input = session.state.check_override_pp(session)
# If checks are ok perform assessment
if ans:
lib = to_single_pp[0]
# Check active tests
to_perform = session.check_active_tests('Post-Processing')
# For the moment no pp is foreseen for experimental benchmarks
# to_perf_exp = session.check_active_tests('Post-Processing',
# exp=True)
# to_perform.extend(to_perf_exp)
# Logging
bartext = 'Post-Processing started'
session.log.bar_adjourn(bartext)
session.log.adjourn('Selected Library: '+lib, spacing=False)
print('\n ########################### POST-PROCESSING STARTED ###########################\n')
for testname in to_perform:
try:
pp.postprocessBenchmark(session, lib, testname)
except PermissionError as e:
clear_screen()
print(pp_menu)
print(' '+str(e))
print(' Please close all excel/word files and retry')
continue
print('\n ######################### POST-PROCESSING ENDED ###############################\n')
t = 'Post-Processing completed'
session.log.bar_adjourn(t, spacing=False)
elif option == 'compare':
# Update the configuration file
session.conf.read_settings()
# Select and check library
ans, to_single_pp, lib_input = session.state.check_override_pp(session)
if ans:
# Logging
bartext = 'Comparison Post-Processing started'
session.log.bar_adjourn(bartext)
session.log.adjourn('Selected Library: '+lib_input,
spacing=True)
print('\n ########################### COMPARISON STARTED ###########################\n')
# Check active tests
to_perform = session.check_active_tests('Post-Processing')
# Execute single pp
for lib in to_single_pp:
for testname in to_perform:
try:
print(' Single PP of library '+lib+' required')
pp.postprocessBenchmark(session, lib, testname)
session.log.adjourn("""
Additional Post-Processing of library:"""+lib+' completed\n', spacing=False)
except PermissionError as e:
clear_screen()
print(pp_menu)
print(' '+str(e))
print(' Please close all excel/word files and retry')
continue
# Execute Comparison
for testname in to_perform:
try:
pp.compareBenchmark(session, lib_input, testname)
except PermissionError as e:
clear_screen()
print(pp_menu)
print(' '+str(e))
print(' Please close all excel/word files and retry')
continue
print('\n ######################### COMPARISON ENDED ###############################\n')
t = 'Post-Processing completed'
session.log.bar_adjourn(t, spacing=False)
elif option == 'compexp':
# Update the configuration file
session.conf.read_settings()
# Select and check library
ans, to_single_pp, lib_input = session.state.check_override_pp(session, exp=True)
if ans:
# Logging
bartext = 'Comparison Post-Processing started'
session.log.bar_adjourn(bartext)
session.log.adjourn('Selected Library: '+lib_input,
spacing=True)
print('\n ########################### COMPARISON STARTED ###########################\n')
# Check active tests
to_perform = session.check_active_tests('Post-Processing',
exp=True)
# # Execut single pp
# for lib in to_single_pp:
# for testname in to_perform:
# try:
# print(' Single PP of library '+lib+' required')
# pp.postprocessBenchmark(session, lib, testname)
# session.log.adjourn("""
# Additional Post-Processing of library:"""+lib+' completed\n', spacing=False)
# except PermissionError as e:
# clear_screen()
# print(pp_menu)
# print(' '+str(e))
# print(' Please close all excel/word files and retry')
# continue
# Execute Comparison
lib_input = EXP_TAG+'-'+lib_input # Insert the exp tag
for testname in to_perform:
try:
pp.compareBenchmark(session, lib_input, testname)
except PermissionError as e:
clear_screen()
print(pp_menu)
print(' '+str(e))
print(' Please close all excel/word files and retry')
continue
print('\n ######################### COMPARISON ENDED ###############################\n')
t = 'Post-Processing completed'
session.log.bar_adjourn(t, spacing=False)
elif option == 'back':
mainloop(session)
elif option == 'exit':
session.log.adjourn(exit_text)
sys.exit()
else:
clear_screen()
print(pp_menu)
print(' Please enter a valid option!')