Search code examples
python-multiprocessingpyevolve

Pyevolve with multi processing using more RAM with each GA generation


I am using pyevolve to run a GA using multi processing. The code runs fine but uses more memory with every new generation of GA. The code is creating new jobs for each generation while the previous ones are idle while reserving RAM.It finally crashes after around 10 generations. How do I correct this?[Ram Usage][1][1]: https://i.sstatic.net/knCC0.jpg

def main_run():

    flowargs, rhoargs, zindex=get_params()
    genome = G1DList.G1DList(18)
    genome.initializator.set(myGA.myInitializator)
    genome.crossover.set(myGA.mycrossover)
    genome.mutator.set(pl.Mutators.G1DListMutatorSwap)
    genome.setParams(z=zindex,f=flowargs,r=rhoargs)
    genome.evaluator.set(get_rho)
    ga = GSimpleGA.GSimpleGA(genome)
    ga.minimax = Consts.minimaxType["minimize"]
    ga.setGenerations(100)
    ga.selector.set(Selectors.GRouletteWheel)
    ga.setInteractiveMode(False)
    ga.setMultiProcessing(True)
    ga.evolve(freq_stats=1)
    best = ga.bestIndividual()
    print(best)

if __name__ == "__main__":
    main_run()

Solution

  • I came across this problem a while back, and after much research I found the answer,

    You have to modify the GPopulation.py in the library source code,

    --Add the following two commands:

    proc_pool.close()
    proc_pool.join()
    

    --before the last line of the function evaluate(self, **args)

    --Rebuild and re-install the libraries.
    i.e. C:\Pevolve Source code\Pyevolve-0.6rc1\pyevolve\GPopulation (mine was here)

    Edit with IDLE

    --Add proc_pool.close() & proc_pool.join() just before self.clearFlags()

    --Save

    Open Command Prompt

    1. Go to C:\Pevolve Source code\Pyevolve-0.6rc1
    2. setup.py build
    3. setup.py install