Skip to content

ga_instance.save will not work with tqdm example #262

Open

Description

@mrh335

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")

Activity

  1. ahmedfgad commented on Jan 27, 2024

    @ahmedfgad
    Owner

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

  2. meono commented on Jul 9, 2024

    @meono

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions