如何只是更改一些参数值并行运行ipython笔记本? [英] How to run an ipython notebook in parallel just changing some parameter values?

查看:96
本文介绍了如何只是更改一些参数值并行运行ipython笔记本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个单元格的IPython笔记本,我想要并行运行几次,但只有一些参数(在笔记本电脑的单元格中定义)之间存在差异。最简单的方法是什么?

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?

我有一个12核心的工作站。每当我运行笔记本时,它只使用其中一个核心。我想使用其他内核来运行完全相同的笔记本,但对某些参数进行了一些修改。有可能吗?

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?

非常感谢

推荐答案

我其实然后找到了一种方法。

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()

在笔记本上面的代码中是一个python函数,它接收一个数字作为输入,获取此迭代的变量值并运行每个原始单元格。

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.

这篇关于如何只是更改一些参数值并行运行ipython笔记本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆