@@ -45,10 +45,31 @@ def compare(candidate: Pack, golden: Pack, tol: Tolerance) -> typing.Tuple[Error
4545 error = compute_error (cVal , gVal )
4646 avg_err .push (error )
4747
48- def raise_err_with_max_diagnostics (msg : str ):
49- # Find maximum errors across ALL files for diagnostics
50- max_errors = find_maximum_errors (candidate , golden )
51- diagnostic_msg = format_diagnostic_message (max_errors )
48+ def raise_err_with_failing_diagnostics (msg : str ):
49+ # Find maximum errors among FAILING variables only
50+ max_abs_info , max_rel_info = find_maximum_errors_among_failing (candidate , golden , tol )
51+
52+ diagnostic_msg = ""
53+ if max_abs_info :
54+ max_abs_filepath , max_abs_valIndex , max_abs_gVal , max_abs_cVal , max_abs_error , max_abs_rel_error = max_abs_info
55+ rel_error_str = f"{ max_abs_rel_error :.2E} " if not math .isnan (max_abs_rel_error ) else "NaN"
56+ diagnostic_msg += f"\n \n Diagnostics - Maximum absolute error among FAILING variables:\n " \
57+ f" - File: { max_abs_filepath } \n " \
58+ f" - Variable n°{ max_abs_valIndex + 1 } \n " \
59+ f" - Candidate: { max_abs_cVal } \n " \
60+ f" - Golden: { max_abs_gVal } \n " \
61+ f" - Absolute Error: { max_abs_error :.2E} \n " \
62+ f" - Relative Error: { rel_error_str } "
63+
64+ if max_rel_info :
65+ max_rel_filepath , max_rel_valIndex , max_rel_gVal , max_rel_cVal , max_rel_error , max_rel_abs_error = max_rel_info
66+ diagnostic_msg += f"\n \n Diagnostics - Maximum relative error among FAILING variables:\n " \
67+ f" - File: { max_rel_filepath } \n " \
68+ f" - Variable n°{ max_rel_valIndex + 1 } \n " \
69+ f" - Candidate: { max_rel_cVal } \n " \
70+ f" - Golden: { max_rel_gVal } \n " \
71+ f" - Relative Error: { max_rel_error :.2E} \n " \
72+ f" - Absolute Error: { max_rel_abs_error :.2E} "
5273
5374 return None , f"""\
5475 Variable n°{ valIndex + 1 } (1-indexed) in { gFilepath } { msg } :
@@ -59,48 +80,21 @@ def raise_err_with_max_diagnostics(msg: str):
5980"""
6081
6182 if math .isnan (gVal ):
62- return raise_err_with_max_diagnostics ("is NaN in the golden file" )
83+ return raise_err_with_failing_diagnostics ("is NaN in the golden file" )
6384 if math .isnan (cVal ):
64- return raise_err_with_max_diagnostics ("is NaN in the pack file" )
85+ return raise_err_with_failing_diagnostics ("is NaN in the pack file" )
6586 if not is_close (error , tol ):
66- return raise_err_with_max_diagnostics ("is not within tolerance" )
87+ return raise_err_with_failing_diagnostics ("is not within tolerance" )
6788
6889 # Return the average relative error
6990 return avg_err .get (), None
7091
7192
72- def format_diagnostic_message (max_errors : typing .Tuple [typing .Optional [typing .Tuple [str , int , float , float , float , float ]], typing .Optional [typing .Tuple [str , int , float , float , float , float ]]]) -> str :
73- """Format the diagnostic message showing maximum errors."""
74- max_abs_info , max_rel_info = max_errors
75- diagnostic_msg = ""
76-
77- if max_abs_info :
78- filepath , var_idx , golden_val , candidate_val , abs_error , rel_error = max_abs_info
79- rel_error_str = f"{ rel_error :.2E} " if not math .isnan (rel_error ) else "NaN"
80- diagnostic_msg += f"\n \n Diagnostics - Maximum absolute error across ALL files:\n " \
81- f" - File: { filepath } \n " \
82- f" - Variable n°{ var_idx + 1 } \n " \
83- f" - Candidate: { candidate_val } \n " \
84- f" - Golden: { golden_val } \n " \
85- f" - Absolute Error: { abs_error :.2E} \n " \
86- f" - Relative Error: { rel_error_str } "
87-
88- if max_rel_info :
89- filepath , var_idx , golden_val , candidate_val , rel_error , abs_error = max_rel_info
90- diagnostic_msg += f"\n \n Diagnostics - Maximum relative error across ALL files:\n " \
91- f" - File: { filepath } \n " \
92- f" - Variable n°{ var_idx + 1 } \n " \
93- f" - Candidate: { candidate_val } \n " \
94- f" - Golden: { golden_val } \n " \
95- f" - Relative Error: { rel_error :.2E} \n " \
96- f" - Absolute Error: { abs_error :.2E} "
97-
98- return diagnostic_msg
99-
100-
101- def find_maximum_errors (candidate : Pack , golden : Pack ) -> typing .Tuple [typing .Optional [typing .Tuple [str , int , float , float , float , float ]], typing .Optional [typing .Tuple [str , int , float , float , float , float ]]]:
93+ def find_maximum_errors_among_failing (candidate : Pack , golden : Pack , tol : Tolerance ) -> typing .Tuple [typing .Optional [typing .Tuple [str , int , float , float , float , float ]], typing .Optional [typing .Tuple [str , int , float , float , float , float ]]]:
10294 """
103- Scan all files to find the maximum absolute and relative errors.
95+ Scan all files to find the maximum absolute and relative errors among FAILING variables only.
96+ A variable fails if is_close(error, tol) returns False.
97+
10498 Returns tuple of:
10599 - max_abs_info: (filepath, var_index, golden_val, candidate_val, absolute_error, relative_error)
106100 - max_rel_info: (filepath, var_index, golden_val, candidate_val, relative_error, absolute_error)
@@ -123,14 +117,18 @@ def find_maximum_errors(candidate: Pack, golden: Pack) -> typing.Tuple[typing.Op
123117
124118 error = compute_error (cVal , gVal )
125119
126- # Track maximum absolute error
120+ # Only consider variables that FAIL tolerance
121+ if is_close (error , tol ):
122+ continue # Skip variables that pass tolerance
123+
124+ # Track maximum absolute error among failing variables
127125 if error .absolute > max_abs_error :
128126 max_abs_error = error .absolute
129127 max_abs_info = (gFilepath , valIndex , gVal , cVal , error .absolute , error .relative )
130128
131- # Track maximum relative error (only if it's not NaN)
129+ # Track maximum relative error among failing variables (only if it's not NaN)
132130 if not math .isnan (error .relative ) and error .relative > max_rel_error :
133131 max_rel_error = error .relative
134132 max_rel_info = (gFilepath , valIndex , gVal , cVal , error .relative , error .absolute )
135133
136- return max_abs_info , max_rel_info
134+ return max_abs_info , max_rel_info
0 commit comments