@@ -75,10 +75,13 @@ def get_agent(self, agent_config: dict, prompts: dict, push: bool) -> Player:
7575 def run (self ) -> None :
7676 """Main execution function that runs all rounds."""
7777 try :
78- self .run_competition_phase (0 ) # Warm up (doesn't count)
78+ self .run_competition_phase (0 ) # Initial round with identical codebases
7979 for round_num in range (1 , self .rounds + 1 ):
8080 self .run_edit_phase (round_num )
8181 self .run_competition_phase (round_num )
82+ # Need to separately compress the last round, because
83+ # in run_edit_phase we always only compress the previous round
84+ self ._compress_round_folder (self .rounds )
8285 finally :
8386 self .end ()
8487
@@ -108,6 +111,7 @@ def run_edit_phase(self, round_num: int) -> None:
108111 self .game .log_local / "rounds" / str (round_num - 1 ),
109112 DIR_LOGS / "rounds" / str (round_num - 1 ),
110113 )
114+ self ._compress_round_folder (round_num - 1 )
111115
112116 with ThreadPoolExecutor () as executor :
113117 futures = [executor .submit (self .run_agent , agent , round_num ) for agent in self .agents ]
@@ -156,8 +160,31 @@ def _compress_round_logs(self) -> None:
156160 shutil .rmtree (self .game .log_local / "rounds" )
157161 self .logger .info ("Round logs compressed successfully" )
158162
163+ def _compress_round_folder (self , round_num_zero_indexed : int ) -> None :
164+ round_dir = self .game .log_local / "rounds" / str (round_num_zero_indexed )
165+ if not round_dir .exists ():
166+ return
167+
168+ archive = self .game .log_local / "rounds" / f"round_{ round_num_zero_indexed } .tar.gz"
169+ cmd = [
170+ "tar" ,
171+ "-zcf" ,
172+ str (archive ),
173+ "-C" ,
174+ str (round_dir .parent ),
175+ str (round_num_zero_indexed ),
176+ ]
177+ self .logger .info (
178+ f"Compressing round { round_num_zero_indexed } logs, this might take a while... ({ ' ' .join (cmd )} )"
179+ )
180+ result = subprocess .run (cmd , capture_output = True , text = True )
181+ if result .returncode != 0 :
182+ raise RuntimeError (f"Command failed with exit code { result .returncode } :\n { result .stderr } " )
183+ self .logger .debug ("Removing %s" , round_dir )
184+ shutil .rmtree (round_dir )
185+ self .logger .info (f"Round { round_num_zero_indexed } logs compressed successfully" )
186+
159187 def end (self ) -> None :
160188 """Save output files, clean up game resources and push agents if requested."""
161189 self ._save ()
162190 self .game .end (self .cleanup_on_end )
163- self ._compress_round_logs ()
0 commit comments