Skip to content

pymoo/evaluate-returns-value

Pack Severity Fix Versions
pymoo error unsafe, with xpd check --fix --unsafe-fixes pymoo 0.6+

pymoo ignores what _evaluate returns and reads the objectives from out, so every objective comes back as inf without an error. Write the value to out["F"].

class Sphere(Problem):
def _evaluate(self, x, out, *args, **kwargs):
return (x**2).sum(axis=1)
out["F"] = (x**2).sum(axis=1)

The rule reports a return with a value in _evaluate when the method never names its out parameter. pymoo ignores the returned value, and every objective then comes back as inf. GA returned res.F = [inf] without an error. A method that hands out to a helper is left alone.

The rule looks for out as the third parameter, after self and the input values.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes out["F"] = <value> for the return. pymoo then reads the value where it read inf, the method goes on past that line, and a value of another shape raises.

pymoo ignores what _evaluate returns and reads the objectives from out, which this method never writes. Every objective then comes back as inf, and GA returned res.F = [inf] without an error. Write the value to out["F"].

See all rules in the pymoo pack.