GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

ga_instance.save will not work with tqdm example

Open mrh335 opened this issue 1 year ago • 2 comments

I am running the example on how to use TQDM. I have used this successfully in a prior version and installation, but when running my previous code or the example code, I receive the error: File C:\ProgramData\Anaconda3\envs\pygad_2_2_0-2\Lib\site-packages\cloudpickle\cloudpickle.py:1245 in dump return super().dump(obj)

TypeError: cannot pickle '_hashlib.HMAC' object

Pygad version 3.1.0 and also tried 3.2.0

This is the code that was run returning this result.

import pygad
import numpy
import tqdm

equation_inputs = [4,-2,3.5]
desired_output = 44

def fitness_func(ga_instance, solution, solution_idx):
    output = numpy.sum(solution * equation_inputs)
    fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
    return fitness

def on_generation_progress(ga):
    pbar.update(1)

num_generations = 100
with tqdm.tqdm(total=num_generations) as pbar:
    ga_instance = pygad.GA(num_generations=num_generations,
                           sol_per_pop=5,
                           num_parents_mating=2,
                           num_genes=len(equation_inputs),
                           fitness_func=fitness_func,
                           on_generation=on_generation_progress)

    ga_instance.run()

ga_instance.plot_result()

ga_instance.save("test")

mrh335 avatar Jan 10 '24 21:01 mrh335

The hash object cannot be pickled. It is an issue with the cloudpickle library used by PyGAD to pickle the pygad.GA objects.

ahmedfgad avatar Jan 27 '24 03:01 ahmedfgad

I see the same error when I try to use parallel_processing. Is there a workaround?

meono avatar Jul 09 '24 07:07 meono