PyNEST

From NEST

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

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. The SLI's commands are, however, available in Python via the low-level functions slirun(expr), slipush(obj) and slipop().

Simulation kernel

Simulate(time) 
Simulate the network for time ms.
Reset() 
Reset all nodes to their initial states.
ResetKernel() 
Reset the simulation kernel. This deletes all nodes and connections.

Models and network nodes

Create("model", n=1) -> [id1,...,idn] 
Create n elements of type model. If n is omitted, only one node is created. Create returns a list with handles to the elements.
LayoutNetwork("model", [d1,...,dn]) 
Create a multidimensional network with dimensions [d1,...,dn] with nodes of type model. The nodes are created inside subnets. LayoutNetwork returns the ID of the top-most subnet.
GetLeaves([subnet_id1,...,[subnet_idn]]) -> [[id1,...],[id2...],...[idn...]] 
Returns a nested list with the IDs of all leaf nodes for each subnet.
GetStatus([id1,...,idn]) -> [dict1,...dictn] 
Returns a list with the property dictionaries for each of the nodes [id1,...,idn].
SetStatus([id1,...,idn], [dict1,...,dictn]) 
Sets the properties of each node in [id1,...,idn] to the corresponding dictionary in [dict1,...,dictn]. If the dictionary list has only one entry, all nodes are set to the same properties.
GetModelStatus("model") -> dict 
Return the property dictionary of model model_id.
SetModelStatus("model", params) 
Set the properties of model model_id to the ones given in params.

Synapse types

SetSynapseDefaults("synapse_type",dict) 
GetSynapseDefaults("synapse_type") -> dict 
CopySynapseType("old","new") 
SetSynapseContext("synapse_type") 
GetSynapseContext() -> "synapse_type" 

Connections

GetConnections([id1,...,idn], "synapse_type") -> [dict1,...,dictn] 
SetConnections([id1,...,idn], "synapse_type", [dict1,...,dictn]) 
Connect([sid1,...,sidn],[tid1,...,tidn]) 
ConnectWD([sid1,...,sidn],[tid1,...,tidn],[w1,...,wn],[d1,...,dn]) 
ConvergentConnect([sid1,...,sidn],[tid1,...,tidk]) 
Connects all nodes in [sid1,...,sidn] to each node in [tid1,...,tidk].
ConvergentConnectWD([sid1,...,sidn],[tid1,...,tidk],[w1,...,wn],[d1,...,dn]) 
Connects all nodes in [sid1,...,sidn] to each node in [tid1,...,tidk], using the weights in [w1,...,wn] and delays in [d1,...,dn]. If both lists contain just one value, all connections will have the same weight w1 and delay d1.
DivergentConnect([sid1,...,sidn],[tid1,...,tidn]) 
Connects each node in [sid1,...,sidn] to all nodes in [tid1,...,tidk].
DivergentConnectWD([sid1,...,sidn],[tid1,...,tidk],[w1,...,wk],[d1,...,dk]) 
Connects each node in [sid1,...,sidn] to all nodes in [tid1,...,tidk], using the weights in [w1,...,wk] and delays in [d1,...,dk]. If both lists contain just one value, all connections will have the same weight w1 and delay d1.

All connection functions expect lists with node IDs. If the list contains more than one id, the function is called for each of the nodes. For example

Connect([1,2],[3,4])

is equivalent to

Connect([1],[3]) ; Connect([2],[4])

ConvergentConnect connects many source nodes to one target node. If more than one target is given, convergent connections are created for each target. DivergentConnect connects one source to many target neurons. Here, the list of source nodes is iterated.

Views
Personal tools