2
2
3
3
import argparse , textwrap
4
4
import os
5
- parser = argparse .ArgumentParser (description = "ADIOS json file parser step 2 (step 1 is use compare.sh to collect properties from json)" )
6
-
7
- TAGS = {
8
- "input_dir" : "dataDir" , ## key name for input direcory is "dataDir"
9
- "rank" : "whichRank" , ##
10
- "out" : "plotPrefix" , ##
11
- "showfig" : "showFig" , ##
12
- "attr" : "jsonAttr" , ## key refer to specific json attr
13
- "zero" : "zeroIf" , ## key refer to a min number to be treated as 0. Spot the first rank with this value, and only plot up to this rank.
14
- "level" : "levelAxis"
15
- }
16
-
17
- TAGS_DEFAULT = {
18
- "input_dir" : "outs/" , ## key name for input direcory defaults to "outs/"
19
- "rank" : 0 , ##
20
- "out" : "plot" , ##
21
- "showfig" : 'False' , ##
22
- "attr" : "ES" , ## default json attr to look at is ES
23
- "zero" : "0.000001" , ## ignore if smaller than
24
- "level" : 'False' ## whether left/right axises (if both exist) should display same range
25
- }
26
-
27
- parser .add_argument ("ioTypes" ,
28
- nargs = "+" ,
29
- help = "A list of known adios types in the output directory.\n "
30
- "Will be accessed as [" + TAGS ["input_dir" ]+ "]/[ioType]_<secs/nCalls>_[profileTag]"
31
- "e.g. outs/flatten_nCalls_ES" )
32
-
33
- helpWithDefaults = ""
5
+
6
+ parser = argparse .ArgumentParser (
7
+ description = "ADIOS json file parser step 2 (step 1 is use compare.sh to collect properties from json)"
8
+ )
9
+
10
+ TAGS = {
11
+ "input_dir" : "dataDir" , ## key name for input direcory is "dataDir"
12
+ "rank" : "whichRank" , ##
13
+ "out" : "plotPrefix" , ##
14
+ "showfig" : "showFig" , ##
15
+ "attr" : "jsonAttr" , ## key refer to specific json attr
16
+ "zero" : "zeroIf" , ## key refer to a min number to be treated as 0. Spot the first rank with this value, and only plot up to this rank.
17
+ "level" : "levelAxis" ,
18
+ }
19
+
20
+ TAGS_DEFAULT = {
21
+ "input_dir" : "outs/" , ## key name for input direcory defaults to "outs/"
22
+ "rank" : 0 , ##
23
+ "out" : "plot" , ##
24
+ "showfig" : "False" , ##
25
+ "attr" : "ES" , ## default json attr to look at is ES
26
+ "zero" : "0.000001" , ## ignore if smaller than
27
+ "level" : "False" , ## whether left/right axises (if both exist) should display same range
28
+ }
29
+
30
+ parser .add_argument (
31
+ "ioTypes" ,
32
+ nargs = "+" ,
33
+ help = "A list of known adios types in the output directory.\n "
34
+ "Will be accessed as [" + TAGS ["input_dir" ] + "]/[ioType]_<secs/nCalls>_[profileTag]"
35
+ "e.g. outs/flatten_nCalls_ES" ,
36
+ )
37
+
38
+ helpWithDefaults = ""
34
39
for k in TAGS :
35
- helpWithDefaults += TAGS [k ] + "(default: " + str (TAGS_DEFAULT [k ])+ ") "
36
-
37
- parser .add_argument ("--set" ,
38
- metavar = "key=value" ,
39
- nargs = '+' ,
40
- help = "Accepted options:\n " + helpWithDefaults
41
- )
40
+ helpWithDefaults += TAGS [k ] + "(default: " + str (TAGS_DEFAULT [k ]) + ") "
41
+
42
+ parser .add_argument (
43
+ "--set" , metavar = "key=value" , nargs = "+" , help = "Accepted options:\n " + helpWithDefaults
44
+ )
42
45
args = parser .parse_args ()
43
46
44
- #print (args.set)
45
- #print (args.file_key)
47
+ # print (args.set)
48
+ # print (args.file_key)
49
+
46
50
47
51
def parse_var (s ):
48
52
"""
49
53
Parse a key, value pair, separated by '=' into a tuple
50
54
"""
51
- items = s .split ('=' )
52
- key = items [0 ].strip () # we remove blanks around keys, as is logical
55
+ items = s .split ("=" )
56
+ key = items [0 ].strip () # we remove blanks around keys, as is logical
53
57
if len (items ) > 1 :
54
58
# rejoin the rest:
55
- value = '=' .join (items [1 :])
59
+ value = "=" .join (items [1 :])
56
60
return (key , value )
57
61
58
62
@@ -68,21 +72,22 @@ def parse_vars(items):
68
72
d [key ] = value
69
73
return d
70
74
75
+
71
76
# parse the key-value pairs
72
77
73
78
command_options = parse_vars (args .set )
74
79
75
80
for k in TAGS :
76
81
if TAGS [k ] not in command_options :
77
- command_options [TAGS [k ]] = TAGS_DEFAULT [k ]
78
-
79
- if ( not command_options [TAGS ["input_dir" ]].endswith ("/" ) ):
80
- command_options [TAGS ["input_dir" ]]+= "/"
82
+ command_options [TAGS [k ]] = TAGS_DEFAULT [k ]
83
+
84
+ if not command_options [TAGS ["input_dir" ]].endswith ("/" ):
85
+ command_options [TAGS ["input_dir" ]] += "/"
81
86
if not os .path .isdir (command_options [TAGS ["input_dir" ]]):
82
87
parser .error (f"Input directory '{ command_options [TAGS ['input_dir' ]]} ' does not exist" )
83
88
84
- #command_options[TAGS["rank"]] = int(command_options[TAGS["rank"]])
85
- #command_options[TAGS["zero"]] = float(command_options[TAGS["zero"]])
89
+ # command_options[TAGS["rank"]] = int(command_options[TAGS["rank"]])
90
+ # command_options[TAGS["zero"]] = float(command_options[TAGS["zero"]])
86
91
try :
87
92
command_options [TAGS ["rank" ]] = int (command_options [TAGS ["rank" ]])
88
93
if command_options [TAGS ["rank" ]] < 0 :
@@ -97,7 +102,7 @@ def parse_vars(items):
97
102
except ValueError :
98
103
parser .error (f"Zero threshold must be a number, got '{ command_options [TAGS ['zero' ]]} '" )
99
104
100
-
105
+
101
106
# Safely convert levelAxis to boolean
102
107
level_val = command_options [TAGS ["level" ]].lower ()
103
108
if level_val not in ("true" , "false" ):
@@ -110,12 +115,12 @@ def parse_vars(items):
110
115
parser .error (f"showFig must be 'True' or 'False', got '{ command_options [TAGS ['level' ]]} '" )
111
116
command_options [TAGS ["showfig" ]] = showFig_val == "true"
112
117
113
- #command_options[TAGS["level"]] = eval(command_options[TAGS["level"]])
118
+ # command_options[TAGS["level"]] = eval(command_options[TAGS["level"]])
114
119
115
- #valid_keys = set(TAGS.values())
116
- #for key in command_options:
120
+ # valid_keys = set(TAGS.values())
121
+ # for key in command_options:
117
122
# if key not in valid_keys:
118
123
# parser.warn(f"Invalid option key: '{key}'. Valid keys are: {', '.join(valid_keys)}")
119
124
#### allow extra options ####
120
125
121
- #print (command_options)
126
+ # print (command_options)
0 commit comments