NRP Core  1.4.1
NEST JSON Engine

This engine type enables the integration of the NEST spiking neural network simulator in NRP-core. It is based on the JSON over REST engine.

At initialization time, it loads a NEST simulation model described in a python script. At run time, it takes care of advancing the simulation when requested and of handling datapack data transfer.

DataPacks

This engine supports a unique datapack type: JsonDataPack. It contains the status of a set of neurons, detectors or synapsis as a dictionary or list of dictionaries. In fact, it can store the status of any NEST object which can be passed as argument to nest.GetStatus() and nest.SetStatus() functions.

nrp_core.engines.nest_json contains two functions that can be used to register datapacks with a NEST Json Engine:

  • RegisterDataPack: takes as arguments a string indicating the datapack name and a NEST object which status will be linked to the datapack
  • CreateDataPack: convenience function that internally calls nest.Create() and then RegisterDataPack(). Its first argument is the datapack name. The rest of the arguments the function is called with will be passed to nest.Create(). Both the datapack name and the return value of nest.Create() are then passed to RegisterDataPack().

After a datapack is registered using the functions described above, a NestEngineJSONDataPackController object is created to handle datapack I/O operations for this datapack in the Engine server. The NEST object passed to RegisterDataPack() is linked to this datapack controller. When the datapack is sent to the engine, it is passed to the controller which calls nest.SetStatus() with the datapack content. When the datapack is requested from the engine, the datapack controller calls nest.GetStatus() and stores the return value in the datapack data attribute.

In examples/nest_simple can be found a simple experiment showing the use of NEST JSON Engine. First, in the script nest_simple.py, a NEST network is defined and two datapacks with names noise and voltage are registered:

"""Init File. Imports nest and sets up a poisson generator, neuron, and voltmeter"""
import nest
import nest.voltage_trace
from nrp_core.engines.nest_json import RegisterDataPack, CreateDataPack
nest.set_verbosity("M_WARNING")
nest.ResetKernel()
noise = CreateDataPack("noise", "poisson_generator", 2)
neuron = nest.Create("iaf_psc_alpha")
voltmeter = nest.Create("voltmeter")
RegisterDataPack('voltage', voltmeter)
nest.Connect(noise, neuron, syn_spec={'weight': [[1.2, -1.0]], 'delay': 1.0})
nest.Connect(voltmeter, neuron)
# EOF

Then, in tf_1.py, the voltage JsonDataPack is accessed and its content printed out. Finally it returns a noise datapack that will be used to set the status of its linked NEST object after it has been received by the engine server:

from nrp_core import *
from nrp_core.data.nrp_json import *
from math import sin, cos
range_max = 100
sin_x = [abs(1000 * sin(x)) for x in range(range_max)]
cos_x = [abs(1000 * cos(x)) for x in range(range_max)]
n = 0
print(sin_x)
@EngineDataPack(keyword='voltage', id=DataPackIdentifier('voltage', 'nest'))
def transceiver_function(voltage):
# Read voltage
print(voltage)
# Set rate
global n
n = (n + 1) % range_max
noise_datapack = JsonDataPack("noise", "nest")
noise_datapack.data.append({"rate": sin_x[n]})
noise_datapack.data.append({"rate": cos_x[n]})
return [noise_datapack]
JsonDataPack Attributes
Attribute Description Python Type C type
data data contained in the datapack as a NlohmannJson object NlohmannJson nlohmann::json

Engine Configuration Parameters

This Engine type parameters are defined in the NestJSONEngine schema (listed here), which in turn is based on EngineBase and EngineJSON schemas and thus inherits all parameters from them.

To use the NEST JSON engine in an experiment, set EngineType to "nest_json".

NameDescriptionTypeDefaultRequiredArray
EngineNameName of the enginestringX
EngineTypeEngine type. Used by EngineLauncherManager to select the correct engine launcherstringX
EngineProcCmdEngine Process Launch commandstring
EngineProcStartParamsEngine Process Start Parametersstring[]X
EngineEnvParamsEngine Process Environment Parametersstring[]X
EngineLaunchCommandLaunchCommand with parameters that will be used to launch the engine processobject{"LaunchType":"BasicFork"}
EngineTimestepEngine Timestep in secondsnumber0.01
EngineCommandTimeoutEngine Timeout (in seconds). It tells how long to wait for the completion of the engine runStep. 0 or negative values are interpreted as no timeoutnumber0.0
NameDescriptionTypeDefaultRequiredArray
ServerAddressEngineJSONServer address. Should this address already be in use, the server will continue trying ports higher upstringlocalhost:9002
RegistrationServerAddressAddress EngineJSONRegistrationServer is listening at. Once the JSON engine server has bound to a port, it will use this address to register itself with the SimulationManagerstringlocalhost:9001
  • Parameters specific to this engine type:
NameDescriptionTypeDefaultRequiredArray
NestInitFileNamePath to the Python script that sets up the neural network for the simulationstringX
NestRNGSeedNest RNG seedinteger0

Schema

As explained above, the schema used by the NEST JSON engine inherits from EngineBase and EngineJSON schemas. A complete schema for the configuration of this engine is given below:

{"engine_nest_base" : {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nest Base",
"description": "Nest Base Engine configuration schema. Configuration for all nest engine implementations inherit from this one",
"$id": "#NestBase",
"properties" : {
"NestInitFileName": {
"type": "string",
"description": "Path to the python script that sets up the neural network for the simulation"
},
"NestRNGSeed": {
"type": "integer",
"default": 0,
"description": "Nest RNG seed"
}
},
"required": ["NestInitFileName"]
},
"engine_nest_json" : {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nest Json Engine",
"description": "Nest Json Engine",
"$id": "#NestJSONEngine",
"allOf": [
{ "$ref": "json://nrp-core/engines/engine_comm_protocols.json#/engine_json" },
{ "$ref": "#/engine_nest_base" },
{
"properties": {
"EngineType": { "enum": ["nest_json"] }
}
}
]
},
"engine_nest_server" : {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Nest Server Engine",
"description": "Nest Server Engine",
"$id": "#NestServerEngine",
"allOf": [
{ "$ref": "json://nrp-core/engines/engine_base.json#EngineBase" },
{ "$ref": "#/engine_nest_base" },
{
"properties": {
"EngineType": { "enum": ["nest_server"] },
"NestServerHost" : {
"type": "string",
"default": "localhost",
"description": "Nest Server Host"
},
"NestServerPort": {
"type": "integer",
"description": "Nest Server Port"
},
"MPIProcs": {
"type": "integer",
"default": 1,
"description": "Number of MPI processes used in the NEST simulation"
}
}
}
]
}
}
TransceiverFunction
Holds a single transfer function decorator.
Definition: transceiver_function.h:36
EngineDataPack
Class for input datapacks for transceiver functions, mapped to EngineDataPack python decorator.
Definition: from_engine_datapack.h:38
RegisterDataPack
void RegisterDataPack(python::str devName, python::object nodeCollection)
Definition: nrp_nest_python_module.cpp:40
DataPackIdentifier
Identifies a single datapack.
Definition: datapack_interface.h:38
DataPack
Base datapack class.
Definition: datapack.h:36
CreateDataPack
python::object CreateDataPack(python::tuple args, python::dict kwargs)
Definition: nrp_nest_python_module.cpp:34