ahmedfgad / GeneticAlgorithmPython

Source code of PyGAD, a Python 3 library for building the genetic algorithm and training machine learning algorithms (Keras & PyTorch).
https://pygad.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.79k stars 451 forks source link

Multi-Objective Optimization and parallel_processing #236

Closed lumy closed 8 months ago

lumy commented 9 months ago

It's seem you can run parrallel processing and multi objective at the same time, if you run this minimal code


def func(a, b, c):
  return [0.25, 0.75, 0.0, 0.5]

def test():
    ga_instance = pygad.GA(
            num_generations=generation,
            num_parents_mating=180,
            fitness_func=func,
            save_solutions=False,
            allow_duplicate_genes=False,
            parallel_processing=["process", 10],
            parent_selection_type="nsga2",
            num_genes=256, sol_per_pop=256,
    )
    ga_instance.run()

you get this error

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Traceback (most recent call last):
  File "/home/lumy/.local/lib/python3.9/site-packages/pygad/pygad.py", line 1790, in cal_pop_fitness
    if pop_fitness[sol_idx] == "undefined":
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

When you look the type of pop_fitness[sol_idx] it's not anymore an instance of List (as we could except because fitness_func return a list) but an numpy.ndarray And numpy doesn't allow that

is this a normal behavior ?