I was trying SCOOP for multi processing along with Constraint Handling.
I simply combined examples used in DEAP documentation for Constraint Handling and SCOOP
I faced two issues, which is mentioned below -
When using toolbox.decorate to apply DeltaPenalty along with 'evalFct function, i get SCOOP error as
WARNING Pickling Error: Can't pickle <function evalFct at 0x000001E19A71B048>: it's not the same object as main.evalFct
I commented below 'decorate' code and run program:
toolbox.decorate("evaluate", tools.DeltaPenalty(feasible, 7.0, distance))
This time program ran but it took a lot of time than it took without using SCOOP (i.e. simply commented toolbox.register("map", futures.map)
Attaching the program for reference
------------------------------------------------
from math import sin
from deap import base, creator, tools
import random
import numpy as np
import math
from deap import algorithms
import matplotlib.pyplot as plt
import seaborn as sns
from scoop import futures
Hi Team,
I was trying SCOOP for multi processing along with Constraint Handling.
I simply combined examples used in DEAP documentation for Constraint Handling and SCOOP
I faced two issues, which is mentioned below -
When using toolbox.decorate to apply DeltaPenalty along with 'evalFct function, i get SCOOP error as WARNING Pickling Error: Can't pickle <function evalFct at 0x000001E19A71B048>: it's not the same object as main.evalFct
I commented below 'decorate' code and run program: toolbox.decorate("evaluate", tools.DeltaPenalty(feasible, 7.0, distance)) This time program ran but it took a lot of time than it took without using SCOOP (i.e. simply commented toolbox.register("map", futures.map)
Attaching the program for reference
------------------------------------------------
from math import sin from deap import base, creator, tools import random import numpy as np import math from deap import algorithms import matplotlib.pyplot as plt import seaborn as sns from scoop import futures
def evalFct(individual):
Evaluation function for the individual.
def feasible(individual):
Feasibility function for the individual. Returns True if feasible False otherwise.
def distance(individual):
A distance function to the feasibility region.
creator.create("FitnessMax", base.Fitness, weights=(1.0,)) creator.create("Individual", list, fitness=creator.FitnessMax)
toolbox = base.Toolbox() toolbox.register("attr_float", random.uniform, 0, 10) toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_float, 1) toolbox.register("population", tools.initRepeat, list, toolbox.individual)
genetic operators:
toolbox.register("select", tools.selTournament, tournsize=2) toolbox.register("mate", tools.cxSimulatedBinaryBounded, low=0, up=10, eta=20) toolbox.register("mutate", tools.mutPolynomialBounded, low=0, up=10, eta=20, indpb=0.05) toolbox.register("evaluate", evalFct) toolbox.decorate("evaluate", tools.DeltaPenalty(feasible, 7.0, distance)) toolbox.register("map", futures.map)
Genetic Algorithm flow:
def main():
if name == "main": main()
-------------------------------------------