7
7
from SpheralCompiledPackages import *
8
8
9
9
from SpheralTestUtilities import globalFrame
10
- from SpheralUtilities import TimerMgr
10
+ import SpheralTimingParser
11
+
12
+ def parse_value (value ):
13
+ gd = globalFrame ().f_globals
14
+ try :
15
+ return eval (value , gd )
16
+ except :
17
+ return value
11
18
12
19
def commandLine (** options ):
13
20
14
21
# Build a command line parser with the keyword arguments passed to us.
15
22
parser = argparse .ArgumentParser ()
16
- for key in options :
17
- parser .add_argument ("--" + key ,
18
- dest = key ,
19
- default = options [key ])
23
+ for key , default in options .items ():
24
+ if default == "None" :
25
+ raise SyntaxError (f"ERROR: { key } , None as a default value cannot be a string" )
26
+ elif type (default ) is str :
27
+ parser .add_argument (f"--{ key } " , type = str , default = default )
28
+ else :
29
+ parser .add_argument (f"--{ key } " , type = parse_value , default = default )
20
30
21
31
# Add the universal options supported by all Spheral++ scripts.
22
32
parser .add_argument ("-v" , "--verbose" ,
23
33
action = "store_true" ,
24
34
dest = "verbose" ,
25
35
default = False ,
26
36
help = "Verbose output -- print all options that were set." )
27
- parser .add_argument ("--caliperConfig" , default = "" , type = str )
28
- parser .add_argument ("--caliperFilename" , default = "" , type = str )
29
- parser .add_argument ("--caliperConfigJSON" , default = "" , type = str )
37
+
38
+ # Parse Caliper and Adiak inputs
39
+ SpheralTimingParser .add_timing_args (parser )
40
+
30
41
# Evaluate the command line.
31
42
args = parser .parse_args ()
32
43
arg_dict = vars (args )
33
44
34
- if (not TimerMgr .timers_usable ()):
35
- if (args .caliperConfig or args .caliperFilename or args .caliperConfigJSON ):
36
- print ("WARNING: Caliper command line inputs provided for " + \
37
- "non-timer install. Reconfigure the install with " + \
38
- "-DENABLE_TIMER=ON to be able to use Caliper timers." )
39
-
40
45
# Verbose output?
41
46
if args .verbose :
42
47
print ("All parameters set:" )
@@ -46,46 +51,12 @@ def commandLine(**options):
46
51
print (" * " , key , " = " , val )
47
52
else :
48
53
print (" " , key , " = " , val )
49
- if (args .caliperConfig ):
50
- print (" * caliperConfig = " , args .caliperConfig )
51
- if (args .caliperFilename ):
52
- print (" * caliperFilename = " , args .caliperFilename )
53
- if (args .caliperConfigJSON ):
54
- print (" * caliperConfigJSON = " , args .caliperConfigJSON )
55
54
# Set all the variables.
56
55
gd = globalFrame ().f_globals
57
56
for key , val in arg_dict .items ():
58
- if key in options :
59
- if (type (val ) != type (options [key ])):
60
- val = eval (val , gd )
57
+ if val == "None" :
58
+ val = None
61
59
gd [key ] = val
62
- # Initialize timers
63
- InitTimers (args .caliperConfig , args .caliperFilename , args .caliperConfigJSON )
64
- return
65
-
66
- def InitTimers (caliper_config , filename , caliper_json ):
67
- if (caliper_json ):
68
- TimerMgr .load (caliper_json )
69
- if (not caliper_config ):
70
- raise RuntimeError ("SpheralOptionParser: specifying a configuration file without using one of the configurations means no timers are started" )
71
- off_tests = ["none" , "off" , "disable" , "disabled" , "0" ]
72
- if (caliper_config .lower () in off_tests ):
73
- return
74
- elif (caliper_config ):
75
- TimerMgr .add (caliper_config )
76
- TimerMgr .start ()
77
- else :
78
- import os , sys
79
- if (filename ):
80
- testname = filename
81
- else :
82
- from datetime import datetime
83
- # Append the current day and time to the filename
84
- unique_digits = datetime .now ().strftime ("_%Y_%m_%d_%H%M%S_%f" )
85
- # Name file based on name of python file being run
86
- testname = os .path .splitext (os .path .basename (sys .argv [0 ]))[0 ]
87
- testname += unique_digits + ".cali"
88
- TimerMgr .default_start (testname )
89
- adiak_valueInt ("threads_per_rank" , omp_get_num_threads ())
90
- adiak_valueInt ("num_ranks" , mpi .procs )
60
+ # Initialize timers and add inputs as Adiak metadata
61
+ SpheralTimingParser .init_timer (args )
91
62
return
0 commit comments