CodeReclaimers / neat-python

Python implementation of the NEAT neuroevolution algorithm
BSD 3-Clause "New" or "Revised" License
1.4k stars 488 forks source link

parallel evaluation throws exception #238

Open cdemirkiran opened 2 years ago

cdemirkiran commented 2 years ago

When I am trying to run with parallel evaluation, I receive the error below. The way I call it:

`def eval_genomes(genomes, config): for genome_id, genome in genomes: genome.fitness = 4.0 net = neat.nn.FeedForwardNetwork.create(genome, config) outputs = [] for inp, out in tuple_from_file(TRAIN_DATA): outputs.append([net.activate(inp), out]) genome.fitness += get_fitness(outputs)

def run(config_file): config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation, config_file)

# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)

# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter(True))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
p.add_reporter(neat.Checkpointer(5))

parallel_evaluator = neat.ParallelEvaluator(2 * multiprocessing.cpu_count() - 1, eval_genomes)`

And the error:

` ** Running generation 0 **

multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/usr/lib/python3.9/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "tryneat.py", line 15, in eval_genomes for genome_id, genome in genomes: TypeError: 'DefaultGenome' object is not iterable """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "tryneat.py", line 80, in run(config_path) File "tryneat.py", line 41, in run winner = p.run(parallel_evaluator.evaluate, 300) File "venv/lib/python3.9/site-packages/neat/population.py", line 89, in run fitness_function(list(iteritems(self.population)), self.config) File "venv/lib/python3.9/site-packages/neat/parallel.py", line 30, in evaluate genome.fitness = job.get(timeout=self.timeout) File "/usr/lib/python3.9/multiprocessing/pool.py", line 771, in get raise self._value TypeError: 'DefaultGenome' object is not iterable`

ubeydtalha commented 2 years ago

In case of parallel operation, I think a single genome comes to the function, try it as if there is a single genome without putting it into the for loop.


https://gitlab.com/lucasrthompson/Sonic-Bot-In-OpenAI-and-NEAT/-/blob/master/neat-paralle-sonic.py Şu kaynakta paralelize edilmiş halde Worker lara tek bir gen gönderilmiş. Ayrıca discordtan ( MAJIN#4884 ) ekleyebilirsen beni konuşabiliriz , bende tam çözmedim bu kütüphaneyi :)