Skip to content

Commit fef20cd

Browse files
committed
#5: Break long lines and fix more f strings
1 parent f137e2a commit fef20cd

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

detection/detect_slow_nodes.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,15 @@ def __findClusterOutliers(self, data):
288288
"""
289289
Finds rank outliers by their total execution times.
290290
"""
291-
data, clusters, cluster_to_times, cluster_to_ranks, cluster_centers, representative_cluster, representative_center, threshold, problematic_clusters = self.__clusterTimes(data)
291+
data, \
292+
clusters, \
293+
cluster_to_times, \
294+
cluster_to_ranks, \
295+
cluster_centers, \
296+
representative_cluster, \
297+
representative_center, \
298+
threshold, \
299+
problematic_clusters = self.__clusterTimes(data)
292300

293301
## warnings if representative cluster is actually the slowest
294302
# identify if representative cluster has slowest center
@@ -308,7 +316,11 @@ def __findClusterOutliers(self, data):
308316
if representative_center - 3 * np.std(cluster_to_times[representative_cluster]) > slowest_non_representative_center:
309317
print()
310318
print(f" WARNING: Clustering results found most times to be slower than others. No outliers will be detected.")
311-
print(f" Most times are centered around {representative_center:.2f}, but other ranks ran in {fastest_non_representative_center:.2f}-{slowest_non_representative_center:.2f}s")
319+
print(
320+
f" Most times are centered around {representative_center:.2f}, "
321+
f"but other ranks ran in {fastest_non_representative_center:.2f}-"
322+
f"{slowest_non_representative_center:.2f}s"
323+
)
312324
print()
313325

314326
node_to_ranks = {}
@@ -320,7 +332,11 @@ def __findClusterOutliers(self, data):
320332
# write clustering results to file
321333
with open(os.path.join(self.__output_dir, f"clustering_results.txt"), 'w') as file:
322334
for cluster in sorted(np.unique(np.array(clusters))):
323-
file.write(f"* Cluster {cluster} {'(representative)' if cluster == representative_cluster else ''}{'(outlier)' if cluster_centers[cluster] > threshold else ''}:\n")
335+
representative_label = '(representative)' if cluster == representative_cluster else ''
336+
outlier_label = '(outlier)' if cluster_centers[cluster] > threshold else ''
337+
file.write(
338+
f"* Cluster {cluster} {representative_label} {outlier_label}:\n"
339+
)
324340

325341
# Print ranks in cluster, grouped by nodes
326342
for node, ranks in node_to_ranks.items():
@@ -383,7 +399,9 @@ def __printClusteringResults(self, clusters, cluster_to_ranks, cluster_centers,
383399
print(f"Representative cluster: {representative_cluster}")
384400
print()
385401
for cluster in sorted(np.unique(np.array(clusters))):
386-
print(f" * Cluster {cluster} {'(representative)' if cluster == representative_cluster else ''}{'(outlier)' if cluster_centers[cluster] > threshold else ''} contains:")
402+
representative_label = '(representative)' if cluster == representative_cluster else ''
403+
outlier_label = '(outlier)' if cluster_centers[cluster] > threshold else ''
404+
print(f" * Cluster {cluster} {representative_label}{outlier_label} contains:")
387405
cluster_nodes = []
388406
for rank, node in self.__rank_to_node_map.items():
389407
if rank in cluster_to_ranks[cluster]:

0 commit comments

Comments
 (0)