Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithms cannot be pickle'd #425

Closed
fschlimb opened this issue Dec 14, 2020 · 4 comments · Fixed by #2067
Closed

Algorithms cannot be pickle'd #425

fschlimb opened this issue Dec 14, 2020 · 4 comments · Fixed by #2067
Labels
bug Something isn't working

Comments

@fschlimb
Copy link
Contributor

Describe the bug
Exception is raised when pickling algorithm objects.

To Reproduce

import daal4py as d4p
import pickle
a=d4p.qr()
p=pickle.dumps(a)

Expected behavior
It should create a pickle buffer

Output/Screenshots

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "stringsource", line 2, in _daal4py.qr.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

Environment:

  • OS: Linux
  • Version: 2020.3
@fschlimb fschlimb added the bug Something isn't working label Dec 14, 2020
@alejandrods
Copy link

Is there any update on this? I am facing the same error with:

Python 3.8
daal4py 2021.4.0

@Alexsandruss
Copy link
Contributor

Alexsandruss commented Nov 16, 2021

There is no obvious reason to pickle objects like d4p.{qr, pca, *_training, *_prediction} since they are mostly wrappers for computation methods. Results of algorithms are correctly working with pickle:

import daal4py as d4p
import numpy as np
import pickle

x = np.random.uniform(size=(1000, 8))

alg = d4p.qr()
res = alg.compute(x)

p = pickle.dumps(res)
loaded_res = pickle.loads(p)
print((loaded_res.matrixQ == res.matrixQ).all(), (loaded_res.matrixR == res.matrixR).all())

Output: True, True

import daal4py as d4p
import numpy as np
from sklearn.datasets import make_classification
import pickle

x, y = make_classification()

alg = d4p.svm_training()
res = alg.compute(x, y.reshape((y.shape[0], 1)))

p = pickle.dumps(res)
loaded_res = pickle.loads(p)
print((loaded_res.model.SupportVectors == res.model.SupportVectors).all())

Output True

@fschlimb
Copy link
Contributor Author

What do you mean? Two people asked for the feature. Why is that not obvious?

A very obvious reason is when you write a generic code accepting an algorithm to call, e.g. if the algorithm is a n argument. You cannot let a remote worker execute such a function if the algorithm cannot be pickle'd.

@fschlimb
Copy link
Contributor Author

Even worse: the current lack of pickle support makes any class/object with a algorithm member unpickle'able.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants