Search code examples
pythonpython-3.xanacondapymcpymc3

pymc3 not working, getting nan and none type errors using Anaconda3


EDIT: Solution found, in answers below. Leaving question up for others who may have the same problem.

I just installed pymc3, and it is only 'partially' working for me. I'm using Anaconda on 64bit installation on windows, but I don't think that is the issue (i.e., I don't think the issue is a need to switch to 32 bit anaconda).

Various examples are not working for me, so I tried working through this example: http://docs.pymc.io/notebooks/getting_started.html#A-Motivating-Example:-Linear-Regression

everything works fine until:

   with basic_model:
       # draw 500 posterior samples
       trace = pm.sample(500)

at that point, I get an error. Edit: I do have reason to believe it's loky, because I've gotten further by reinstalling theanos and something else. But I am still getting this:

C:\Users\Yurik\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Running on PyMC3 v3.4.1
WARNING (theano.gof.compilelock): Overriding existing lock by dead process '26576' (I am process '27640')
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_log__, beta, alpha]
Traceback (most recent call last):

  File "<ipython-input-1-1ef2ccded6b8>", line 1, in <module>
    runfile('C:/Users/Yurik/.spyder-py3/temp.py', wdir='C:/Users/Yurik/.spyder-py3')

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Yurik/.spyder-py3/temp.py", line 57, in <module>
    trace = pm.sample(500)

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\pymc3\sampling.py", line 442, in sample
    trace = _mp_sample(**sample_args)

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\pymc3\sampling.py", line 982, in _mp_sample
    traces = Parallel(n_jobs=cores, mmap_mode=None)(jobs)

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\joblib\parallel.py", line 962, in __call__
    self.retrieve()

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\joblib\parallel.py", line 865, in retrieve
    self._output.extend(job.get(timeout=self.timeout))

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\joblib\_parallel_backends.py", line 515, in wrap_future_result
    return future.result(timeout=timeout)

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\joblib\externals\loky\_base.py", line 431, in result
    return self.__get_result()

  File "C:\Users\Yurik\Anaconda3\lib\site-packages\joblib\externals\loky\_base.py", line 382, in __get_result
    raise self._exception

BrokenProcessPool: A process in the executor was terminated abruptly while the future was running or pending.

Solution

  • I finally figured it out! After tracing the functions, I noticed that loky was getting cores = None, and that there is an optional argument. So the example needs to have cores = 1 (or similar) included in the arguments for pm.sample, then it works! Like below

    with basic_model: 
       # draw 500 posterior samples 
       trace = pm.sample(500, cores=1)
    

    (though it's also worth noting I needed to install / reinstall a couple of the dependencies, theanos and mw64 or something like that even before I got to this point)