Wednesday, March 29, 2017

Running PaCAL on OSX with conda

PaCAL is a great library for performing arithmetic on probabilistic random variables just like you do with ordinary program variables. Here is a more detailed paper on PaCAL.

There are a couple of gotchas setting it up on OSX with conda:

  • Requires Python 2.7.x (3.x not supported as of March 2017)
  • Required dependencies: numpy matplotlib sympy scipy
  • Workaround for "RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework".

Here are the steps to set up PaCAL under a conda environment on OSX:

$ conda create -n pacal python=2.7
$ source activate pacal

(pacal) $ pip install numpy matplotlib sympy scipy
(pacal) $ pip install pacal

(pacal) $ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
>>>
>>> # This TkAgg bit is to prevent the OSX 'Python is not installed as a framework' error.
>>> import matplotlib as mpl
>>> mpl.use('TkAgg')
>>>
>>> from pacal import *
Compiled interpolation routine not available
Compiled sparse grid routine not available
>>> dL = UniformDistr(1,3)
>>> L0 = UniformDistr(9,11)
>>> dT = NormalDistr(1,1)
>>> K = dL / (L0 * dT)
>>> K.plot()
>>> show()