1+ """Collect and log benchmark results to DVC."""
2+
13import json
24import os
35import shutil
46import sys
57from datetime import date
6- from dvclive . live import Live
8+ from dvclive import Live
79
810
911def delete_dir_contents (dir ):
12+ """Delete all contents of a directory."""
1013 for filename in os .listdir (dir ):
1114 file_path = os .path .join (dir , filename )
1215 try :
@@ -19,6 +22,7 @@ def delete_dir_contents(dir):
1922
2023
2124def open_json_report (id , report_name ):
25+ """Open JSON report from build or measurement artifacts."""
2226 # look in both, build & measurement, artifacts
2327 path1 = os .path .join ("build_artifacts" , "runs_output" , "run_%d" % (id ), "reports" , report_name )
2428 path2 = os .path .join (
@@ -38,7 +42,10 @@ def open_json_report(id, report_name):
3842
3943# Wrapper around DVC Live object
4044class DVCLoggerHelper :
45+ """Wrapper around DVC Live for logging experiments."""
46+
4147 def __init__ (self , experiment_name , experiment_msg , id , params ):
48+ """Initialize DVC logger with experiment details."""
4249 self .id = id
4350
4451 # extract logging settings from params
@@ -62,20 +69,24 @@ def __init__(self, experiment_name, experiment_msg, id, params):
6269 self .log_params (params )
6370
6471 def __enter__ (self ):
72+ """Enter context manager."""
6573 return self
6674
6775 def __exit__ (self , exc_type , exc_value , traceback ):
76+ """Exit context manager and end DVC session."""
6877 if self .store_as_experiment :
6978 # End DVC Live experiment session
7079 self .live .end ()
7180
7281 def log_params (self , params ):
82+ """Log parameters to DVC."""
7383 if self .store_as_experiment :
7484 self .live .log_params (params )
7585 if self .store_as_data :
7686 self .data_dict .update (params )
7787
7888 def log_metric (self , prefix , name , value ):
89+ """Log a single metric to DVC."""
7990 # sanitize '/' in name because DVC uses it to nest metrics (which we do via prefix)
8091 name = name .replace ("/" , "-" )
8192
@@ -95,27 +106,32 @@ def log_metric(self, prefix, name, value):
95106 _dict [name ] = value
96107
97108 def log_image (self , image_name , image_path ):
109+ """Log an image artifact to DVC."""
98110 if self .store_as_experiment :
99111 self .live .log_image (image_name , image_path )
100112
101113 def log_artifact (self , artifact_path ):
114+ """Log an artifact to DVC."""
102115 if self .store_as_experiment :
103116 self .live .log_artifact (artifact_path )
104117
105118 def log_all_metrics_from_report (self , report_name , prefix = "" ):
119+ """Log all metrics from a JSON report."""
106120 report = open_json_report (self .id , report_name )
107121 if report :
108122 for key in report :
109123 self .log_metric (prefix , key , report [key ])
110124
111125 def log_metrics_from_report (self , report_name , keys , prefix = "" ):
126+ """Log specific metrics from a JSON report."""
112127 report = open_json_report (self .id , report_name )
113128 if report :
114129 for key in keys :
115130 if key in report :
116131 self .log_metric (prefix , key , report [key ])
117132
118133 def log_nested_metrics_from_report (self , report_name , key_top , keys , prefix = "" ):
134+ """Log nested metrics from a JSON report."""
119135 report = open_json_report (self .id , report_name )
120136 if report :
121137 if key_top in report :
@@ -125,7 +141,10 @@ def log_nested_metrics_from_report(self, report_name, key_top, keys, prefix=""):
125141
126142
127143if __name__ == "__main__" :
128- # Go through all runs found in the artifacts and log their results to DVC
144+ """Go through all runs found in the artifacts and log their results to DVC."""
145+ print ("FIXME: collect.py" )
146+ sys .exit (0 )
147+
129148 run_dir_list = os .listdir (os .path .join ("build_artifacts" , "runs_output" ))
130149 print ("Looking for runs in build artifacts" )
131150 run_ids = []
0 commit comments