High-level API of PyNEST

lib.hl_api_connections module

Functions for connection handling

lib.hl_api_connections.CGConnect( *args, **kwargs )

Connect neurons from pre to neurons from post using connectivity specified by the connection generator cg.

This function is only available if NEST was compiled with support for libneurosim.

pre: list must contain 1 subnet, or a list of GIDs

post: list must contain 1 subnet, or a list of GIDs

cg: connection generator libneurosim connection generator to use

parameter_map: dict, optional Maps names of values such as weight and delay to value set positions

model: str, optional Synapse model to use

kernel.NESTError

lib.hl_api_connections.CGParse( *args, **kwargs )

Parse an XML file and return the correcponding connection generator cg.

The library to provide the parsing can be selected by CGSelectImplementation().

xml_filename: str Filename of the xml file to parse.

kernel.NESTError Description

lib.hl_api_connections.CGSelectImplementation( *args, **kwargs )

Select a library to provide a parser for XML files and associate an XML tag with the library.

XML files can be read by CGParse().

tag: str XML tag to associate with the library

library: str Library to use to parse XML files

kernel.NESTError Description

lib.hl_api_connections.Connect( *args, **kwargs )

Connect pre nodes to post nodes.

Nodes in pre and post are connected using the specified connectivity (all-to-all by default) and synapse type (static_synapse by default). Details depend on the connectivity rule.

pre: list Presynaptic nodes, as list of GIDs

post: list Postsynaptic nodes, as list of GIDs

conn_spec: str or dict, optional Specifies connectivity rule, see below

syn_spec: str or dict, optional Specifies synapse model, see below

model: str or dict, optional alias for syn_spec for backward compatibility

kernel.NESTError Description

Connect does not iterate over subnets, it only connects explicitly specified nodes.

Connectivity is specified either as a string containing the name of a connectivity rule (default: ‘all_to_all’) or as a dictionary specifying the rule and any mandatory rule-specific parameters (e.g. ‘indegree’).

In addition, switches setting permission for establishing self-connections (‘autapses’, default: True) and multiple connections between a pair of nodes (‘multapses’, default: True) can be contained in the dictionary. Another switch enables the creation of symmetric connections (‘symmetric’, default: False) by also creating connections in the opposite direction.

  • ‘all_to_all’ (default)
  • ‘one_to_one’
  • ‘fixed_indegree’, ‘indegree’
  • ‘fixed_outdegree’, ‘outdegree’
  • ‘fixed_total_number’, ‘N’
  • ‘pairwise_bernoulli’, ‘p’

  • ‘one_to_one’
  • {‘rule’: ‘fixed_indegree’, ‘indegree’: 2500, ‘autapses’: False}
  • {‘rule’: ‘pairwise_bernoulli’, ‘p’: 0.1}

The synapse model and its properties can be given either as a string identifying a specific synapse model (default: ‘static_synapse’) or as a dictionary specifying the synapse model and its parameters.

Available keys in the synapse specification dictionary are: - ‘model’ - ‘weight’ - ‘delay’ - ‘receptor_type’ - any parameters specific to the selected synapse model.

All parameters are optional and if not specified, the default values of the synapse model will be used. The key ‘model’ identifies the synapse model, this can be one of NEST’s built-in synapse models or a user-defined model created via CopyModel().

If ‘model’ is not specified the default model ‘static_synapse’ will be used.

All other parameters can be scalars, arrays or distributions. In the case of scalar parameters, all keys must be doubles except for ‘receptor_type’ which must be initialised with an integer.

Parameter arrays are available for the rules ‘one_to_one’, ‘all_to_all’, ‘fixed_indegree’ and ‘fixed_outdegree’: - For ‘one_to_one’ the array has to be a one-dimensional NumPy array with length len(pre).

  • For ‘all_to_all’ the array has to be a two-dimensional NumPy array with shape (len(post), len(pre)), therefore the rows describe the target and the columns the source neurons.
  • For ‘fixed_indegree’ the array has to be a two-dimensional NumPy array with shape (len(post), indegree), where indegree is the number of incoming connections per target neuron, therefore the rows describe the target and the columns the connections converging to the target neuron, regardless of the identity of the source neurons.
  • For ‘fixed_outdegree’ the array has to be a two-dimensional NumPy array with shape (len(pre), outdegree), where outdegree is the number of outgoing connections per source neuron, therefore the rows describe the source and the columns the connections starting from the source neuron regardless of the identity of the target neuron.

Any distributed parameter must be initialised with a further dictionary specifying the distribution type (‘distribution’, e.g. ‘normal’) and any distribution-specific parameters (e.g. ‘mu’ and ‘sigma’).

To see all available distributions, run: nest.slirun(‘rdevdict info’)

To get information on a particular distribution, e.g. ‘binomial’, run: nest.help(‘rdevdict::binomial’)

  • ‘normal’ with ‘mu’, ‘sigma’
  • ‘normal_clipped’ with ‘mu’, ‘sigma’, ‘low’, ‘high’
  • ‘lognormal’ with ‘mu’, ‘sigma’
  • ‘lognormal_clipped’ with ‘mu’, ‘sigma’, ‘low’, ‘high’
  • ‘uniform’ with ‘low’, ‘high’
  • ‘uniform_int’ with ‘low’, ‘high’

  • ‘stdp_synapse’

  • {‘weight’: 2.4, ‘receptor_type’: 1}

  • {‘model’: ‘stdp_synapse’,

‘weight’: 2.5, ‘delay’: {‘distribution’: ‘uniform’, ‘low’: 0.8, ‘high’: 2.5}, ‘alpha’: {‘distribution’: ‘normal_clipped’, ‘low’: 0.5, ‘mu’: 5.0, ‘sigma’: 1.0} }

lib.hl_api_connections.DataConnect( *args, **kwargs )

Connect neurons from lists of connection data.

pre: list Presynaptic nodes, given as lists of GIDs or lists of synapse status dictionaries. See below.

params: list, optional See below

model: str, optional Synapse model to use, see below

TypeError

Connect each neuron in pre to the targets given in params, using synapse type model.

  • pre: [gid_1, ... gid_n]
  • params: [ {param_1}, ..., {param_n} ]
  • model= ‘synapse_model’

The dictionaries param_1 to param_n must contain at least the following keys: - ‘target’ - ‘weight’ - ‘delay’ Each key must resolve to a list or numpy.ndarray of values.

Depending on the synapse model, other parameters can be given in the same format. All arrays in params must have the same length as ‘target’.

Connect neurons according to a list of synapse status dictionaries, as obtained from GetStatus.

pre = [ {synapse_state1}, ..., {synapse_state_n}] params=None model=None

During connection, status dictionary misses will not raise errors, even if the kernel property ‘dict_miss_is_error’ is True.

lib.hl_api_connections.Disconnect( *args, **kwargs )

Disconnect pre neurons from post neurons.

Neurons in pre and post are disconnected using the specified disconnection rule (one-to-one by default) and synapse type (static_synapse by default). Details depend on the disconnection rule.

pre: list Presynaptic nodes, given as list of GIDs

post: list Postsynaptic nodes, given as list of GIDs

conn_spec: str or dict Disconnection rule, see below

syn_spec: str or dict Synapse specifications, see below

Apply the same rules as for connectivity specs in the Connect method

Possible choices of the conn_spec are - ‘one_to_one’ - ‘all_to_all’

The synapse model and its properties can be inserted either as a string describing one synapse model (synapse models are listed in the synapsedict) or as a dictionary as described below.

If no synapse model is specified the default model ‘static_synapse’ will be used.

Available keys in the synapse dictionary are: - ‘model’ - ‘weight’ - ‘delay’, - ‘receptor_type’ - parameters specific to the synapse model chosen

All parameters are optional and if not specified will use the default values determined by the current synapse model.

‘model’ determines the synapse type, taken from pre-defined synapse types in NEST or manually specified synapses created via CopyModel().

All other parameters are not currently implemented. Note: model is alias for syn_spec for backward compatibility.

Disconnect does not iterate over subnets, it only connects explicitly specified nodes.

lib.hl_api_connections.DisconnectOneToOne( *args, **kwargs )

Disconnect a currently existing synapse.

source: int GID of presynaptic node

target: int GID of postsynaptic node

syn_spec: str or dict See Connect() for definition

lib.hl_api_connections.GetConnections( *args, **kwargs )

Return an array of connection identifiers.

Any combination of source, target, synapse_model and synapse_label parameters is permitted.

source: list, optional Source GIDs, only connections from these pre-synaptic neurons are returned

target: list, optional Target GIDs, only connections to these post-synaptic neurons are returned

synapse_model: str, optional Only connections with this synapse type are returned

synapse_label: int, optional (non-negative) only connections with this synapse label are returned

array: Connections as 5-tuples with entries (source-gid, target-gid, target-thread, synapse-id, port)

Only connections with targets on the MPI process executing the command are returned.

TypeError Description

lib.hl_api_helper module

These are helper functions to ease the definition of the high-level API of the PyNEST wrapper.

lib.hl_api_helper.SuppressedDeprecationWarning ( no_dep_funcs )

Bases: object

Context manager turning off deprecation warnings for given methods.

Think thoroughly before use. This context should only be used as a way to make sure examples do not display deprecation warnings, that is, used in functions called from examples, and not as a way to make tedious deprecation warnings dissapear.

lib.hl_api_helper.broadcast ( item, length, allowed_types, name='item' )

Broadcast item to given length.

item: object Object to broadcast

length: int Length to broadcast to

allowed_types: list List of allowed types

name: str, optional Name of item

object: The original item broadcasted to sequence form of length

TypeError

lib.hl_api_helper.check_stack ( thing )

Convenience wrapper for applying the stack_checker decorator to all class methods of the given class, or to a given function.

If the object cannot be decorated, it is returned unchanged.

thing: function or class
Description

function or class
Decorated function or class

ValueError

lib.hl_api_helper.deprecated ( alt_func_name, text=None )

Decorator for deprecated functions.

Shows a warning and calls the original function.

alt\_func\_name: str, optional
Name of the function to use instead

text: str, optional
Text to display instead of standard text

function:
Decorator function

lib.hl_api_helper.get_debug ( )

Return the current value of the debug flag of the high-level API.

bool: current value of the debug flag

lib.hl_api_helper.get_unistring_type ( )

Returns string type dependent on python version.

str or basestring: Depending on Python version

lib.hl_api_helper.get_verbosity( *args, **kwargs )

Return verbosity level of NEST’s messages.

int: The current verbosity level

lib.hl_api_helper.get_wrapped_text ( text, width=80 )

Formats a given multiline string to wrap at a given width, while preserving newlines (and removing excessive whitespace).

text: str String to format

str: Wrapped string

lib.hl_api_helper.is_coercible_to_sli_array ( seq )

Checks whether a given object is coercible to a SLI array

seq: object Object to check

bool: True if object is coercible to a SLI array

lib.hl_api_helper.is_iterable ( seq )

Return True if the given object is an iterable, False otherwise.

seq: object Object to check

bool: True if object is an iterable

lib.hl_api_helper.is_literal ( obj )

Check whether obj is a “literal”: a unicode string or SLI literal

obj: object Object to check

bool: True if obj is a “literal”

lib.hl_api_helper.is_sequence_of_connections ( seq )

Checks whether low-level API accepts seq as a sequence of connections.

seq: object Object to check

bool: True if object is an iterable of dictionaries or subscriptables of CONN_LEN

lib.hl_api_helper.is_sequence_of_gids ( seq )

Checks whether the argument is a potentially valid sequence of GIDs (non-negative integers).

seq: object Object to check

bool: True if object is a potentially valid sequence of GIDs

lib.hl_api_helper.is_string ( obj )

Check whether obj is a unicode string

obj: object Object to check

bool: True if obj is a unicode string

lib.hl_api_helper.model_deprecation_warning ( model )

Checks whether the model is to be removed in a future verstion of NEST. If so, a deprecation warning is issued.

model: str Name of model

lib.hl_api_helper.set_debug ( dbg=True )

Set the debug flag of the high-level API.

dbg: bool, optional Value to set the debug flag to

lib.hl_api_helper.set_verbosity( *args, **kwargs )

Change verbosity level for NEST’s messages.

level: str Can be one of ‘M_FATAL’, ‘M_ERROR’, ‘M_WARNING’, ‘M_DEPRECATED’, ‘M_INFO’ or ‘M_ALL’.

lib.hl_api_helper.show_deprecation_warning ( func_name, alt_func_name=None, text=None )

Shows a deprecation warning for a function.

func_name: str Name of the deprecated function

alt_func_name: str, optional Name of the function to use instead

text: str, optional Text to display instead of standard text

lib.hl_api_helper.stack_checker ( f )

Decorator to add stack checks to functions using PyNEST’s low-level API.

This decorator works only on functions. See check_stack() for the generic version for functions and classes.

f: function Function to decorate

function: Decorated function

kernel.NESTError

lib.hl_api_info module

Functions to get information on NEST.

lib.hl_api_info.GetStatus( *args, **kwargs )

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.

nodes: list or tuple Either a list of global ids of nodes, or a tuple of connection handles as returned by GetConnections()

keys: str or list, optional String or a list of strings naming model properties. GetDefaults then returns a single value or a list of values belonging to the keys given.

dict: All parameters

type: If keys is a string, the corrsponding default parameter is returned

list: If keys is a list of strings, a list of corrsponding default parameters is returned

TypeError Description

lib.hl_api_info.SetStatus( *args, **kwargs )

Set the parameters of nodes or connections to params.

If val is given, params has to be 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.

nodes: list or tuple Either a list of global ids of nodes, or a tuple of connection handles as returned by GetConnections()

params: str or dict or list Dictionary of parameters or list of dictionaries of parameters of same length as nodes. If val is given, this has to be the name of a model property as a str.

val: str, optional If given, params has to be the name of a model property.

TypeError Description

lib.hl_api_info.authors( *args, **kwargs )

Print the authors of NEST.

lib.hl_api_info.get_argv( *args, **kwargs )

Return argv as seen by NEST.

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

tuple: Argv, as seen by NEST.

lib.hl_api_info.help( *args, **kwargs )

Show the help page for the given object using the given pager.

The default pager is less.

obj: object, optional Object to display help for

pager: str, optional Pager to use

lib.hl_api_info.helpdesk( *args, **kwargs )

Open the NEST helpdesk in the given browser.

The default browser is firefox.

browser: str, optional Name of the browser to use

lib.hl_api_info.message( *args, **kwargs )

Print a message using NEST’s message system.

level : Level

sender : Message sender

text: str Text to be sent in the message

lib.hl_api_info.sysinfo( *args, **kwargs )

Print information on the platform on which NEST was compiled.

lib.hl_api_info.version( *args, **kwargs )

Return the NEST version.

str: The version of NEST.

lib.hl_api_models module

Functions for model handling

lib.hl_api_models.ConnectionRules( *args, **kwargs )

Return a typle of all available connection rules, sorted by name.

tuple: Available connection rules

lib.hl_api_models.CopyModel( *args, **kwargs )

Create a new model by copying an existing one.

existing: str Name of existing model

new: str Name of the copy of the existing model

params: dict, optional Default parameters assigned to the copy. Not provided parameters are taken from the existing model.

lib.hl_api_models.GetDefaults( *args, **kwargs )

Return a dictionary with the default parameters of the given model, specified by a string.

model: str Name of the model

keys: str or list, optional String or a list of strings naming model properties. GetDefaults then returns a single value or a list of values belonging to the keys given.

dict: All default parameters

type: If keys is a string, the corrsponding default parameter is returned

list: If keys is a list of strings, a list of corrsponding default parameters is returned

TypeError

GetDefaults(‘iaf_psc_alpha’,’V_m’) -> -70.0 GetDefaults(‘iaf_psc_alpha’,[‘V_m’, ‘model’) -> [-70.0, ‘iaf_psc_alpha’]

lib.hl_api_models.Models( *args, **kwargs )

Return a tuple of all available model (neurons, devices and synapses) names, sorted by name.

mtype: str, optional Use mtype=’nodes’ to only see neuron and device models, or mtype=’synapses’ to only see synapse models.

sel: str, optional String used to filter the result list and only return models containing it.

tuple: Available model names

  • Synapse model names ending with ‘_hpc’ provide minimal memory requirements by using thread-local target neuron IDs and fixing the rport to 0.
  • Synapse model names ending with ‘_lbl’ allow to assign an individual integer label (synapse_label) to created synapses at the cost of increased memory requirements.

ValueError Description

lib.hl_api_models.SetDefaults( *args, **kwargs )

Set the default parameters of the given model to the values specified in the params dictionary.

New default values are used for all subsequently created instances of the model.

model: str Name of the model

params: str or dict Dictionary of new default values. If val is given, this has to be the name of a model property as a str.

val: str, optional If given, params has to be the name of a model property.

lib.hl_api_nodes module

Functions for node handling

lib.hl_api_nodes.Create( *args, **kwargs )

Create n instances of type model.

model: str Name of the model to create

n: int, optional Number of instances to create

params: TYPE, optional Parameters for the new nodes. A single dictionary or a list of dictionaries with size n. If omitted, the model’s defaults are used.

list: Global IDs of created nodes

lib.hl_api_nodes.GetLID( *args, **kwargs )

Return the local id of a node with the global ID gid.

gid: int Global id of node

int: Local id of node

NESTError

lib.hl_api_parallel_computing module

Functions for parallel computing

lib.hl_api_parallel_computing.NumProcesses( *args, **kwargs )

Return the overall number of MPI processes.

int: Number of overall MPI processes

lib.hl_api_parallel_computing.Rank( *args, **kwargs )

Return the MPI rank of the local process.

int: MPI rank of the local process

lib.hl_api_parallel_computing.SetAcceptableLatency( *args, **kwargs )

Set the acceptable latency (in ms) for a MUSIC port.

port: object MUSIC port to set latency for

latency: float Latency in ms

lib.hl_api_parallel_computing.SetNumRecProcesses( *args, **kwargs )

Set the number of recording MPI processes.

Usually, spike detectors are distributed over all processes and record from local neurons only. If a number of processes is dedicated to spike detection, each spike detector is hosted on one of these processes and records globally from all simulating processes.

nrp: int Number of recording MPI processes

lib.hl_api_simulation module

Functions for simulation control

lib.hl_api_simulation.DisableStructuralPlasticity( *args, **kwargs )

Disable structural plasticity for the network simulation

lib.hl_api_simulation.EnableStructuralPlasticity( *args, **kwargs )

Enable structural plasticity for the network simulation

lib.hl_api_simulation.GetKernelStatus( *args, **kwargs )

Obtain parameters of the simulation kernel.

keys: str or list, optional Single parameter name or list of parameter names

dict: Parameter dictionary, if called without argument

type: Single parameter value, if called with single parameter name

list: List of parameter values, if called with list of parameter names

TypeError

lib.hl_api_simulation.GetStructuralPlasticityStatus( *args, **kwargs )

Get the current structural plasticity parameters for the network simulation.

lib.hl_api_simulation.Install( *args, **kwargs )

Load a dynamically linked NEST module.

module_name: str Name of the dynamically linked module

NEST module identifier, required for unloading.

nest.Install(“mymodule”)

Dynamically linked modules are searched in the LD_LIBRARY_PATH (DYLD_LIBRARY_PATH under OSX).

lib.hl_api_simulation.ResetKernel( *args, **kwargs )

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.

lib.hl_api_simulation.ResetNetwork( *args, **kwargs )

Reset all nodes and connections to their original state.

lib.hl_api_simulation.ResumeSimulation( *args, **kwargs )

Resume an interrupted simulation.

lib.hl_api_simulation.SetKernelStatus( *args, **kwargs )

Set parameters for the simulation kernel.

params: dict Dictionary of parameters to set.

GetKernelStatus

lib.hl_api_simulation.SetStructuralPlasticityStatus( *args, **kwargs )

Set structural plasticity parameters for the network simulation.

params: dict Dictionary of structural plasticity parameters to set

lib.hl_api_simulation.Simulate( *args, **kwargs )

Simulate the network for t milliseconds.

t: float Time to simulate in ms

lib.hl_api_subnets module

Functions for hierarchical networks

lib.hl_api_subnets.BeginSubnet( *args, **kwargs )

Create a new subnet and change into it.

label: str, optional Name of the new subnet

params: dict, optional The custict of the new subnet

lib.hl_api_subnets.ChangeSubnet( *args, **kwargs )

Make given subnet the current.

subnet: int GID of the subnet

NESTError

lib.hl_api_subnets.CurrentSubnet( *args, **kwargs )

Returns the global id of the current subnet.

int: GID of current subnet

lib.hl_api_subnets.EndSubnet( *args, **kwargs )

Change to the parent subnet and return the gid of the current.

NESTError Description

lib.hl_api_subnets.GetChildren( *args, **kwargs )

Return the global ids of the immediate children of the given subnets.

subnets: list GIDs of subnets

properties: dict, optional Only global ids of nodes matching the properties given in the dictionary exactly will be returned. Matching properties with float values (e.g. the membrane potential) may fail due to tiny numerical discrepancies and should be avoided.

local_only: bool, optional If True, only GIDs of nodes simulated on the local MPI process will be returned. By default, global ids of nodes in the entire simulation will be returned. This requires MPI communication and may slow down the script.

list: GIDs of leaf nodes

GetLeaves GetNodes

lib.hl_api_subnets.GetLeaves( *args, **kwargs )

Return the GIDs of the leaf nodes of the given subnets.

Leaf nodes are all nodes that are not subnets.

subnets: list GIDs of subnets

properties: dict, optional Only global ids of nodes matching the properties given in the dictionary exactly will be returned. Matching properties with float values (e.g. the membrane potential) may fail due to tiny numerical discrepancies and should be avoided.

local_only: bool, optional If True, only GIDs of nodes simulated on the local MPI process will be returned. By default, global ids of nodes in the entire simulation will be returned. This requires MPI communication and may slow down the script.

list: GIDs of leaf nodes

GetNodes GetChildren

lib.hl_api_subnets.GetNetwork( *args, **kwargs )

Return a nested list with the children of subnet id at level depth.

gid: int GID of subnet

depth: int Depth of list to return. If depth==0, the immediate children of the subnet are returned. The returned list is depth+1 dimensional.

list: nested lists of GIDs of child nodes

NESTError

lib.hl_api_subnets.GetNodes( *args, **kwargs )

Return the global ids of the all nodes of the given subnets.

subnets: list GIDs of subnets

properties: dict, optional Only global ids of nodes matching the properties given in the dictionary exactly will be returned. Matching properties with float values (e.g. the membrane potential) may fail due to tiny numerical discrepancies and should be avoided.

local_only: bool, optional If True, only GIDs of nodes simulated on the local MPI process will be returned. By default, global ids of nodes in the entire simulation will be returned. This requires MPI communication and may slow down the script.

list: GIDs of leaf nodes

GetLeaves GetChildren

lib.hl_api_subnets.LayoutNetwork( *args, **kwargs )

Create a subnetwork of dimension dim with nodes of type model and return a list of ids.

params is a dictionary, which will be set as custict of the newly created subnet.

model: str Neuron model to use

dim: int Dimension of subnetwork

label: str, optional Name of the new subnet

params: dict, optional The custict of the new subnet. Not the parameters for the neurons in the subnetwork.

ValueError Description

lib.hl_api_subnets.PrintNetwork( *args, **kwargs )

Print the network tree up to depth, starting at subnet.

If subnet is omitted, the current subnet is used instead.

depth: int, optional Depth to print to

subnet: TYPE, optional Subnet to start at

NESTError