Weird error: 'The kernel appears to have died. It will restart automatically'

Hi everybody!
In the case of writing new distribution in pymc3, I’m trying to write a defined distribution in the program to compare its result with pymc3 itself (in this way, I can extend the strategy to undefined distributions). For this approach, my choice was exponential distribution and my code is:

Blockquote
import theano.tensor as tt
def expo(lam):
def logp(x):
return tt.log(lam) -lam*x
return logp
with pm.Model():
s = pm.Uniform(‘s’,0,10)
obs = pm.DensityDist(‘obs’,expo(s),observed = 3)
trace = pm.sample(20000)
with pm.Model():
s1 = pm.Uniform(‘s1’,0,10)
obs1 = pm.Exponential(‘obs1’,lam = s1,observed = 3)
trace1 = pm.sample(20000)
sns.distplot(trace[‘s’])
sns.distplot(trace1[‘s1’])
plt.legend([‘khodam’,‘py’])
plt.show()

when I run this code, suddenly my kernel dies!! with this message on the display: ‘The kernel appears to have died. It will restart automatically’. Would you please help me to solve this?!

Thank you

1 Like

Are you on Windows? There are common issues with parallel sampling on Windows that could be behind the kernel dying. You can try setting cores = 1 in pm.sample and see it solves it.

2 Likes

yes, my OS is windows and (again) yess it worked!.. thank you
Could you tell me what is the role of ‘cores’ in the code?? why should I give 1 to this value?

1 Like

Cores means how many cpu cores will be used for sampling. By default this is 4, meaning PyMC3 will sample 4 chains in parallel. Unfortunately, this often fails on Windows. If you set it cores to 1, PyMC3 will still sample 4 chains, but one at a time.

2 Likes