简体   繁体   English

ipython并行中的异步求值

[英]Asynchronous evaluation in ipython parallel

Since the awesome 1.0.0 release I've been playing around with iPython parallel interface. 自从1.0.0版发布以来,我一直在使用iPython并行接口。 What I'm trying to do is to set up a asynchronous stochastic gradient descent system. 我正在尝试做的是建立一个异步随机梯度下降系统。 The way I see it, I want to send a function to all the nodes and get the results as they come out. 我的看法是,我想向所有节点发送一个函数,并在它们出来时得到结果。 From what I was able to implement and glance from the documentation the standard views implemented don't really support that. 从我能够实现的内容和文档中看,实现的标准视图并不能真正支持这一点。 The get(timeout) method would do that, but you can't really loop through every entry in a <ASync_result> object using a timeout. get(timeout)方法可以做到这一点,但是您实际上不能使用超时循环遍历<ASync_result>对象中的每个条目。 The way I managed to get it running was the following 我设法使其运行的方法如下

c = Client()
calls = []
for i,j in enumerate(args):
    calls.append( c[ i % len( c.ids ) ].apply( f, j ) )

while condition:
    dels = []
    for i,j in enumerate( calls ):
         try:
             print j.get(0.01) #or some other timeout
             dels.append( i ) #I keep track of the calls that have been called
             #do something with the last result, throw a new call
             calls.append( c[ i % len(c.ids) ].apply( f, argument )
         except:
             pass

    for i,d in enumerate( dels ):
         del calls[ d - i ] #delete gotten calls

    #evaluate stopping condition

Now, before you all go screaming that this is horrible code and a stupid way to do that, I know it. 现在,在大家大声疾呼这是可怕的代码和愚蠢的做法之前,我知道这一点。 I could make this particular way of doing it nicer, but I'm just wondering if there is some built-in way of doing something similar in IPython.parallel. 我可以使这种特殊的方法做得更好,但是我只是想知道在IPython.parallel中是否有某种内置的方法来做类似的事情。

Thanks in advance to anyone taking the time. 在此先感谢您抽出宝贵的时间。

Best, Al. 最好,Al。

You can create multiple async calls, and then iterate through them. 您可以创建多个异步调用,然后遍历它们。

c = Client()
dview = c[:]
asyncs = [dview.map_async(f, [arg]) for arg in args]
while asyncs:
    for async in asyncs[:]:
        if async.ready():
            asyncs.remove(async)
            print async.result[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM