pymoo
pymoo copied to clipboard
Restarting from Checkpoint, multiple runs, always reverts back to first checkpoint.
Hello, I am trying to create multiple checkpoints, esentially in a loop to ask the user if they would like to iterate 2 more generations or be done with the initial optimization run. However, if I try and continue the loop twice, the second time (and subsequent times) just restarts from the original checkpoint n_gen rather than the latest checkpoint n_gen.
How can I fix this? Is it a bug in Pymoo or an error on my part?
res = minimize(problem,
algorithm,
termination,
#seed=1,
copy_algorithm=False,
save_history=True,
verbose=True)
if os.path.exists("checkpoint"): # remove "checkpoint" file if already exists, before creating new one
os.remove("checkpoint")
with open("checkpoint", "wb") as f: # create checkpoint file
dill.dump(algorithm, f)
elapsed_time = time.time() - start_time
print(f"Optimization runtime: {elapsed_time/60:.2f} min")
# Offer to run n_gen_continue more generations
while True:
n_gen_continue = 2
selec1 = input(f"\n\n>>> Continue for another {n_gen_continue} generations? (y/n): ")
if selec1 == "Y" or selec1 == "y": # then continue optimizaiton for another "n_gen_continue" generations
print("\nContinuing...")
with open("checkpoint", 'rb') as f:
checkpoint = dill.load(f)
print("> Loaded Checkpoint:", checkpoint)
print("\n\n")
start_time = time.time()
checkpoint.termination = MaximumGenerationTermination(checkpoint.n_gen + n_gen_continue)
res = minimize(problem,
checkpoint,
#seed=1,
copy_algorithm=True,
save_history=True,
verbose=True)
# if os.path.exists("checkpoint"): # remove "checkpoint" file if already exists, before creating new one
# os.remove("checkpoint")
with open("checkpoint", "wb") as f: # create checkpoint
dill.dump(algorithm, f)
elapsed_time = time.time() - start_time
print(f"Optimization runtime: {elapsed_time/60:.2f} min")
elif selec1 == "N" or selec1 == "n": # then don't continue optimization
break
else:
print("***Invalid selection ***")