I’m new to pymc3, just started looking to use it over the past week. I have been looking at a couple quick examples, but ran into runtimeerror when running sample. I only receive the error when I set cores >1, so this looks like a threading issue. Not sure if I have something installed wrong or if this is a true bug
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
import warnings
from pymc3 import Model, Normal, Uniform
from pymc3 import sample
warnings.filterwarnings("ignore")
radon = pd.read_csv('C:/Users\Craig/source/repos/pymc_test/radon.csv', index_col=0)
radon_hennepin = radon.query('county=="HENNEPIN"').log_radon
print(radon_hennepin.head())
with Model() as radon_model:
mu = Normal('mu',mu=0, sd=10)
sigma = Uniform('sigma', 0, 10)
with radon_model:
dist = Normal('dist', mu=mu, sigma=sigma, observed=radon_hennepin)
with radon_model:
samples = sample(1000, tune=1000, cores=4, random_seed=42)
When cores is set to 1 the code executes fine. However if the cores is set to anything greater than 1, like in the example above I receive the following error:
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, mu]
Traceback (most recent call last):
File "<ipython-input-5-afe32d11c49f>", line 1, in <module>
runfile('C:/Users/Craig/source/repos/pymc_test/pymc3_test_spyder.py', wdir='C:/Users/Craig/source/repos/pymc_test')
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Craig/source/repos/pymc_test/pymc3_test_spyder.py", line 22, in <module>
samples = sample(1000, tune=1000, cores=4, random_seed=42)
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\pymc3\sampling.py", line 437, in sample
trace = _mp_sample(**sample_args)
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\pymc3\sampling.py", line 965, in _mp_sample
chain, progressbar)
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\pymc3\parallel_sampling.py", line 361, in __init__
for chain, seed, start in zip(range(chains), seeds, start_points)
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\pymc3\parallel_sampling.py", line 361, in <listcomp>
for chain, seed, start in zip(range(chains), seeds, start_points)
File "C:\Users\Craig\Anaconda3\envs\envTF1\lib\site-packages\pymc3\parallel_sampling.py", line 251, in __init__
raise exc
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.
I’ve run the following code in both MS Visual Studio as well as Spyder. I have the following installed in the environment:
Python == 3.6
Pandas == 0.25.0
Numpy == 1.15.4
pymc3 == 3.7