Python-DEAP和SCOOP:每个节点的结果/名人堂不同吗?

时间:2018-06-26 16:19:24

标签: python parallel-processing python-multiprocessing genetic-algorithm deap

我正在使用

  • Linux上的Python 3.6.4 / Anaconda自定义(64位)[GCC 7.2.0]
  • SCOOP 0.7.2.0
  • DEAP 1.2.2

https://github.com/soravux/scoop/blob/master/examples/deap_ga_onemax.py运行遗传算法示例scoop / examples / deap_ga_onemax.py

在使用SLURM脚本的HPC群集上

,请参见下面发布的代码。

请注意,deap_ga_onemax.py中的第71行已被注释:#random.seed(64)

Python代码:

"""
Code from the deap framework, available at:
https://code.google.com/p/deap/source/browse/examples/ga/onemax_short.py
Conversion to its parallel form took two lines:
from scoop import futures
toolbox.register("map", futures.map)
"""
import array
import random

import numpy

from deap import algorithms
from deap import base
from deap import creator
from deap import tools
from scoop import futures

creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", array.array, typecode='b',                 
fitness=creator.FitnessMax)

toolbox = base.Toolbox()

# Attribute generator
toolbox.register("attr_bool", random.randint, 0, 100)

# Structure initializers
toolbox.register("individual", tools.initRepeat, creator.Individual,     
toolbox.attr_bool, 100)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)

def evalOneMax(individual):
    return sum(individual),

toolbox.register("evaluate", evalOneMax)
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
toolbox.register("select", tools.selTournament, tournsize=3)
toolbox.register("map", futures.map)

def main():
    #random.seed(64)

    pop = toolbox.population(n=100)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)

    pop, log = algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=10,stats=stats, halloffame=hof, verbose=True)

        return pop, log, hof

if __name__ == "__main__":
    pop, log, hof = main()
    print(hof)

SLURM脚本:

#!/bin/bash

#SBATCH -J xxx
#SBATCH -A xxx
#SBATCH -N 4
#SBATCH -n 4
#SBATCH --time=00:03:00
#SBATCH --mem-per-cpu=1024M

#echo "ERROR"
hosts=$(srun bash -c hostname)
srun /projects/p_thermo_dat/software/python36/bin/python -m scoop --host $hosts -v scoop_deap_test.py > $(date +"%Y%m%d_%I%M%p")_log_scoop_deap_test.txt

exit

问题: 在具有4个处理器的4个节点上并行运行deap_ga_onemax.py会导致4个不同的名人堂。在3个节点上运行会导致3个不同的名人堂,依此类推。这样,每个节点都有自己的名人堂。

如何获得一个包含所有节点结果的名人堂?

任何见解都会非常有帮助...

1 个答案:

答案 0 :(得分:0)

OP还对DEAP的github问题提出了这个问题。作为DEAP开发人员,我认为它在那里更适合,并且这里是对话的链接。

https://github.com/DEAP/deap/issues/285