Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ga_instance.save will not work with tqdm example #262

Open
mrh335 opened this issue Jan 10, 2024 · 2 comments
Open

ga_instance.save will not work with tqdm example #262

mrh335 opened this issue Jan 10, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mrh335
Copy link

mrh335 commented Jan 10, 2024

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")
@ahmedfgad ahmedfgad added the bug Something isn't working label Jan 27, 2024
@ahmedfgad
Copy link
Owner

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

@meono
Copy link

meono commented Jul 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants