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'))
@TransceiverFunction("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]

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

Name

Description

Type

Default

Required

Array

EngineName

Name of the engine

string

X

EngineType

Engine type. Used by

string

X

EngineProcCmd

Engine Process Launch command

string

EngineProcStartParams

Engine Process Start Parameters

string

[]

X

EngineEnvParams

Engine Process Environment Parameters

string

[]

X

EngineLaunchCommand

object

{“LaunchType”:”BasicFork”}

EngineTimestep

Engine Timestep in seconds

number

0.01

EngineCommandTimeout

Engine Timeout (in seconds). It tells how long to wait for the completion of the engine runStep. 0 or negative values are interpreted as no timeout

number

0.0

Name

Description

Type

Default

Required

Array

ServerAddress

string

localhost:9002

RegistrationServerAddress

Address

string

localhost:9001

  • Parameters specific to this engine type:

Name

Description

Type

Default

Required

Array

NestInitFileName

Path to the Python script that sets up the neural network for the simulation

string

X

NestRNGSeed

Nest RNG seed

integer

0

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"
          }
        }
      }
    ]
  }
}