2016-11-29 112 views
0

我已經成功地顯現了幾天dask對象了,但我只是重新啓動我的筆記本Jupyter內核和正在運行到一個KeyError,我似乎無法調試。DASK形象化()KeyError異常

之前我重新啓動的內核,下面的代碼工作正常:

def sigmoid(x): 
    '''Sigmoid function of x.''' 
    return 1/(1+da.exp(-x)) 

X = da.from_array(np.random.random((4,2)), chunks=2) 
beta = np.ones((2,1)) 

## 
p = (X.dot(beta)).map_blocks(sigmoid) 
W = da.diag((p*(1-p))[:,0]) 
hessian = da.dot(X.T.dot(W),X) 
hessian.visualize() 

但現在當我跑,我得到以下回溯:

KeyError         Traceback (most recent call last) 
<ipython-input-62-660a47cb4654> in <module>() 
     7 W = da.diag((p*(1-p))[:,0]) 
     8 hessian = dot(X.T.dot(W),X) 
----> 9 hessian.visualize() 

.../anaconda3/anaconda/lib/python3.5/site-packages/dask/base.py in visualize(self, filename, format, optimize_graph, **kwargs) 
    59   """ 
    60   return visualize(self, filename=filename, format=format, 
---> 61       optimize_graph=optimize_graph, **kwargs) 
    62 
    63  def compute(self, **kwargs): 

.../anaconda3/anaconda/lib/python3.5/site-packages/dask/base.py in visualize(*args, **kwargs) 
    234  dsk = merge(dsks) 
    235 
--> 236  return dot_graph(dsk, filename=filename, **kwargs) 
    237 
    238 

.../anaconda3/anaconda/lib/python3.5/site-packages/dask/dot.py in dot_graph(dsk, filename, format, **kwargs) 
    217  dask.dot.to_graphviz 
    218  """ 
--> 219  g = to_graphviz(dsk, **kwargs) 
    220 
    221  fmts = ['.png', '.pdf', '.dot', '.svg', '.jpeg', '.jpg'] 

.../anaconda3/anaconda/lib/python3.5/site-packages/dask/dot.py in to_graphviz(dsk, data_attributes, function_attributes, rankdir, graph_attr, node_attr, edge_attr, **kwargs) 
    130    if func_name not in seen: 
    131     seen.add(func_name) 
--> 132     g.node(func_name, label=task_label(v), shape='circle', 
    133      **function_attributes.get(k, {})) 
    134    g.edge(func_name, k_name) 

.../anaconda3/anaconda/lib/python3.5/site-packages/dask/dot.py in task_label(task) 
    29  if hasattr(func, 'funcs'): 
    30   if len(func.funcs) > 1: 
---> 31    return '{0}(...)'.format(funcname(func.funcs[0])) 
    32   else: 
    33    head = funcname(func.funcs[0]) 

KeyError: 0 

這似乎有一些標籤失蹤其中一個任務或類似的東西?

編輯:其實,重現錯誤,你需要進行如下修改雙曲線函數:

from multipledispatch import dispatch 

@dispatch(da.Array) 
def sigmoid(x): 
    '''Sigmoid function of x.''' 
    return 1/(1+da.exp(-x)) 

@dispatch(np.ndarray) 
def sigmoid(x): 
    '''Sigmoid function of x.''' 
    return 1/(1+np.exp(-x)) 

回答

0

感謝您的可重複的例子。

不幸的是,這個運行對我罰款:

In [1]: import numpy as np 

In [2]: import dask.array as da 

In [3]: from multipledispatch import dispatch 
    ...: 
    ...: @dispatch(da.Array) 
    ...: def sigmoid(x): 
    ...:  '''Sigmoid function of x.''' 
    ...:  return 1/(1+da.exp(-x)) 
    ...: 
    ...: @dispatch(np.ndarray) 
    ...: def sigmoid(x): 
    ...:  '''Sigmoid function of x.''' 
    ...:  return 1/(1+np.exp(-x)) 
    ...: 

In [4]: pdb 
Automatic pdb calling has been turned ON 

In [5]: def sigmoid(x): 
    ...:  '''Sigmoid function of x.''' 
    ...:  return 1/(1+da.exp(-x)) 
    ...: 
    ...: X = da.from_array(np.random.random((4,2)), chunks=2) 
    ...: beta = np.ones((2,1)) 
    ...: 
    ...: ## 
    ...: p = (X.dot(beta)).map_blocks(sigmoid) 
    ...: W = da.diag((p*(1-p))[:,0]) 
    ...: hessian = da.dot(X.T.dot(W),X) 
    ...: hessian.visualize() 
    ...: 
Out[5]: <IPython.core.display.Image object> 

它的工作,直到你重新啓動的東西是一個有點奇怪的事實。你的環境可能有些問題?

+0

嗯,你對重複性的評論讓我思考 - 我粘貼的代碼實際上*不會*爲我運行!我編輯了這篇文章,完全重現了我正在使用的代碼,現在我懷疑你會有'KeyError'。 – chriswhite

+0

仍然似乎爲我工作 – MRocklin

+0

看起來像你在單元塊[5]中用一個新的dask-only sigmoid函數覆蓋dispatch sigmoid。 – chriswhite