PyNEST

From NEST Initiative
Jump to: navigation, search

[ Software:Documentation ]

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 PyNEST commands are mostly the same as in SLI, so that the SLI documentation can be used for both.

Publication

The implementation of PyNEST is published as Jochen Martin Eppler, Moritz Helias, Eilif Muller, Markus Diesmann, and Marc-Oliver Gewaltig. PyNEST: A convenient interface to the NEST simulator. Frontiers in Neuroinformatics, 2:12, 2009. doi:10.3389/neuro.11.012.2008 and avaliable from here.

Note on the usage of SciPy

We recently observed that if PyNEST is used with some versions of SciPy, a segmentation fault is caused. The exact reason for this is not identified yet. However, to circumvent the problem, you can import SciPy before PyNEST.

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.

OSX 10.6 and IPython 2.6

IPython 2.6 under OSX 10.6 has some issues with NEST, at least the IPython version from MacPorts. You can use the following work-around to start NEST in IPython 2.6 on Snow Leopard: First start plain python and then load nest first before loading IPython by hand:

>>> import nest 
>>> import IPython.Shell
>>> IPython.Shell.start().mainloop()
In [1]: import nest
In [2]: nest.Simulate(1)

Note that you need to import NEST a second time once you have entered the IPython shell. Output has been removed in the code snippet above. We are working on this issue under ticket #397.

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().

Cheat-Sheet

Please download the Poster describing the Python API to NEST (pdf), presented at the Neuroinformatics 2008 conference in Stockholm.

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.
help()
Show the help page for the given object
helpdesk(browser="firefox")
Open the NEST helpdesk in the given browser.

Low-level access to SLI

sli_pop()
Pop an object off the SLI stack and return it.
sli_push(object)
Push an object onto the SLI stack.
sli_run()
Send a command string to the NEST kernel to be executed and raise errors as Python errors.

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. sel can be a string, used to filter the result list and only return models containing it.
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, specified by a string.
SetDefaults(model, params)
Set the default parameters of the given model to the values specified in the params dictionary.

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, keys=None)
Return the parameter dictionaries of the given list of nodes. If keys is given, a list of values is returned instead. keys may also be a list, in which case the returned list contains lists of values.
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', options=None)
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. options is a dictionary specifying options to the RandomConvergentConnect function: allow_autapses, allow_multapses.
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', options=None)
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. options is a dictionary specifying options to the RandomDivergentConnect function: allow_autapses, allow_multapses.
FindConnections(source, target=None, synapse_type=None)
Return an array of identifiers for connections that match the given parameters. Only source is mandatory and must be a list of one or more nodes. If target and/or synapse_type is/are given, they must be single values, lists of length one or the same length as source. Use GetStatus()/SetStatus() to inspect/modify the found connections.
GetStatus(conns, keys=None)
Return the parameter dictionaries of the given list of connections (identified by handles as returned by FindConnections()). If keys is given, a list of values is returned instead. keys may also be a list, in which case the returned list contains lists of values.
SetStatus(conns, params, val=None)
Set the parameters of connections (identified by handles as returned by FindConnections()) 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 connections. val can be a single value or a list of the same size as conns.

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.
BeginSubnet()
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.
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.
GetNodeAt(gidlist, adr)
For each subnet in gidlist, get the gid of the node at position adr.
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.
LayoutNetwork(model, dim, label=None, params=None)
Create a subnetwork of dimension dim with nodes of type model and return a list of ids.
Personal tools
Namespaces

Variants
Actions
Software
Initiative
Impressum
Tools