Types module

Accessing and setting node and parameter types in NEST.

Classes defining the different PyNEST types

class nest.lib.hl_api_types.CollocatedSynapses(*args)

Bases: object

Class for collocated synapse specifications.

Wrapper around a list of specifications, used when calling Connect().

Example

nodes = nest.Create('iaf_psc_alpha', 3)
syn_spec = nest.CollocatedSynapses({'weight': 4., 'delay': 1.5},
                               {'synapse_model': 'stdp_synapse'},
                               {'synapse_model': 'stdp_synapse', 'alpha': 3.})
nest.Connect(nodes, nodes, conn_spec='one_to_one', syn_spec=syn_spec)

conns = nest.GetConnections()

print(conns.alpha)
print(len(syn_spec))
class nest.lib.hl_api_types.Compartments(node_collection, elements)

Bases: CmBase

nest.lib.hl_api_types.CreateParameter(parametertype, specs)

Create a parameter.

Parameters:
  • parametertype (string) – Parameter type with or without distance dependency. Can be one of the following: ‘constant’, ‘linear’, ‘exponential’, ‘gaussian’, ‘gaussian2D’, ‘uniform’, ‘normal’, ‘lognormal’, ‘distance’, ‘position’

  • specs (dict) – Dictionary specifying the parameters of the provided parametertype, see Parameter types.

Returns:

Object representing the parameter

Return type:

Parameter

Notes

Instead of using CreateParameter you can also use the various parametrizations embedded in NEST. See for instance uniform().

Parameter types

Examples of available parameter types (parametertype parameter), with their function and acceptable keys for their corresponding specification dictionaries:

  • Constant

    'constant' :
        {'value' : float} # constant value
    
  • Randomization

    # random parameter with uniform distribution in [min,max)
    'uniform' :
        {'min' : float, # minimum value, default: 0.0
         'max' : float} # maximum value, default: 1.0
    
    # random parameter with normal distribution
    'normal':
        {'mean' : float, # mean value, default: 0.0
         'std'  : float} # standard deviation, default: 1.0
    
    # random parameter with lognormal distribution
    'lognormal' :
        {'mean' : float, # mean value of logarithm, default: 0.0
         'std'  : float} # standard deviation of log, default: 1.0
    
class nest.lib.hl_api_types.Mask(datum)

Bases: object

Class for spatial masks.

Masks are used when creating connections when nodes have spatial extent. A mask describes the area of the pool population that shall be searched to find nodes to connect to for any given node in the driver population. Masks are created using the CreateMask() command.

Inside(point)

Test if a point is inside a mask.

Parameters:

point (tuple/list of float values) – Coordinate of point

Returns:

out – True if the point is inside the mask, False otherwise

Return type:

bool

class nest.lib.hl_api_types.NodeCollection(data=None)

Bases: object

Class for NodeCollection.

NodeCollection represents the nodes of a network. The class supports iteration, concatenation, indexing, slicing, membership, length, conversion to and from lists, test for membership, and test for equality. By using the membership functions get() and set(), you can get and set desired parameters.

A NodeCollection is created by the Create() function, or by converting a list of nodes to a NodeCollection with nest.NodeCollection(list).

If your nodes have spatial extent, use the member parameter spatial to get the spatial information.

Slicing a NodeCollection follows standard Python slicing syntax: nc[start:stop:step], where start and stop gives the zero-indexed right-open range of nodes, and step gives the step length between nodes. The step must be strictly positive.

Example

import nest

nest.ResetKernel()

# Create NodeCollection representing nodes
nc = nest.Create('iaf_psc_alpha', 10)

# Convert from list
node_ids_in = [2, 4, 6, 8]
new_nc = nest.NodeCollection(node_ids_in)

# Convert to list
nc_list =  nc.tolist()

# Concatenation
Enrns = nest.Create('aeif_cond_alpha', 600)
Inrns = nest.Create('iaf_psc_alpha', 400)
nrns = Enrns + Inrns

# Slicing and membership
print(new_nc[2])
print(new_nc[1:2])
6 in new_nc
get(*params, **kwargs)

Get parameters from nodes.

Parameters:
  • params (str or list, optional) –

    Parameters to get from the nodes. It must be one of the following:

    • A single string.

    • A list of strings.

    • One or more strings, followed by a string or list of strings. This is for hierarchical addressing.

  • output (str, ['pandas','json'], optional) – If the returned data should be in a Pandas DataFrame or in a JSON serializable format.

Returns:

  • int or float – If there is a single node in the NodeCollection, and a single parameter in params.

  • array_like – If there are multiple nodes in the NodeCollection, and a single parameter in params.

  • dict – If there are multiple parameters in params. Or, if no parameters are specified, a dictionary containing aggregated parameter-values for all nodes is returned.

  • DataFrame – Pandas Data frame if output should be in pandas format.

Raises:
  • TypeError – If the input params are of the wrong form.

  • KeyError – If the specified parameter does not exist for the nodes.

Examples

>>>    nodes.get()
       {'archiver_length': (0, 0, 0),
       'beta_Ca': (0.001, 0.001, 0.001),
       'C_m': (250.0, 250.0, 250.0),
       ...
       'V_th': (-55.0, -55.0, -55.0),
       'vp': (0, 0, 0)}
>>>    nodes.get('V_m')
       (-70.0, -70.0, -70.0)
>>>    nodes[0].get('V_m')
       -70.0
>>>    nodes.get('V_m', 'C_m')
       {'V_m': (-70.0, -70.0, -70.0), 'C_m': (250.0, 250.0, 250.0)}
>>>    voltmeter.get('events', 'senders')
       array([...], dtype=int64)
index(node_id)

Find the index of a node ID in the NodeCollection.

Parameters:

node_id (int) – Global ID to be found.

Raises:

ValueError – If the node ID is not in the NodeCollection.

set(params=None, **kwargs)

Set the parameters of nodes to params.

NB! This is almost the same implementation as SetStatus.

If kwargs is given, it has to be names and values of an attribute as keyword argument pairs. The values can be single values or list of the same size as the NodeCollection.

Parameters:
  • params (str or dict or list) – Dictionary of parameters (either lists or single values) or list of dictionaries of parameters of same length as the NodeCollection.

  • kwargs (keyword argument pairs) – Named arguments of parameters of the elements in the NodeCollection.

Raises:
  • TypeError – If the input params are of the wrong form.

  • KeyError – If the specified parameter does not exist for the nodes.

tolist()

Convert NodeCollection to list.

class nest.lib.hl_api_types.Parameter(datum)

Bases: object

Class for parameters

A parameter may be used as a probability kernel when creating connections and nodes or as synaptic parameters (such as weight and delay). Parameters are created using the CreateParameter() command.

GetValue()

Compute value of parameter.

Returns:

out – The value of the parameter

Return type:

value

See also

CreateParameter

Example

import nest

# normal distribution parameter
P = nest.CreateParameter('normal', {'mean': 0.0, 'std': 1.0})

# get out value
P.GetValue()
apply(spatial_nc, positions=None)
is_spatial()
class nest.lib.hl_api_types.Receptors(node_collection, elements)

Bases: CmBase

class nest.lib.hl_api_types.SynapseCollection(data)

Bases: object

Class for Connections.

SynapseCollection represents the connections of a network. The class supports indexing, iteration, length and equality. You can get and set connection parameters by using the membership functions get() and set(). By using the membership function sources() you get an iterator over source nodes, while targets() returns an interator over the target nodes of the connections.

A SynapseCollection is created by the GetConnections() function.

disconnect()

Disconnect the connections in the SynapseCollection.

get(keys=None, output='')

Return a parameter dictionary of the connections.

If keys is a string, a list of values is returned, unless we have a single connection, in which case the single value is returned. keys may also be a list, in which case a dictionary with a list of values is returned.

Parameters:
  • keys (str or list, optional) – String or a list of strings naming model properties. get then returns a single value or a dictionary with lists of values belonging to the given keys.

  • output (str, ['pandas','json'], optional) – If the returned data should be in a Pandas DataFrame or in a JSON serializable format.

Returns:

  • dict – All parameters, or, if keys is a list of strings, a dictionary with lists of corresponding parameters

  • type – If keys is a string, the corresponding parameter(s) is returned

Raises:
  • TypeError – If input params are of the wrong form.

  • KeyError – If the specified parameter does not exist for the connections.

See also

set

Examples

>>>    conns.get()
       {'delay': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
        ...
        'weight': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]}
>>>    conns.get('weight')
       [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
>>>    conns[0].get('weight')
       1.0
>>>    nodes.get(['source', 'weight'])
       {'source': [1, 1, 1, 2, 2, 2, 3, 3, 3],
        'weight': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]}
set(params=None, **kwargs)

Set the parameters of the connections to params.

NB! This is almost the same implementation as SetStatus

If kwargs is given, it has to be names and values of an attribute as keyword argument pairs. The values can be single values or list of the same size as the SynapseCollection.

Parameters:
  • params (str or dict or list) – Dictionary of parameters (either lists or single values) or list of dictionaries of parameters of same length as SynapseCollection.

  • kwargs (keyword argument pairs) – Named arguments of parameters of the elements in the SynapseCollection.

Raises:
  • TypeError – If input params are of the wrong form.

  • KeyError – If the specified parameter does not exist for the connections.

See also

get

sources()

Returns iterator containing the source node IDs of the SynapseCollection.

targets()

Returns iterator containing the target node IDs of the SynapseCollection.

nest.lib.hl_api_types.serializable(data)

Make data serializable for JSON.

Parameters:

data (any) –

Returns:

data_serialized – Data can be encoded to JSON

Return type:

str, int, float, list, dict

nest.lib.hl_api_types.to_json(data, **kwargs)

Serialize data to JSON.

Parameters:
  • data (any) –

  • kwargs (keyword argument pairs) – Named arguments of parameters for json.dumps function.

Returns:

data_json – JSON format of the data

Return type:

str

Functions to get information on NEST.

nest.lib.hl_api_info.GetStatus(nodes, keys=None, output='')

Return the parameter dictionaries of nodes or connections.

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.

Parameters:
  • nodes (NodeCollection or SynapseCollection) – Either a NodeCollection representing nodes, or a SynapseCollection of connection handles as returned by GetConnections().

  • keys (str or list, optional) – string or a list of strings naming model properties. GetStatus then returns a single value or a list of values belonging to the keys given.

  • output (str, optional) – Whether the returned data should be in a selected format (output='json').

Returns:

  • list of dicts – All parameters in a dict for each node or connection.

  • list of values – If keys is a string, the value of the corresponding parameter for each node or connection is returned.

  • list of lists of values – If keys is a list of strings, a list of values of the corresponding parameters for each node or connection is returned.

  • str – If output is json, the above formats are converted to JSON format before they are returned.

Raises:

TypeError – If nodes or keys are on the wrong form.

Examples

For nodes:

>>>    nest.GetStatus(nodes)
       ({'archiver_length': 0,
         'beta_Ca': 0.001,
         ...
         'global_id': 1,
         ...
         'vp': 0},
        ...
        {'archiver_length': 0,
         'beta_Ca': 0.001,
         ...
         'global_id': 3,
         ...
         'vp': 0})
>>>    nest.GetStatus(nodes, 'V_m')
       (-70.0, -70.0, -70.0)
>>>    nest.GetStatus(nodes, ['V_m', 'C_m'])
       ((-70.0, 250.0), (-70.0, 250.0), (-70.0, 250.0))
>>>    nest.GetStatus(nodes, ['V_m', 'C_m'], output='json')
       '[[-70.0, 250.0], [-70.0, 250.0], [-70.0, 250.0]]'

For connections:

>>>    nest.GetStatus(conns)
       ({'delay': 1.0,
         ...
         'source': 1,
         ...
         'weight': 1.0},
        ...
        {'delay': 1.0,
         ...
         'source': 3,
         ...
         'weight': 1.0})
>>>    nest.GetStatus(conns, 'weight')
       (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)
>>>    nest.GetStatus(conns, ['source', 'delay'])
       ((1, 1.0),
        ...
        (3, 1.0))
>>>    nest.GetStatus(conns, ['source', 'delay'], output='json')
       '[[1, 1.0], [1, 1.0], [1, 1.0], [2, 1.0], [2, 1.0], [2, 1.0],
       [3, 1.0], [3, 1.0], [3, 1.0]]'
nest.lib.hl_api_info.SetStatus(nodes, params, val=None)

Set parameters of nodes or connections.

Parameters of nodes or connections, given in nodes, is set as specified by params. If val is given, params has to be a string with the name of an attribute, which is set to val on the nodes/connections. val can be a single value or a list of the same size as nodes.

Parameters:
  • nodes (NodeCollection or SynapseCollection) – Either a NodeCollection representing nodes, or a SynapseCollection of connection handles as returned by GetConnections().

  • params (str or dict or list) – Dictionary of parameters (either lists or single values) or list of dictionaries of parameters of same length as nodes. If val is given, this has to be a string giving the name of a model property.

  • val (int, list, optional) – If given, params has to be the name of a model property.

Raises:

TypeError – If nodes is not a NodeCollection of nodes, a SynapseCollection of synapses, or if the number of parameters don’t match the number of nodes or synapses.

nest.lib.hl_api_info.get_argv()

Return argv as seen by NEST.

This is similar to Python sys.argv but might have changed after MPI initialization.

Returns:

Argv, as seen by NEST

Return type:

tuple