Description
Hi everyone,
I am using the parallel processing feature and am encountering and issue where if I define the fitness function using closure in a class (to pass additional data whilst respecting the number of arguments the function can take) and use parallel processing with the "process"
flag, no errors are raised and the program just stays stuck indefinitely. This does not happen when using "thread"
or when not using parallel processing.
I have made a simple example of the setup I have below to show how I define my fitness function.
import pygad
class Test:
def __init__(self):
self.data = 5
""" Input data needed for fitness function here """
def outer_fitness_func(self):
def fitness_func(solution, sol_idx):
"""calculations"""
fitness_value = self.data
return fitness_value
return fitness_func
test = Test()
ga_instance = pygad.GA(num_generations=10,
num_parents_mating=3,
sol_per_pop=5,
num_genes=10,
fitness_func=test.outer_fitness_func(),
parallel_processing=["process", 2])
if __name__ == '__main__':
ga_instance.run()
Not using "process"
is not feasible for my application as it significantly improves the performance. My current fix is to allow an extra argument to be passed in the fitness function and pass all my data through that. However, this is not very clean and I can still not include my fitness function into a class. Any solutions to this?