<< Main Manual 

Tutorial #6. Writing Custom Utility Scripts

This tutorial assumes that you have completed Tutorial #5.

Creating Custom Utility Scripts

Using the nne utility scripts is helpful for quickly prototyping new networks. However, if one were interested in dynamically generated variable networks on the fly it's much faster to write your own single utility Python script that uses the nne API. From the command-line:

> cd NeuronetExperimenter-simulations
> python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *             
# This allows us access to a Network object we will use to build our network
>>> network = Network()    
>>> network.addNeurons('zca', 10)
>>> network.addNeurons('Butera', 5)
>>> network.connectAll2All('Excitatory')
>>> network.save('tut6_1.net')
Saving Network to: tut6_1.net
>>> quit()
>

Take a look at the tut6_1.net file in a text editor and you should see that there are 10 zca neurons followed by 5 Butera neurons, and their associated parameters and initial conditions as we defined them in the original .oden files.

Suppose we want to add random connections from each zca neuron to the Butera neurons and vice versa. Rather than generating an adjacency matrix as tutorial #4 showed, or doing this by hand in the .net file (uggghhhh), we can use our Python access to each neuron directly:

#!/usr/bin/env python

from nne import *

POPSIZE=50

network = Network()
network.addNeurons("Butera", POPSIZE)

#// Nodose connections
network.addConnections_FixedInbound("Butera", "Butera", 5, "0.0")
network.changeAttribute("Butera", "g_syn = 0.5")                 
# This sets the g_syn on each Butera neuron to 0.5
network.changeAttribute("Butera", "g_LK = gauss(2.4,0.2)")       
# This sets the g_LK on each Butera neuron to a value from
                                                                  #    a 2.4±0.2 Gaussian distribution

network.save("Butera.net")


Help on the functions and properties of nne.Network objects can be found as follows:
python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *            

>>> help(Network)
Help on class Network in module nne:

class Network(builtins.object)
 |  Proxy of C++ Network class.
 |
 |  Methods defined here:
 |
 |  __init__(self)
 |      __init__(Network self) -> Network
 |
 |  __repr__ = _swig_repr(self)
 |
 |  add(self, neuron)
 |      add(Network self, Neuron neuron)
 |
 |  addConnections_FixedInbound(self, fromNeuronType, toNeuronType, numberOfConnections, latencyString, connectionType='Excitatory')
 |
 |  addConnections_FixedOutbound(self, fromNeuronType, toNeuronType, numberOfConnections, latencyString, connectionType='Excitatory')
 |
 |  addNeuron(self, neuronName)
 |      addNeuron(Network self, char * neuronName)
 |
 |  addNeurons(self, neuronName, number)
 |      addNeurons(Network self, char * neuronName, int number)
 |
 |  changeAttribute(self, neuronType, change)
 |
 |  clearAllConnections(self, *args)
 |      clearAllConnections(Network self, range const & ourRange=range(long(1),long(0)))
 |
 |  connectAll2All(self, connectionType, allowAutapses=False)
 |      connectAll2All(Network self, char const * connectionType, bool allowAutapses=False)
 |
 |  connectWithWiringProbability(self, fromType, toType, connectionType, probability, latencyString='0')


Help on the functions and properties of nne.Network objects can be found as follows with the Python help function:
python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *            

>>> help(Network)

Help on class Network in module nne:

class Network(builtins.object)
 |  Proxy of C++ Network class.
 |
 |  Methods defined here:
 |
 |  __init__(self)
 |      __init__(Network self) -> Network
 |
 |  __repr__ = _swig_repr(self)
 |
 |  add(self, neuron)
 |      add(Network self, Neuron neuron)
 |
 |  addConnections_FixedInbound(self, fromNeuronType, toNeuronType, numberOfConnections, latencyString, connectionType='Excitatory')
 |
 |  addConnections_FixedOutbound(self, fromNeuronType, toNeuronType, numberOfConnections, latencyString, connectionType='Excitatory')
 |
 |  addNeuron(self, neuronName)
 |      addNeuron(Network self, char * neuronName)
 |
 |  addNeurons(self, neuronName, number)
 |      addNeurons(Network self, char * neuronName, int number)
 |
 |  changeAttribute(self, neuronType, change)
 |
 |  clearAllConnections(self, *args)
 |      clearAllConnections(Network self, range const & ourRange=range(long(1),long(0)))
 |
 |  connectAll2All(self, connectionType, allowAutapses=False)
 |      connectAll2All(Network self, char const * connectionType, bool allowAutapses=False)
 |
 |  connectWithWiringProbability(self, fromType, toType, connectionType, probability, latencyString='0')


In addition to Network objects, other objects may be create and manipulated with the nne library. Of particular interest are Setup and Experiment objects that allow the dynamic generation of entire simulation protocols.

Setup objects:
python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *            

>>> help(Setup)

Help on class Setup in module nne:

class Setup(builtins.object)
 |  Proxy of C++ Setup class.
 |
 |  Methods defined here:
 |
 |  __init__(self)
 |      __init__(Setup self) -> Setup
 |
 |  __repr__ = _swig_repr(self)
 |
 |  addExperiment(self, experiment)
 |      addExperiment(Setup self, Experiment experiment)
 |
 |  addExperiments(self, experiment, numberOfExperiments)
 |      addExperiments(Setup self, Experiment experiment, int numberOfExperiments)
 |
 |  addNetwork(self, network)
 |      addNetwork(Setup self, Network network)
 |
 |  addNetworkProxy(self, proxy)
 |      addNetworkProxy(Setup self, NetworkProxy proxy)
 |
 |  addOutputStatsVariable(self, variableName)
 |      addOutputStatsVariable(Setup self, string variableName)
 |
 |  addOutputVariable(self, variableName)
 |      addOutputVariable(Setup self, string variableName)
 |
 |  addRasterVariable(self, variableName)
 |      addRasterVariable(Setup self, string variableName)
 |
 |  backup(self, path)
 |      backup(Setup self, string path)


Experiment objects:
python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *            

>>> help(Experiment)

Help on class Experiment in module nne:

class Experiment(builtins.object)
 |  Experiment(*args)
 |
 |  Proxy of C++ Experiment class.
 |
 |  Methods defined here:
 |
 |  __init__(self, *args)
 |      __init__(Experiment self) -> Experiment
 |      __init__(Experiment self, Experiment a) -> Experiment
 |
 |  __repr__ = _swig_repr(self)
 |
 |  addChange(self, neuronIdentifier, changeString)
 |      addChange(Experiment self, string neuronIdentifier, string changeString)
 |
 |  getChange(self, index)
 |      getChange(Experiment self, int index) -> string
 |
 |  getChangeStrings(self)
 |      Returns the change expressions associated with this Experiment.
 |
 |  getName(self)
 |      getName(Experiment self) -> string
 |
 |  getNumberOfChanges(self)
 |      getNumberOfChanges(Experiment self) -> int
 |
 |  getTime(self)
 |      getTime(Experiment self) -> fp_type
 |
 |  load(self, experimentFilename)
 |      load(Experiment self, string experimentFilename)

Finally, another object of interest is the generic Neuron object that all models inherit from (such as 'zca' and 'Butera' neurons).

Neuron object:
python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *            

>>> help(Neuron)

Help on class Neuron in module nne:

class Neuron(builtins.object)
 |  Neuron(*args, **kwargs)
 |
 |  Proxy of C++ Neuron class.
 |
 |  Methods defined here:
 |
 |  __init__(self, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  __repr__ = _swig_repr(self)
 |
 |  addConnectionFrom(self, connectionType, fromNeuron, latency=0, defaultWeight=1.0)
 |      addConnectionFrom(Neuron self, unsigned long const & connectionType, Neuron fromNeuron, fp_type const & latency=0, fp_type const & defaultWeight=1.0)
 |
 |  addConnectionTo(self, *args)
 |      addConnectionTo(Neuron self, char const * connectionType, Neuron toNeuron, fp_type const & latency=0.0, fp_type const & weight=1.0)
 |      addConnectionTo(Neuron self, unsigned long const & connectionType, Neuron toNeuron, fp_type const & latency=0.0, fp_type const & weight=1.0)
 |
 |  addConnectionsTo(self, connectionType, compartments)
 |      Adds the same type of connection to all the target compartments.
 |
 |  addGroup(self, groupName)
 |      addGroup(Neuron self, string groupName)
 |
 |  addInputVar(self, *args)
 |      addInputVar(Neuron self, string aname, fp_type * actual)
 |      addInputVar(Neuron self, string aname) -> bool
 |
 |  addOutputVar(self, gname, shouldOut=True)
 |      addOutputVar(Neuron self, string gname, bool const & shouldOut=True) -> bool
 |
 |  addStatVar(self, gname)


This is particularly useful for accessing directly the connectivity, parameters, or state variables of neurons.

python
Python 3.9.19 (r251:54869, Apr 18 2007, 22:08:04)
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nne import *            

>>> network = Network()
>>> network.load('tut6_1.net')
>>> print(network.getNeuronTypes())
['zca', 'Butera']
>>> neuronID = 6
>>> neuron = network.getNeuron(neuronID)
>>> print(neuron.getID())
6
>>> print(neuron.getNeuronType())
zca
>>> print(neuron.getNumberOfParameterVars())
47
>>> print(neuron.getStateVariableName(0))
'V'
>>> print(neuron.getStateVariable('V'))
-71.81327
>>> print(neuron.getStateVariableNames())
['V', 'hhs', 'nns', 'bbs', 'zzs', 's_AMPA']
>>> print(neuron.getParameterNames())
['sigma_m',
 'theta_m',
 'sigma_p',
 'theta_p',
 'sigma_a',
 'theta_a',
 'sigma_s',
 'theta_s',
 'V_Na',
 'pms',
 'g_Na',
 'g_NaP',
 'V_K',
 'pns',
 'g_Kdr',
 'g_A',
 'g_Z',
 'g_syn',
 'C_m',
 'I_app',
 'V_L',
 'g_L',
 'tau_h',
 'sigma_h',
 'theta_h',
 'phi',
 'tau_n',
 'sigma_n',
 'theta_n',
 'tau_Bs',
 'sigma_b',
 'theta_b',
 'tau_Zs',
 'sigma_z',
 'theta_z',
 'tau_s',
 'sigma_k']
>>> print(neuron.getParameter('
sigma_k'))
7.0
>>> neuron.setParameter('sigma_k', 14.0)
>>> print(neuron.getParameter('sigma_k'))
14.0
>>> neuron.getInboundConnectionTypes()
['Excitatory']
>>> inboundConnections = neuron.getInboundConnections('Excitatory')

In addition to the interactive help command through Python, we have generated pydoc for the nne package found here.

>> Tutorial #7. Exporting Models as LaTex

<< Main Manual