我在一个简单的Python程序中遇到了一个名称空间问题:有人能给我指出正确的方向吗
import numpy as np
import simple_sim
from IPython.parallel import Client
prescale_steps = np.linspace(0.5, 1.5, 101)
val = []
c = Client()
dview = c[:]
dview.execute('import simple_sim')
dview.execute('from numpy import *')
dview['prescale_steps'] = prescale_steps
dview['val'] = val
detuning_steps = np.linspace(-11,11,101)
def fid(det):
for p in prescale_steps:
tlist, ret = simple_sim.simple_simulation(pulse_file='/home/andreas/Dropbox/puls25p8gn15map.mat', pulse_length=0.5, gamma=0, detuning=det, prescale=p)
val.append(np.array([d,p,ret[-1]]))
return val
lview = c.load_balanced_view()
res = lview.map(fid, detuning_steps)
a = res.get()
a = np.asarray(a)
总是引发错误:global name 'simple_sim' is not defined
,尽管它应该被定义,不是吗?你知道吗
确保
simple_sim
位于ipython引擎的路径中,而不仅仅是ipython shell。你知道吗也就是说,如果
simple_sim.py
在~/mydir/
中,您需要在~/mydir/
中运行ipcluster start n=4
,或者在$PYTHON_PATH
中有~/mydir
,以便shell运行ipcluster
。你知道吗不是100%确定,但可能是因为简单的sim卡不在网站包中或与dview不在同一文件夹中。换句话说,dview找不到简单的sim模块,因此会产生错误。然而,如果情况并非如此,我不确定是什么导致了这种错误。你知道吗
相关问题 更多 >
编程相关推荐