88
99from __future__ import annotations
1010
11+ import gc
1112import json
1213import os
1314import random
@@ -72,19 +73,32 @@ def solve_with_budget(task: Dict[str, Any], solver: ARCSolver) -> Tuple[List[Dic
7273 dictionaries of the form ``{"output": grid}`` and ``metadata``
7374 contains diagnostic information such as elapsed time and timeout flag.
7475 """
75-
76+ # [S:ALG v1] fallback=best_so_far memlimit=soft pass
7677 _set_mem_limit ()
7778 signal .signal (signal .SIGALRM , _alarm )
7879 signal .alarm (int (HARD_TIMEOUT_SEC ))
7980 start = time .time ()
8081 try :
8182 attempt1 , attempt2 = solver .solve_task_two_attempts (task )
8283 elapsed = time .time () - start
83- return [{"output" : attempt1 }, {"output" : attempt2 }], {"elapsed" : elapsed , "timeout" : False }
84+ return [
85+ {"output" : attempt1 },
86+ {"output" : attempt2 },
87+ ], {"elapsed" : elapsed , "timeout" : False , "memerror" : False }
8488 except Timeout :
8589 best = solver .best_so_far (task )
8690 elapsed = time .time () - start
87- return [{"output" : best }, {"output" : best }], {"elapsed" : elapsed , "timeout" : True }
91+ return [
92+ {"output" : best },
93+ {"output" : best },
94+ ], {"elapsed" : elapsed , "timeout" : True , "memerror" : False }
95+ except MemoryError :
96+ best = solver .best_so_far (task )
97+ elapsed = time .time () - start
98+ return [
99+ {"output" : best },
100+ {"output" : best },
101+ ], {"elapsed" : elapsed , "timeout" : False , "memerror" : True }
88102 finally :
89103 signal .alarm (0 )
90104
@@ -95,19 +109,23 @@ def main() -> None:
95109 solver = ARCSolver (use_enhancements = True )
96110 solutions : Dict [str , Dict [str , List [List [int ]]]] = {}
97111
112+ mem_error_count = 0
98113 for task_id , task in data .items ():
99114 attempts , meta = solve_with_budget (task , solver )
100115 solutions [task_id ] = {
101116 "attempt_1" : attempts [0 ]["output" ],
102117 "attempt_2" : attempts [1 ]["output" ],
103118 }
119+ if meta .get ("memerror" ):
120+ mem_error_count += 1
104121 print (
105- f"[task { task_id } ] t={ meta ['elapsed' ]:.2f} s timeout={ meta ['timeout' ]} " ,
122+ f"[task { task_id } ] t={ meta ['elapsed' ]:.2f} s timeout={ meta ['timeout' ]} memerror= { meta [ 'memerror' ] } " ,
106123 file = sys .stderr ,
107124 )
125+ gc .collect ()
108126
109127 path = save_submission (solutions , "submission.json" )
110- print (f"Saved { path } with { len (solutions )} tasks." )
128+ print (f"Saved { path } with { len (solutions )} tasks. memory_errors= { mem_error_count } " )
111129
112130
113131if __name__ == "__main__" :
0 commit comments