How to run an ipython notebook in parallel just changing some parameter values?

微笑、不失礼 提交于 2019-12-06 06:38:09

问题


I have an IPython notebook with multiple cells that I want to run several times in parallel with only a difference on some parameters (which are defined inside on of the notebook's cells). What is the easiest way of doing it?

I have a workstation with 12 cores. whenever I run a notebook it only uses one of the cores. I want to use the other cores to run the exact same notebook but with some modifications of some parameters. Is it possible?

Thank you very much


回答1:


I actually then found a way to do it.

import multiprocessing
list_of_variables=something #a 2D numpy array with all your combinations of variable values, 
             #each row has a different combination of parameter values
number_of_combinations=shape(list_of_variables)[0] #number of rows
def notebook(i):
    variables=list_of_variables[i,:]
    #all your code here
pool = multiprocessing.Pool(processes=n)  # Create a pool with n workers.
pool.map(notebook,range(number_of_combinations)) 
pool.close()
pool.join()

in the code above notebook is a python function that receives as input a number, get the variables values for this iteration and runs every original cell.



来源:https://stackoverflow.com/questions/18871376/how-to-run-an-ipython-notebook-in-parallel-just-changing-some-parameter-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!