Skip to content

pymoo/has-terminated-assignment

Rule has-terminated-assignment
Pack pymoo
Severity error
Fix none, edit by hand
Library versions pymoo 0.6 and later

Since pymoo 0.6.0, has_terminated is not read, so setting it does not restart a loaded algorithm that had finished. Give the algorithm a new termination instead.

(checkpoint,) = np.load("checkpoint.npy", allow_pickle=True).flatten()
checkpoint.has_terminated = False
res = minimize(problem, checkpoint, ("n_gen", 20), seed=1, copy_algorithm=False)
checkpoint.termination = MaximumGenerationTermination(20)
res = minimize(problem, checkpoint, copy_algorithm=False)

The rule reports has_terminated = False on a name that the file assigns from np.load, pickle.load or dill.load, also as one name of a tuple. Another object with an attribute of the same name is left alone. The checkpoint recipe of pymoo 0.4 and 0.5 set the attribute to let a loaded algorithm run on, and since 0.6.0 pymoo no longer reads it. An NSGA2 that had finished its 5 generations ran 0 more generations after has_terminated = False, and 15 more after it got a new termination.

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.

has_terminated is not read since pymoo 0.6.0, so a loaded algorithm that had finished stays finished. It ran 0 more generations after this line, and 15 more after it got a new termination. Write $A.termination = MaximumGenerationTermination(n), with the class from pymoo.termination.max_gen and n the total number of generations.

Browse the other rules of the pymoo pack.