I want to save an object ('clustering') of the following type in order to use it later. The object has the type
<class 'pyemma.coordinates.clustering.kmeans.KmeansClustering'>
I tried using pickle, but the loaded object leads to an error.
n_clusters = 3
clustering = coor.cluster_kmeans(Y, k=n_clusters, max_iter=100, tolerance=1e-10, fixed_seed=True)
with open("clustering.file", "wb") as f:
pickle.dump(clustering, f, pickle.HIGHEST_PROTOCOL)
with open("clustering.file", "rb") as f:
clustering=pickle.load(f)
clustering.save_traj()
dtrajs = clustering.dtrajs # get discrete trajectories
This is the error:
File "pyemma_dG.py", line 102, in <module>
dtrajs = clustering.dtrajs # get discrete trajectories
File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/clustering/interface.py", line 101, in dtrajs
self._dtrajs = self.assign(stride=1)
File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/clustering/interface.py", line 217, in assign
mapped = self.get_output(stride=stride, chunk=self.chunksize, skip=skip)
File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/data/_base/transformer.py", line 182, in chunksize
return self.default_chunksize
File "/home/local/andtos-loc/anaconda3/lib/python3.5/site-packages/pyemma/coordinates/data/_base/iterable.py", line 74, in default_chunksize
if self._default_chunksize is None:
AttributeError: 'KmeansClustering' object has no attribute '_default_chunksize'
1 Answer 1
Unfortunately this old version of PyEMMA did not support pickling complex objects in the coordinates subpackage. Versions higher than 2.5 support it correctly. I would recommend using the builtin save and load functionality as it also provides very fast and io efficient array serialization with HDF5.
answered Aug 13, 2019 at 6:38
marscher
8501 gold badge7 silver badges24 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py