PyNEST
From NEST
Contents |
Introduction
NEST 2.0 can be used with the Python programming language via the PyNEST extension module. This means that Python is used instead of NEST's native simulation language interpreter (SLI). Python has a more convenient syntax and gives you access to many supplementary packages, like e.g. the Matplotlib/Pylab library to visualize the data directly from within the simulation script.
The implementation of PyNEST is published as Eppler JM, Helias M, Muller E, Diesmann M, and Gewaltig M-O (2008) PyNEST: A convenient interface to the NEST simulator. Front. Neuroinform. 2:12 and avaliable from here.
The PyNEST commands are mostly the same as in SLI, so that the SLI documentation can be used for both.
Starting Python
First, you must tell Python where it finds NEST. To do this, define the environment variable PYTHONPATH. For example, bash users type
export PYTHONPATH=<prefix>/lib/python2.5/site-packages
where you must replace 2.5 by your Python version. Again, you can consult extras/nest.config to learn which Python version NEST was compiled for.
A small example
Here is a small example that creates the same network as in Neural simulations, but now using PyNEST instead of SLI. After staring the Python interpreter (or Ipython, an enhanced, interactive Python shell), you first have to import the PyNEST module by typing
import nest
This will initialize the NEST library that runs in the background. Now we can start to set up our simulation.
neuron = nest.Create("iaf_neuron")
The first command will create a neuron of type iaf_neuron. The Create command has an optional argument for the number of neurons to be created. The return value of Create is always a list that contains the IDs of the created elements. In our case it has only a single element, the ID of our neuron.
vm = nest.Create("voltmeter")
The next command connects the voltmeter with the neuron:
nest.Connect(vm, neuron)
Command Index
Following is a list of commands that are available in PyNEST. They correspond directly to the SLI commands with similar names. As Python already has extensive standard libraries for things like math, linear algebra, handling of arrays, statistics, etc. we do not provide them in the PyNEST API. However, PyNEST provides direct access to SLI via the low-level functions sli_run(expr), sli_push(obj) and sli_pop().
Information on NEST
- authors()
- Show the authors of NEST.
- sysinfo()
- Print information on the platform on which NEST was compiled.
- version()
- Print the NEST version
Simulation control
- Simulate(t)
- Simulate the network for t milliseconds.
- ResumeSimulation()
- Resume an interrupted simulation.
- ResetKernel()
- Reset the simulation kernel. This will destroy the network as well as all custom models created with CopyModel(). Calling this function is equivalent to restarting NEST.
- ResetNetwork()
- Reset all nodes and connections to their original state.
- GetKernelStatus()
- Return a dictionary with the parameters of the simulation kernel.
- SetKernelStatus(params)
- Set parameters for the simulation kernel.
Models
- Models(mtype='all', sel=None)
- Return a list of all available NEST models (neurons, devices, synapses). Use mtype='nodes' to only see neuron and device models, mtype='synapses' to only see synapse models.
- CopyModel(existing, new, params=None)
- Create a new model by copying an existing one. Default parameters can be given as params, or else are taken from existing.
- GetDefaults(model)
- Return a dictionary with the default parameters for the given model.
- SetDefaults(model, params)
- Set the default values of the given model to the given parameters.
Nodes
- Create(model, n=1, params=None)
- Create n instances of type model. Parameters for the new nodes can are given as params (a single dictionary or a list of dictionaries with size n). If omitted, the model's defaults are used.
- GetStatus(nodes, attr=None)
- Return the parameter dictionaries of the given list of nodes. If attr is given, a list of values is returned instead. attr may also be a list, in which case the returned list contains lists of values.BR nodes can also be the name of a model, in which case a single dictionary is returned. If attr is given, a value is returned. attr may also be a list, in which case a list of values is returned.
- SetStatus(nodes, params, val=None)
- Set the parameters of nodes to params, which may be a single dictionary or a list of dictionaries. If val is given, params has to be the name of an attribute, which is set to val on the nodes. val can be a single value or a list of the same size as nodes.
- GetAddress(gids)
- Return the addresses of one or more nodes.
- GetGID(addresses)
- Return the global ids of one or more nodes.
- GetLID(gid)
- Return the local id of a node with gid.
Connections
- Connect(pre, post, params=None, delay=None, model='static_synapse')
- Make one-to-one connections of type model between the nodes in pre and the nodes in post. pre and post have to be lists of the same length. If params is given (as dictionary or list of dictionaries), they are used as parameters for the connections. If params is given as a single float or as list of floats, it is used as weight(s), in which case delay also has to be given as float or as list of floats.
- ConvergentConnect(pre, post, weight=None, delay=None, model='static_synapse')
- Connect all neurons in pre to each neuron in post. pre and post have to be lists. If weight is given (as a single float or as list of floats), delay also has to be given as float or as list of floats.
- RandomConvergentConnect(pre, post, n, weight=None, delay=None, model='static_synapse')
- Connect n randomly selected neurons from pre to each neuron in post. pre and post have to be lists. If weight is given (as a single float or as list of floats), delay also has to be given as float or as list of floats.
- DivergentConnect(pre, post, weight=None, delay=None, model='static_synapse')
- Connect each neuron in pre to all neurons in post. pre and post have to be lists. If weight is given (as a single float or as list of floats), delay also has to be given as float or as list of floats.
- RandomDivergentConnect(pre, post, n, weight=None, delay=None, model='static_synapse')
- Connect each neuron in pre to n randomly selected neurons from post. pre and post have to be lists. If weight is given (as a single float or as list of floats), delay also has to be given as float or as list of floats.
- FindConnections(source, target, synapse)
- Return a dictionary of threads, ports for a given source and target node
- GetConnection(node, synapse, port)
- Return a single connection of a given synapse type.
- SetConnection(node, synapse, port, params)
- Change a single connection of a given synapse type.
- GetConnections(nodes, synapse)
- Return the connections of a given synapse type for one or more nodes.
- SetConnections(nodes, synapse, params)
- Change the connections of a given synapse type for one or more nodes.
Distributed simulations
- NumProcesses()
- Return the overall number of MPI processes.
- Rank()
- Return the MPI rank of the local process.
Structured Networks
- PrintNetwork(depth=1, subnet=None)
- Print the network tree up to depth, starting at subnet. if subnet is omitted, the current subnet is used instead.
- CurrentSubnet()
- Returns the global id of the current subnet.
- ChangeSubnet(subnet)
- Make subnet the current subnet.
- GetLeaves(subnets)
- Return the global ids of all leaf nodes of the given subnet.
- GetNodes(subnets)
- Return the complete list of nodes (including sub-networks) under subnet.
- GetChildren(gid)
- Return the immediate children of subnet id.
- GetNetwork(gid, depth)
- Return a nested list with the children of subnet id at level depth. If depth==0, the immediate children of the subnet are returned. The returned list is depth+1 dimensional.
- GetNodeAt(gidlist, adr)
- For each subnet in gidlist, get the gid of the node at position adr.
- LayoutNetwork(model, dim, label=None, params=None)
- Create a subnetwork of dimension dim with nodes of type model and return a list of ids.
- BeginSubnet(label=None, params=None)
- Create a new subnet and change into it. A string argument can be used to name the new subnet. A dictionary argument can be used to set the subnet's custom dict.
- EndSubnet()
- Change to the parent subnet and return the gid of the current.
