You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the callbacks to print progress at the stages you need. For one update per completed generation:
defon_generation(ga_instance):
solution, fitness, solution_idx=ga_instance.best_solution(
pop_fitness=ga_instance.last_generation_fitness)
print(f"Generation: {ga_instance.generations_completed}, best fitness: {fitness}")
Pass this function through on_generation=on_generation when constructing the GA. Supplying last_generation_fitness avoids recalculating fitness just to print it.
The lifecycle guide now explains the current ordering: evaluate the initial population, then select parents, apply crossover and mutation, update the population, evaluate it, and call on_generation. on_fitness observes the fitness used for parent selection. The guide and runnable lifecycle example show all stage callbacks.
Tests verify callback ordering and fitness evaluation for both a normal run and an early stop. Closing this issue as answered; the current lifecycle and progress reporting are documented and tested.
Activity
ahmedfgad commentedon Feb 14, 2023
You can use the callback functions to print something about the progress. Please check this example: https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#life-cycle-of-pygad
whubaichuan commentedon Feb 21, 2023
@ahmedfgad I think the workflow may be wrong. I have tested and show my point of view.

ahmedfgad commentedon Feb 22, 2023
@whubaichuan,
Yes you are right. The library went through some changes which affected some steps. This is the new lifecycle.
PyGAD 2.19.0 Release
ahmedfgad commentedon Oct 8, 2026
Use the callbacks to print progress at the stages you need. For one update per completed generation:
Pass this function through
on_generation=on_generationwhen constructing the GA. Supplyinglast_generation_fitnessavoids recalculating fitness just to print it.The lifecycle guide now explains the current ordering: evaluate the initial population, then select parents, apply crossover and mutation, update the population, evaluate it, and call
on_generation.on_fitnessobserves the fitness used for parent selection. The guide and runnable lifecycle example show all stage callbacks.Tests verify callback ordering and fitness evaluation for both a normal run and an early stop. Closing this issue as answered; the current lifecycle and progress reporting are documented and tested.