science-codeevolve icon indicating copy to clipboard operation
science-codeevolve copied to clipboard

second_autocorr_ineq evaluate.py accepts NaN/+inf sequences and writes a NaN result

Open maximusrufus opened this issue 1 month ago • 1 comments

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):

maximusrufus avatar Oct 26 '26 14:10 maximusrufus

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.

HenriqueAssumpcao avatar Oct 28 '26 09:10 HenriqueAssumpcao