science-codeevolve
science-codeevolve copied to clipboard
second_autocorr_ineq evaluate.py accepts NaN/+inf sequences and writes a NaN result
Affected (at c077959): problems/alphaevolve_math_problems/autocorrelation_problems/second_autocorr_ineq/input/evaluate.py:45 (np.any(f_values < -1e-6)), :48 (np.maximum), :67 (norm_1 * norm_inf < 1e-12).
Reproducer:
printf 'def construct_function():\n return [float("nan")]*10\n' > /tmp/p.py
cd problems/alphaevolve_math_problems/autocorrelation_problems/second_autocorr_ineq/input
python -c "import evaluate;evaluate.evaluate('/tmp/p.py','/tmp/res.json');print(open('/tmp/res.json').read())"
No exception; /tmp/res.json contains "c2": NaN, "benchmark_ratio": NaN. float("inf") behaves the same; -inf raises "Function must be non-negative".
Why invalid: f < -1e-6 is False for NaN, np.maximum keeps NaN, and NaN < 1e-12 is False, so every guard passes and a NaN c2 is written as a completed result.
Suggested fix:
+ if not np.isfinite(f_values).all():
+ raise ValueError("Function values must be finite")
if np.any(f_values < -1e-6):
Good catch!
The suggested fix should do it. If you want, you can create a PR with the fix and I'll merge it into the main branch.