Many researchers prefer to create models by writing scripts rather than using a graphical user interface. To accomplish this, we have embedded a scripting system within Nengo.
The scripting language used in Nengo is Python. Detailed documentation on Python syntax can be found at http://www.python.org/. Nengo uses Jython (http://jython.org) to interface between the script and the underlying Java implementation of Nengo. This allows us to use Python syntax and still have access to all of the underlying Java code.
You can also use scripting to interact with a model within Nengo. Click on the icon to toggle the script console (or press Ctrl-P to jump to it). You can now type script commands that will be immediately run. For example, you can type this at the console:
print "Hello from Nengo"
When using the script console, you can refer to the currently selected object using the word that. For example, if you click on a component of your model (it should be highlighted in yellow to indicate it is selected), you can get its name by typing:
You can also change aspects of then model this way. For example, click on an ensemble of neurons and change the number of neurons in that ensemble by typing:
You can also run a script file from the console with this command, with script_name replaced by the name of the script to run:
Pressing the up and down arrows will scroll through the history of your console commands.
You can also run scripts from the command line. This allows you to simply run the model without running Nengo itself. To do this, instead of running nengo with nengo (or nengo.bat on Windows), do:
The scripting system allows you to make use of any Java library and any 100% Python library. There are two methods for doing this in Python.
First, you can do it this way:
but then when you use the library, you will have to provide its full name:
The other option is to import this way:
from ca.nengo.utils import *
This allows you to just do: