In [1]:
# You need to install the latest version of dask and distributed
# pip install git+https://github.com/dask/dask.git (--upgrade)
# pip install git+https://github.com/dask/distributed.git (--upgrade)

In [2]:
import sys
# Assuming we are in the notebook directory add this so that we can import the library
sys.path.append('..')

from abcpy.core import *
from abcpy.distributions import *
from distributed import Client

from dask.dot import dot_graph

In [3]:
c = Client()
c


Out[3]:
<Client: scheduler="127.0.0.1:54739" processes=8 cores=8>

In [10]:
tau = NumpyRV('tau', 'normal', 5)
values = tau.generate(9, batch_size=3)

# Draw the dask graph
dot_graph(values.dask)


Out[10]:

In [11]:
# You can see the dask graph dictionary with
values.dask


Out[11]:
{'getitem-2cf042c2098a6d1c684be549323904b1': (<function _operator.getitem>,
  ('tau', 3, 3),
  'data'),
 'dict-fb96e33c8f477a5742678665cbe5703c': (dict,
  [['data', (tuple, ['getitem-c10e54e306948bda142d38b2f3389945'])],
   ['index', 0],
   ['n', 3],
   ['random_state', 'set_substream-4fe42326f11e5cca4798d2a94e79355b']]),
 ('tau',
  0,
  3): (functools.partial(<function npr_op at 0x7f675c307bf8>, 'normal', (1,)), 'dict-fb96e33c8f477a5742678665cbe5703c'),
 'dict-20cdda89919c68898729a1c40088a652': (dict,
  [['data', (tuple, ['getitem-4e294198482a6ae0151a9900c16e9a45'])],
   ['index', 6],
   ['n', 3],
   ['random_state', 'set_substream-63c82ebd9d2cd724889c47c03bba8544']]),
 'getitem-4e294198482a6ae0151a9900c16e9a45': (<function _operator.getitem>,
  ('_tau_c0b9ce', 6, 3),
  'data'),
 'set_substream-4fe42326f11e5cca4798d2a94e79355b': (<function abcpy.core.set_substream>,
  0,
  6),
 'dict-a26b2d2d39b990e0c9700d4eb3b06c26': {'data': (), 'index': 6, 'n': 3},
 'dict-f3326c828e0692bb08326098f0f17ea6': (dict,
  [['data', (tuple, ['getitem-bfe0ecfedcf991f935a51beab6f0aaff'])],
   ['index', 3],
   ['n', 3],
   ['random_state', 'set_substream-873f392d1b8f432714f47d283416a7d0']]),
 ('_tau_c0b9ce',
  6,
  3): (<function abcpy.core.Constant.__init__.<locals>.<lambda>>, 'dict-a26b2d2d39b990e0c9700d4eb3b06c26'),
 'getitem-d12986e9128e506ba37a6c48653f4712': (<function _operator.getitem>,
  ('tau', 0, 3),
  'data'),
 'set_substream-873f392d1b8f432714f47d283416a7d0': (<function abcpy.core.set_substream>,
  0,
  7),
 ('tau',
  6,
  3): (functools.partial(<function npr_op at 0x7f675c307bf8>, 'normal', (1,)), 'dict-20cdda89919c68898729a1c40088a652'),
 ('tau',
  3,
  3): (functools.partial(<function npr_op at 0x7f675c307bf8>, 'normal', (1,)), 'dict-f3326c828e0692bb08326098f0f17ea6'),
 ('_tau_c0b9ce',
  3,
  3): (<function abcpy.core.Constant.__init__.<locals>.<lambda>>, 'dict-2becf81dced2380a1878763ebd35a32d'),
 'dict-2becf81dced2380a1878763ebd35a32d': {'data': (), 'index': 3, 'n': 3},
 ('_tau_c0b9ce',
  0,
  3): (<function abcpy.core.Constant.__init__.<locals>.<lambda>>, 'dict-1d0314ce433ee3f4ee4b92f1caf33b4d'),
 'set_substream-63c82ebd9d2cd724889c47c03bba8544': (<function abcpy.core.set_substream>,
  0,
  8),
 'getitem-c10e54e306948bda142d38b2f3389945': (<function _operator.getitem>,
  ('_tau_c0b9ce', 0, 3),
  'data'),
 'vstack-395e1f4f-ff1c-4394-96b4-d4eaed14f1bf': (<function numpy.core.shape_base.vstack>,
  (tuple,
   ['getitem-d12986e9128e506ba37a6c48653f4712',
    'getitem-2cf042c2098a6d1c684be549323904b1',
    'getitem-b34ba13c48690d4468e2079ffc64249f'])),
 'dict-1d0314ce433ee3f4ee4b92f1caf33b4d': {'data': (), 'index': 0, 'n': 3},
 'getitem-bfe0ecfedcf991f935a51beab6f0aaff': (<function _operator.getitem>,
  ('_tau_c0b9ce', 3, 3),
  'data'),
 'getitem-b34ba13c48690d4468e2079ffc64249f': (<function _operator.getitem>,
  ('tau', 6, 3),
  'data')}

In [13]:
# Finally compute the values
c.compute(values, sync=True)


Out[13]:
array([[ 4.68821633],
       [ 5.72900392],
       [ 5.21782079],
       [ 6.6905257 ],
       [ 4.53406263],
       [ 5.03282016],
       [ 5.09120472],
       [ 6.09128273],
       [ 3.05302969]])