Reputation: 51
I am learning to use PyMC3. However, whenever I try to run an MCMC simulation in Spyder 4.0.0 , I get the following RuntimeError:
RuntimeError: The communication pipe between the main process and its spawned children is broken. In Windows OS, this usually means that the child process raised an exception while it was being spawned, before it was setup to communicate to the main process. The exceptions raised by the child process while spawning cannot be caught or handled from the main process, and when running from an IPython or jupyter notebook interactive kernel, the child's exception and traceback appears to be lost. A known way to see the child's error, and try to fix or handle it, is to run the problematic code as a batch script from a system's Command Prompt. The child's exception will be printed to the Command Promt's stderr, and it should be visible above this error and traceback. Note that if running a jupyter notebook that was invoked from a Command Prompt, the child's exception should have been printed to the Command Prompt on which the notebook is running.
As an example, I am using a copy-paste from the first example of the PyMC3 'Getting Started' tutorial (https://docs.pymc.io/notebooks/getting_started.html), however I seem to get this error no matter which model I use. I only get an error when running the pm.sample()
function line. I have tried using a new virtual environment, and even removing and reinstalling Python/Anaconda from my computer. Interestingly, when I run the programme in Jupyter - it works. Any ideas what's going on?
# True parameter values
alpha, sigma = 1, 1
beta = [1, 2.5]
# Size of dataset
size = 100
# Predictor variable
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2
# Simulate outcome variable
Y = alpha + beta[0]*X1 + beta[1]*X2 + np.random.randn(size)*sigma
basic_model = pm.Model()
with basic_model:
# Priors for unknown model parameters
alpha = pm.Normal('alpha', mu=0, sigma=10)
beta = pm.Normal('beta', mu=0, sigma=10, shape=2)
sigma = pm.HalfNormal('sigma', sigma=1)
# Expected value of outcome
mu = alpha + beta[0]*X1 + beta[1]*X2
# Likelihood (sampling distribution) of observations
Y_obs = pm.Normal('Y_obs', mu=mu, sigma=sigma, observed=Y)
with basic_model:
# draw 500 posterior samples
trace = pm.sample(500)
Upvotes: 1
Views: 947
Reputation: 27
try this:
with basic_model:
# draw 500 posterior samples
trace = pm.sample(500, cores=1)
Upvotes: 2