CalebBell / thermo

Thermodynamics and Phase Equilibrium component of Chemical Engineering Design Library (ChEDL)
MIT License
594 stars 114 forks source link

Chemical serialize able #138

Closed cloasdata closed 9 months ago

cloasdata commented 10 months ago

@CalebBell, first of all thanks a lot for your works. I found that class chemical is not pickle able. AttributeError: Can't pickle local object 'Chemical.set_TP_sources.<locals>.<lambda>'

At the moment I work arround by removing chemical from state to pickle and later when loaded I construct it again. But it would be a lot easier not think about it at all.

May be this would be somehow possible. Other solution would be to use dill instead.

Thanks!

CalebBell commented 10 months ago

Hi @cloasdata, It does seem the lambda expression is the only thing stopping the pickling of the Chemical object. It seems reasonable to add a dedicated method for that lambda, I agree.

I don't think offering official support for pickling is in the roadmap today because there are lots of features in Thermo that will break it if you use them. Maintaining reliable pickling is a lot of work, and lambdas do have lots of valid uses.

However, I will try to patch it up enough that pickling Chemical works out of the box anyway for the next release.

Sincerely, Caleb

cloasdata commented 10 months ago

Hi Caleb,

if it have to much impact, then just pass this request because it is not super urgent, as chemicals are working on string keys it is not a problem to have a wrapper/adapter to make them persistent. Anyway, thanks very much! Simon

CalebBell commented 9 months ago

This is now resolved in the latest version of Thermo!