DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.76k stars 1.12k forks source link

Pickling is problematic #323

Open max3-2 opened 5 years ago

max3-2 commented 5 years ago

When pickling a dict with deap Individuals, unpickling is only possible when the Fitness and the Individuals have been created. This makes using those pickling tedious. This might be a duplicate o f PR#76. Has this been fixed or at least considered?

280 seems to have already implemented this

fmder commented 5 years ago

This is also true when pickling any other user class in Python.

Le lun. 31 déc. 2018 11 h 12, max3-2 notifications@github.com a écrit :

When pickling a dict with deap Individuals, unpickling is only possible when the Fitness and the Individuals have been created. This makes using those pickling tedious. This might be a duplicate o f PR#76. Has this been fixed or at least considered?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DEAP/deap/issues/323, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6rwmFlEiq1tgOHqThnmS7Jk6rFPpEAks5u-jdxgaJpZM4ZlhcB .

richban commented 5 years ago

@fmder how is possible to solve the pickling issue?

I am storing the best genome following way:

        with open('winner_{0}'.format(hof[0].key), 'wb') as winner:
            pickle.dump(hof[0], winner)

However the unpickling does not work:

genome = pickle.load(f)
AttributeError: Can't get attribute 'Individual' on <module 'deap.creator' from '/Users/richban/.local/share/virtualenvs/behavioral.neuroevolution-ViNSkuNA/lib/python3.7/site-packages/deap/creator.py'>

any suggestions?

fmder commented 5 years ago

Import the creator from your original script and make sure that class creation is made at the module level.

This is more of a pickling question than a deap question. You can get more information on user class pickling on stack overflow.