@@ -39,7 +39,7 @@ def __init__(self, use_enhancements: bool = True,
3939 def solve_task (self , task : Dict [str , List [Dict [str , List [List [int ]]]]]) -> Dict [str , List [List [List [int ]]]]:
4040 """Solve a single ARC task using enhanced or baseline methods."""
4141 self .stats ['total_tasks' ] += 1
42-
42+
4343 # Extract training pairs as numpy arrays, skipping malformed ones
4444 train_pairs : List [Tuple [Array , Array ]] = []
4545 for pair in task .get ("train" , []):
@@ -59,52 +59,51 @@ def solve_task(self, task: Dict[str, List[Dict[str, List[List[int]]]]]) -> Dict[
5959 test_inputs .append (np .zeros ((1 , 1 ), dtype = np .int16 ))
6060
6161 if not train_pairs :
62- return {
63- "attempt_1" : [to_list (arr ) for arr in test_inputs ],
64- "attempt_2" : [to_list (arr ) for arr in test_inputs ],
65- }
66-
67- # Try enhanced synthesis first, fall back to baseline if needed
62+ identity = [to_list (arr ) for arr in test_inputs ]
63+ return {"attempt_1" : identity , "attempt_2" : identity }
64+
65+ # Collect predictions for each test input individually
66+ attempt1 : List [List [List [int ]]] = []
67+ attempt2 : List [List [List [int ]]] = []
68+ for test_input in test_inputs :
69+ predictions = self ._get_predictions (train_pairs , test_input )
70+ if predictions and predictions [0 ]:
71+ first = to_list (predictions [0 ][0 ])
72+ second_arr = predictions [1 ][0 ] if len (predictions ) > 1 else predictions [0 ][0 ]
73+ second = to_list (second_arr )
74+ attempt1 .append (first )
75+ attempt2 .append (second )
76+ else :
77+ # Use identity grid as safe fallback
78+ fallback = to_list (test_input )
79+ attempt1 .append (fallback )
80+ attempt2 .append (fallback )
81+
82+ return {"attempt_1" : attempt1 , "attempt_2" : attempt2 }
83+
84+ def _get_predictions (
85+ self , train_pairs : List [Tuple [Array , Array ]], test_input : Array
86+ ) -> List [List [Array ]]:
87+ """Get prediction attempts for a single test input."""
6888 try :
6989 if self .use_enhancements :
90+ print ("Using enhanced search for prediction" )
7091 progs = synthesize_with_enhancements (train_pairs )
71- attempts = predict_two_enhanced (progs , test_inputs )
72-
73- # Check if we got a reasonable solution
74- if self ._validate_solution (attempts , test_inputs ):
75- if any (np .all (out == 0 ) for out in attempts [0 ]):
76- self .stats ['fallback_used' ] += 1
77- raise Exception ("Enhanced search produced degenerate output" )
78- self .stats ['tasks_solved' ] += 1
79- return {
80- "attempt_1" : [to_list (arr ) for arr in attempts [0 ]],
81- "attempt_2" : [to_list (arr ) for arr in attempts [1 ]],
82- }
92+ attempts = predict_two_enhanced (progs , [test_input ])
93+ if self ._validate_solution (attempts , [test_input ]):
94+ return attempts
8395 else :
84- # Enhancement didn't work, try fallback
85- self .stats ['fallback_used' ] += 1
86- raise Exception ("Enhanced search failed validation" )
96+ print ("Enhanced prediction failed validation" )
8797 else :
88- raise Exception ("Enhancements disabled" )
89-
90- except Exception :
91- # Fall back to baseline approach
92- progs = synth_baseline (train_pairs )
93- attempts = predict_two_baseline (progs , test_inputs )
94-
95- # Sanity check predictions and fall back to identity if needed
96- fixed_attempts : List [List [Array ]] = [[], []]
97- for idx , pred in enumerate (attempts [0 ]):
98- if pred is None or pred .size == 0 or np .all (pred == 0 ):
99- fixed_attempts [0 ].append (test_inputs [idx ])
100- else :
101- fixed_attempts [0 ].append (pred )
102- fixed_attempts [1 ] = attempts [1 ] if len (attempts ) > 1 else fixed_attempts [0 ]
103-
104- return {
105- "attempt_1" : [to_list (arr ) for arr in fixed_attempts [0 ]],
106- "attempt_2" : [to_list (arr ) for arr in fixed_attempts [1 ]],
107- }
98+ print ("Enhancements disabled, using baseline search" )
99+ except Exception as e :
100+ print (f"Enhanced prediction error: { e } " )
101+
102+ # Fall back to baseline search
103+ self .stats ['fallback_used' ] += 1
104+ print ("Falling back to baseline search" )
105+ progs = synth_baseline (train_pairs )
106+ return predict_two_baseline (progs , [test_input ])
108107
109108 def solve_task_two_attempts (
110109 self , task : Dict [str , List [Dict [str , List [List [int ]]]]]
0 commit comments