Skip to content

Commit b235444

Browse files
committed
#7: add cli options for controlling error bars
1 parent b56bde1 commit b235444

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

detection/plot_dropped_nodes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def main():
2121
parser.add_argument('-s', '--slownode', help='Absolute or relative path to the output from slow_node executable', required=True)
2222
parser.add_argument('-a', '--analysis', help='Absolute or relative path to the output from detect_slow_nodes', required=True)
2323
parser.add_argument('-o', '--output', help='Absolute or relative path to the output directory where the plot will be saved. Defaults to $(pwd)/output', default=None)
24+
parser.add_argument('-r', '--show_ranges', help='Show range for all nodes (not just the dropped ones)', action="store_true")
25+
parser.add_argument('-n', '--no_ranges', help='Hide ranges for all nodes (including the dropped ones). Overrides -r', action="store_true")
2426
args = parser.parse_args()
2527

2628
slownode_filepath = os.path.abspath(args.slownode)
@@ -30,7 +32,7 @@ def main():
3032
rank_times, _, rank_to_node_map = parseOutput(slownode_filepath)
3133
dropped_nodes = parseAnalysis(analysis_filepath)
3234

33-
plotDroppedNodes(rank_times, rank_to_node_map, dropped_nodes, output_filepath)
35+
plotDroppedNodes(rank_times, rank_to_node_map, dropped_nodes, output_filepath, args.show_ranges, args.no_ranges)
3436

3537
if __name__ == "__main__":
3638
timeFtn(main)

detection/utils/Plot.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def plotData(x_data, y_data, title, xlabel, save_dir, threshold_pct=0.05, highli
5252
plt.savefig(save_path)
5353
plt.close()
5454

55-
def plotNodes(x_data, y_data, y_mins, y_maxes, title, save_dir, dropped_nodes=[]):
55+
def plotNodes(x_data, y_data, y_mins, y_maxes, title, save_dir, dropped_nodes=[], show_all_ranges=False, hide_all_ranges=False):
5656
"""
5757
Plots y_data vs. x_data and highlights outliers.
5858
Saves plots to the same directory as the input file.
@@ -71,6 +71,18 @@ def plotNodes(x_data, y_data, y_mins, y_maxes, title, save_dir, dropped_nodes=[]
7171
plt.scatter(x_data, y_data, label='Data', zorder=3, s=10)
7272
plt.plot(x_data, [avg] * y_size, label="Average", color="tab:green", zorder=1)
7373

74+
if show_all_ranges and not hide_all_ranges:
75+
all_mins, all_maxes = [], []
76+
for n_id in x_data:
77+
idx = x_data.index(n_id)
78+
n_time = y_data[idx]
79+
n_min = y_mins[idx]
80+
n_max = y_maxes[idx]
81+
all_mins.append(n_time - n_min)
82+
all_maxes.append(n_max - n_time)
83+
ranges = [all_mins, all_maxes]
84+
plt.errorbar(x_data, y_data, yerr=ranges, fmt='none', color='black', elinewidth=0.5, capsize=3, capthick=0.5, zorder=1)
85+
7486
if len(dropped_nodes) > 0:
7587
dropped_node_times = []
7688
mins, maxes = [], []
@@ -84,9 +96,10 @@ def plotNodes(x_data, y_data, y_mins, y_maxes, title, save_dir, dropped_nodes=[]
8496
mins.append(n_time - n_min)
8597
maxes.append(n_max - n_time)
8698
s = "" if len(dropped_node_times) == 1 else "s"
87-
errors = [mins, maxes]
88-
plt.errorbar(dropped_nodes, dropped_node_times, yerr=errors, fmt='none', color='red', elinewidth=0.5, capsize=3, capthick=0.5, zorder=4)
8999
plt.scatter(dropped_nodes, dropped_node_times, label=f"Dropped Node{s}", color="r", marker="*", zorder=4)
100+
errors = [mins, maxes]
101+
if not hide_all_ranges:
102+
plt.errorbar(dropped_nodes, dropped_node_times, yerr=errors, fmt='none', color='red', elinewidth=1.0 if show_all_ranges else 0.5, capsize=3, capthick=0.5, zorder=4)
90103

91104
plt.title(title)
92105
plt.xlabel("Node ID")
@@ -100,7 +113,10 @@ def plotNodes(x_data, y_data, y_mins, y_maxes, title, save_dir, dropped_nodes=[]
100113
plt.savefig(save_path)
101114
plt.close()
102115

103-
def plotDroppedNodes(rank_times, rank_to_node_map, dropped_nodes, output_filepath):
116+
def plotDroppedNodes(rank_times, rank_to_node_map, dropped_nodes, output_filepath, show_all_ranges=False, hide_all_ranges=False):
117+
if hide_all_ranges:
118+
show_all_ranges = False
119+
104120
# Gather all times on this node
105121
all_node_data = {}
106122
for r_id, r_time in rank_times.items():
@@ -137,5 +153,7 @@ def plotDroppedNodes(rank_times, rank_to_node_map, dropped_nodes, output_filepat
137153
all_node_ydata["max"],
138154
"Average Time Across All Ranks on All Nodes",
139155
output_filepath,
140-
dropped_nodes=[getNodeNumber(n_id) for n_id in dropped_nodes]
141-
)
156+
dropped_nodes=[getNodeNumber(n_id) for n_id in dropped_nodes],
157+
show_all_ranges=show_all_ranges,
158+
hide_all_ranges=hide_all_ranges
159+
)

0 commit comments

Comments
 (0)