The user-defined function potential is not recognised during %time potential(cluster) in the non-Dask, numpy version. I think the problem arises in the function distances that is called within the potential function.
Minimal Complete Verifiable Example:
import numpy as np
# make a random collection of particles
def make_cluster(natoms, radius=40, seed=1981):
np.random.seed(seed)
cluster = np.random.normal(0, radius, (natoms,3))-0.5
return cluster
def lj(r2):
sr6 = (1./r2)**3
pot = 4.*(sr6*sr6 - sr6)
return pot
# build the matrix of distances
def distances(cluster):
diff = cluster[:, np.newaxis, :] - cluster[np.newaxis, :, :]
mat = (diff*diff).sum(-1)
return mat
# the lj function is evaluated over the upper triangle
# after removing distances near zero
def potential(cluster):
d2 = distances(cluster)
dtri = np.triu(d2)
energy = lj(dtri[dtri > 1e-6]).sum()
return energy
cluster = make_cluster(int(7e3), radius=500)
%time potential(cluster)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<timed eval> in <module>
NameError: name 'potential' is not defined
What happened:
The user-defined function
potential
is not recognised during%time potential(cluster)
in the non-Dask, numpy version. I think the problem arises in the functiondistances
that is called within thepotential
function.Minimal Complete Verifiable Example:
Environment:
I am using the binder notebook