1

我在用着

  • Linux 上的 Python 3.6.4 / Anaconda 自定义(64 位)[GCC 7.2.0]
  • 勺 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 个不同的名人堂,依此类推。这样,每个节点都有自己的名人堂。

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

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

4

1 回答 1

-1

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

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

于 2018-06-28T13:41:14.487 回答