Skip to content

pymoo/reused-algorithm-without-copy

Rule reused-algorithm-without-copy
Pack pymoo
Severity error
Fix none, edit by hand
Library versions pymoo 0.6 and later

With copy_algorithm=False, a second minimize on the same algorithm does not set it up again and returns the earlier result. Build a new algorithm for each run, or drop copy_algorithm=False.

algorithm = NSGA2(pop_size=100)
for problem in problems:
algorithm = NSGA2(pop_size=100)
results.append(minimize(problem, algorithm, ("n_gen", 200), seed=1, copy_algorithm=False))

The rule reports a second minimize on the same algorithm when both calls pass copy_algorithm=False, in one block or in a loop that never binds the name. With copy_algorithm=False, minimize sets the algorithm up only when it has no problem yet. A second call with another problem, ("n_gen", 30) and another seed returned the F of the first call, still at generation 11 and still on the first problem. A loop over the algorithms, as in for algorithm in [NSGA2(), SMSEMOA()], gives each pass another object and is left alone.

xpd has no automatic fix, so make the change by hand.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

$ALG already ran in an earlier minimize with copy_algorithm=False, so this call does not set it up again and returns the earlier result. A second call with another problem, ("n_gen", 30) and another seed returned the F of the first call, still at generation 11. Build a new algorithm for this run, or drop copy_algorithm=False.

Browse the other rules of the pymoo pack.