-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
PicklingError with njobs>1 using DensityDist #1995
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
Comments
Multiprocessing requires everything passed to thread to be picklable. Lambdas defined in local namespace are not picklable. Hopefully it will work if you define density beforehand |
I see. Yep defining the function beforehand works. # add scatter to points
xdata = np.random.normal(xdata, 10)
ydata = np.random.normal(ydata, 10)
def loglike1(value):
return -1.5 * tt.log(1 + value**2)
def loglike2(value):
return -tt.log(tt.abs_(value))
with pm.Model() as model1:
# alpha = pm.Uniform('intercept', -100, 100)
alpha = pm.Normal('intercept', mu=0, sd=100)
# Create custom densities, you must supply logp
beta = pm.DensityDist('beta', loglike1, testval=0)
eps = pm.DensityDist('eps', loglike2, testval=1)
# Create likelihood
like = pm.Normal('y_est', mu=alpha + beta * xdata, sd=eps, observed=ydata)
trace = pm.sample(1e3, njobs=2) # Make sure not to draw too many samples Maybe this should be in the doc strings of |
Totally agreed. I had not known that lambdas are not picklable! (And have been using python for years)! |
To open an old thread. Lambda are pickleable with the package |
Problem is that pickling comes up when using multiprocessing through It looked like from some comments that importing Here's some code if you want to try to get it:
For what it is worth, I ran into this over the weekend when I needed a parameterized density distribution (subfunctions are also not pickleable). I had to write a |
Might be work asking https://github.com/mmckerns if he has any advice. |
While testing the model in #1994, I ran into a PicklingError on multiple jobs:
The model:
error output:
No problem if
njobs=1
The text was updated successfully, but these errors were encountered: