Exception pickling kernels
See original GitHub issueI get this error when pickling a kernel once it has been used by a GP. Since the exception doesn’t occur before this, I am assuming that the kernels are supposed to be picklable? The error is the same for other kernels I tried. It is also triggered by using copy.deepcopy
.
My intention was to save the unused kernel anyway, and so passing a copy to the GP solved my issue, but this might still be a bug that needs fixing?
#!/usr/bin/env python3
import GPy
import pickle
import numpy as np
import sys
print('python version = ' + sys.version)
print('GPy.__version__ = ' + GPy.__version__)
k = GPy.kern.Matern52(1)
print('before using')
pickle.loads(pickle.dumps(k))
print('k._name = ' + k._name)
gp = GPy.models.GPRegression(np.array([[1]]), np.array([[1]]), kernel=k)
print('after using')
print('k._name = ' + k._name)
print('saving')
saved = pickle.dumps(k)
print('loading')
pickle.loads(saved)
python version = 3.6.3 (default, Oct 3 2017, 21:45:48)
[GCC 7.2.0]
GPy.__version__ = 1.9.2
before using
k._name = Mat52
after using
k._name = Mat52
saving
loading
Traceback (most recent call last):
File "pickle_problem.py", line 20, in <module>
pickle.loads(saved)
File "/usr/local/lib/python3.6/dist-packages/paramz/parameterized.py", line 340, in __setstate__
super(Parameterized, self).__setstate__(state)
File "/usr/local/lib/python3.6/dist-packages/GPy/core/parameterization/priorizable.py", line 18, in __setstate__
super(Priorizable, self).__setstate__(state)
File "/usr/local/lib/python3.6/dist-packages/paramz/core/parameter_core.py", line 495, in __setstate__
super(Parameterizable, self).__setstate__(state)
File "/usr/local/lib/python3.6/dist-packages/paramz/core/indexable.py", line 56, in __setstate__
super(Indexable, self).__setstate__(state)
File "/usr/local/lib/python3.6/dist-packages/paramz/core/pickleable.py", line 125, in __setstate__
self.observers = ObserverList()
File "/usr/local/lib/python3.6/dist-packages/paramz/parameterized.py", line 330, in __setattr__
pnames = self.parameter_names(False, adjust_for_printing=True, recursive=False)
File "/usr/local/lib/python3.6/dist-packages/paramz/core/parameter_core.py", line 191, in parameter_names
names.extend([adjust(x.name) for x in self.parameters])
File "/usr/local/lib/python3.6/dist-packages/paramz/core/parameter_core.py", line 191, in <listcomp>
names.extend([adjust(x.name) for x in self.parameters])
File "/usr/local/lib/python3.6/dist-packages/paramz/core/nameable.py", line 63, in name
return self._name
AttributeError: 'Matern52' object has no attribute '_name'
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10
Top Results From Across the Web
Can't pickle <class 'decimal.Decimal'>: it's not the same object ...
I got this error when running in an jupyter notebook. I think the problem was that I was using %load_ext autoreload autoreload 2...
Read more >Python Tutorial: serialization with pickle - 2020 - BogoToBogo
The pickle.load() function takes a stream object, reads the serialized data from the stream, creates a new Python object, recreates the serialized data...
Read more >kedro.extras.datasets.pickle.PickleDataSet - Read the Docs
PickleDataSet loads/saves data from/to a Pickle file using an underlying filesystem (e.g.: local, S3, GCS). The underlying functionality is supported by the ...
Read more >42899b89-ebb0-4017-a713-b6d91df0f1f8.ipynb
By default, unpickling will raise an exception if it finds information in your pickle file that does not match the current Python source...
Read more >What's New In Python 3.8 — Python 3.11.1 documentation
When pickle is used to transfer large data between Python processes in order ... CancelledError now inherits from BaseException rather than Exception and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have run into the exact same problem. Unfortunately I can’t use the same work around though.
for my use case I didn’t actually require pickling kernels that have been used, so I restructured my code to copy the kernel and pass the copy to the GP instead, allowing the object holding the unused kernel to be pickled. This probably doesn’t help most cases though, sorry