The python implementation of the Stochastic Self-Consistent Harmonic Approximation (SSCHA).
GNU General Public License v3.0
55
stars
21
forks
source link
sscha.Utilities.save_binary throws TypeError: cannot pickle '_thread.lock' object when trying to save sscha.Relax.SSCHA object into file #114
Open
Kurufinve opened 1 year ago
Dear developers,
It was found that when trying to save sscha.Relax.SSCHA object into file after the relaxation was ended, the pickle module throws the following error:
File ~/miniconda3/lib/python3.9/site-packages/sscha/Utilities.py:664, in save_binary(object, filename) 661 if not sscha.Parallel.am_i_the_master(): 662 return --> 664 pickle.dump(object, open(filename, "wb"))
TypeError: cannot pickle '_thread.lock' object
Searching for the methods for fixing this error I found that there is another python module for dumping objects into binary files named "dill"
With dill, the sscha.Relax.SSCHA object was successfully dumped into the file and then loaded from it.
The code example:
Saving relax object with dill
import dill filename = 'relax_fix_volume.bin' dill.dump(relax, open(filename, "wb"))
Loading the relax object with dill
filename = 'relax_fix_volume.bin' relax_loaded= dill.load(open(filename, "rb")) relax_loaded.minim.finalize() relax_loaded.minim.plot_results()
I think, it will be better to use dill instead of pickle in the sscha.Utilities.save_binary wrapper in the future releases!
With best regards, Daniil Poletaev