Open neuronicprogrammer opened 11 years ago
Unfortunately interacting with Nengo using pydev and other traditional Python development tools is difficult at the moment. We have a lot of Java dependencies, one of which is Jython, which we include a version of; I'm not sure how you would run Nengo with a system's Jython. Sorry! This is just outside of our technical limitations right now, and with the tools that we've chosen to build Nengo with.
If you're adamant about doing this, and figure out a way to do it, I'd really appreciate knowing how you did it! I suspect that what you would need to do is set up a Run Configuration from within Eclipse that does something similar to how we run Nengo in the release version:
Sorry there isn't a straightforward answer to this. Once I have some time, I'm hoping to make the process of running and debugging Nengo more flexible.
It's not the best integration (I don't think debugging or anything like that will work), but if you just want to be able to run nengo scripts from eclipse, then that can be done. The things that need to be added to the path are:
sys.path.append("<nengo installation>/simulator/bin")
for f in os.listdir("<nengo installation>/simulator/lib"):
if f.endswith(".jar"):
sys.path.append("<nengo installation>/simulator/lib/%s" % f)
You will also need to install a local copy of Jython (we use version 2.5; others may work, but I would recommend that to be safe), hook that up to eclipse, and then execute your script as a Jython run.
Thanks for the assistance on this. I actually got it working by adding the jar files using eclipse gui
Right click your Project Properties -> PyDev PYTHONPATH -> External Libraries
add the nengo-nnnn.jar everything in lib and everything in python/jar
I am using the jython.jar file provided with the nengo distribution
I can get everything to work that is not commeneted out in the code below except that net.view() displays a window but it is missing the simulation play button.
The code below may contain logic errors as I am still getting use to the nengo jar file interfaces
import sys
sys.path.append('/Users/dir1/dir2/simulators/Nengo/nengo-5f37d63/python')
import nef
import ca.nengo.util.MU as MU
print "MU has the following attributes: "
print ', '.join(i for i in dir(MU) if not i.startswith('__'))
# Compute the weight matrix for a projection p
# a projection is the link between two nodes that NEFEnsembles
# This does not work if one of the two nodes is an input
def myweights(p):
print "Calculating weights for a projection in the network " + p.getNetwork().name
print "Calculating weights for the projection that connects from node "+p.origin.node.name+" to node "+p.termination.node.name
if isinstance(p.origin.node, ca.nengo.model.nef.impl.NEFEnsembleImpl) and isinstance(p.termination.node, ca.nengo.model.nef.impl.NEFEnsembleImpl):
print "The origin node and termination node of this projection are both NEFEnsembles"
else:
print "Either the origin node or termination node of this projection is NOT a NEFEnsemble: you cannot calculate the weights"
return False
network = p.getNetwork()
print "The network is: "
print network
transform = p.termination.transform
print "The transform is: "
print transform
decoder = p.origin.getDecoders()
print "The decoder is: "
print decoder
print len(decoder)
encoder = p.termination.node.getEncoders()
print "The raw encoder is: "
print encoder
print len(encoder)
radii = p.termination.node.getRadii()[0]
print "The radii is: "
print radii
# It is assumed that the network has no overall scale factor or this scale factor is 1
scaled_encoder = MU.prod(encoder,1.0/radii)
print "The scaled_encoder is: "
print scaled_encoder
print len(p.termination.node.nodes)
for i,n in enumerate(p.termination.node.nodes):
print "The scale factor for the "+str(i)+"th neuron is "+str(n.scale)
for j in range(len(scaled_encoder[i])):
#print scaled_encoder[i][j]
# It appears that n.scale is just the encoder array
scaled_encoder[i][j] = scaled_encoder[i][j]*n.scale
print "The i= "+str(i)+" j="+str(j)+" scaled encoder is "+str(scaled_encoder[i][j])
decoder_t = MU.transpose(decoder)
print decoder_t
#1x1x1x5=1x5
transformed_decoder = MU.prod(transform,decoder_t)
print transformed_decoder
# 5x1x1x5=5x5
weights = MU.prod(scaled_encoder,transformed_decoder)
print "The weights calculated by myweights are: "
print weights
return weights
print "nef successfully imported"
net=nef.Network('Test Network')
# constant inout
#input=net.make_input('input',values=[1])
# Random sine wave input
input=net.make_fourier_input('input',dimensions=1,base=0.1,high=10,power=0.5,seed=0)
A=net.make('A',neurons=5,dimensions=1)
B=net.make('B',neurons=5,dimensions=1)
net.connect(input,A)
"""
def print_weights(w):
print w
net.connect('A','B',weight_func=print_weights)
"""
def square(x):
return x[0]*x[0]
net.connect(A,B,func=square)
net.add_to_nengo()
#net.view()
"""
t=0.2
dt=0.2
net.run(2.0)
print "simulation time step"
"""
import ca.nengo
import ca.nengo.util.MU as MU
print "Listing all nodes"
for node in net.network.nodes:
print "current node is "+node.name
# the following can only be done for nodes that are NEFEnsebles
#if node.name !='input':
if isinstance(node, ca.nengo.model.nef.impl.NEFEnsembleImpl):
print "This node is a NEFEnsemble"
print "This node contains "+str(node.neurons)+" other nodes (neurons) "
print node.nodes
mynodes = node.nodes
print "Here is a list of the nodes (neurons) in this ensemble: "
for i, n in enumerate(mynodes):
print "node number "+str(i)+" is named "+n.name+" its hash name is "
print n
print "It has a bias value of "+str(n.bias)
else:
print "This node is not an NEFEnsemble"
print "Listing all projections"
for p in net.network.projections:
print "This projection has a hashed name of:"
print p
print "This projection connects from node "+p.origin.node.name+" to node "+p.termination.node.name
if isinstance(p.origin.node, ca.nengo.model.nef.impl.NEFEnsembleImpl):
print "The origin node of this projection is a NEFEnsemble"
else:
print "The origin node of this projection is NOT a NEFEnsemble"
myw = p.getWeights()
print "The weights matrix of this projection is: "
print myw
print p.origin
print p.termination.node.getEncoders()
# the node A is a basic origin and hence has no decoders
if isinstance(p.origin.node, ca.nengo.model.nef.impl.NEFEnsembleImpl):
print "The decoder for "+p.origin.node.name+" is:"
print p.origin.getDecoders()
else:
print p.origin.node.name+" has no decoder because it is not a NEFEnsemble"
print p.termination.transform
print "termination tau= "+str(p.termination.tau)
print "Listing of all connections for projections between NEFEnsembles: "
if isinstance(p.origin.node, ca.nengo.model.nef.impl.NEFEnsembleImpl) and isinstance(p.termination.node, ca.nengo.model.nef.impl.NEFEnsembleImpl):
for i in range(p.origin.node.neurons):
for j in range(p.termination.node.neurons):
print p.origin.node.name+str(i)+" to "+p.termination.node.name+str(j)
else:
print "This projection is not between NEFEnsembles"
print "Setting up logging..."
log = net.log()
log.add('A')
log.add('B')
# Cannot log an inout node
#log.add('input')
net.run(1.0)
print "log has these attributes "
print ', '.join(i for i in dir(log) if not i.startswith('__'))
#print log.read()
#import stats
# write a header to the csv file which contains the names of the nodes being logged
log.write_header()
#write the data
log.write_data()
# net.view does not show the simulation play button
#net.view()
for node in net.network.nodes:
print "The node "+node.name+" has the following attributes: "
print ', '.join(i for i in dir(node) if not i.startswith('__'))
for p in net.network.projections:
print "This is the projection that connects node "+p.origin.node.name+" to node "+p.termination.node.name
print p
print "It has the following attributes: "
print ', '.join(i for i in dir(p) if not i.startswith('__'))
print "It has the following weights: "
print p.weights
print "It is located in the network "+p.getNetwork().name
print "The weights returned by myweights are: "
print myweights(p)
print "The weights returned by p.weights are by comparison :"
print p.weights
The links you provide above Nengo in the release version:
Graphical Command-line
Give me a 404 error. Can you fix this? It would be quite useful to see the command line version as this might enable me to resolve myself the problem with net.view not having a simulator play button. I looked around the source code (for a short time!) and could not find the code for these.
Ah sorry, more permanent links:
In both of these, the build process expands BUILDNUMBER
to a git shorthash, and LIBS
to the contents of the lib/
directory.
It would be helpful (to me!) if instructions could be provided so that nengo python scripts could be entered and run (maybe debugged?) in an ide. For jython based development the eclipse/pydev ide is probably a good choice. I have tried to set this up but am having a problem with finding jar files beginning with ca.
Here is my attempt in pydev using the jython jar included with nengo
sys.path.append('/Users/somedir/someotherdir/simulators/Nengo/nengo-5f37d63/python') sys.path.append('/Users/somedir/someotherdir/simulators/Nengo/nengo-5f37d63/lib/Lib') sys.path.append('classpath') sys.path.append('pyclasspath/') sys.path.append('python') sys.path.append('.') import nef
The result is this
Traceback (most recent call last): File "/Users/somedir/Eclipse/mypydev/main.py", line 20, in
import nef
File "/Users/somedir/someotherdir/simulators/Nengo/nengo-5f37d63/python/nef/init.py", line 1, in
import generators
File "/Users/somedir/someotherdir/simulators/Nengo/nengo-5f37d63/python/nef/generators.py", line 1, in
from ca.nengo.util import Vect
I suspect that this is just a matter of getting the classpath right but I don't know where to point it.