NESTML Izhikevich tutorial


The aim of this exercise is to obtain familiarity with NESTML by completing a partial model of the Izhikevich neuron [1].


You need to have a working NEST Simulator and NESTML installation, see Installing NESTML.

You need to be able to run NESTML to generate and build model code. NESTML can be used from the command line, and via a Python API. The latter will be used in this notebook. See Running NESTML.

%matplotlib inline
import matplotlib.pyplot as plt
import nest
import numpy as np
import os

from pynestml.codegeneration.nest_code_generator_utils import NESTCodeGeneratorUtils


We assume here that we will generate code in a temporary directory /tmp/nestml-component. You can also create a unique temporary path using the Python tempfile module.

The Izhikevich model

A simple model for spiking neurons that nevertheless can exhibit a wide variety of dynamical behaviour, depending on its parameter values [1]. It is defined as follows:

\begin{align} \frac{dv}{dt} &= 0.04 v^2 + 5 v + 140 - u + I\\ \frac{du}{dt} &= a (b v - u) \end{align}

State update:


&text{if};; v geq V_{th}:\ &;;;; v text{ is set to } c\ &;;;; u text{ is incremented by } d\ & , \ &v text{ jumps on each spike arrival by the weight of the spike}


Example parameters for regular spiking (the meaning of these parameters is described in detail in the paper [1]; see also Task 2 below):

\begin{align} a&=0.02\\ b&=0.2\\ c&=-65~\text{mV}\\ d&=8 \end{align}

Task 1: Finish the model

In the file `izhikevich_task.nestml <>`__, only a subset of the parameters, state equations and update block is implemented.

Open the file in a text editor and finish the partially-completed model.

For reference, the solution is included as `izhikevich_solution.nestml <>`__.

NESTML code generation

Assume that our NESTML input model is at izhikevich_solution.nestml. To generate code and build a dynamic library that can be loaded as a user module in NEST Simulator:

# generate and build code
module_name, neuron_model_name = \
[6,izhikevich_tutorial6ab472512d2146018e56b9f1fb2ade9a_nestml, WARNING, [12:8;12:17]]: Variable 'a' has the same name as a physical unit!
[7,izhikevich_tutorial6ab472512d2146018e56b9f1fb2ade9a_nestml, WARNING, [15:8;15:17]]: Variable 'd' has the same name as a physical unit!
[17,izhikevich_tutorial6ab472512d2146018e56b9f1fb2ade9a_nestml, WARNING, [12:8;12:17]]: Variable 'a' has the same name as a physical unit!
[18,izhikevich_tutorial6ab472512d2146018e56b9f1fb2ade9a_nestml, WARNING, [15:8;15:17]]: Variable 'd' has the same name as a physical unit!
[24,izhikevich_tutorial6ab472512d2146018e56b9f1fb2ade9a_nestml, WARNING, [12:8;12:17]]: Variable 'a' has the same name as a physical unit!
[25,izhikevich_tutorial6ab472512d2146018e56b9f1fb2ade9a_nestml, WARNING, [15:8;15:17]]: Variable 'd' has the same name as a physical unit!

Check the generated log output for any potential error messages or warnings.

The generated extension module can be loaded using nest.Install():

# load dynamic library (NEST extension module) into NEST kernel

Instantiate model in NEST Simulator and run

Using the PyNEST API, the model can be instantiated and simulated in NEST. The following code will create one instance of the neuron model (nest.Create("izhikevich_tutorial")), inject a constant current and run the simulation for 250 ms.


neuron = nest.Create(neuron_model_name)
voltmeter = nest.Create("voltmeter")

voltmeter.set({"record_from": ["v", "u"]})
nest.Connect(voltmeter, neuron)

cgs = nest.Create('dc_generator')
cgs.set({"amplitude": 25.})
nest.Connect(cgs, neuron)

sr = nest.Create("spike_recorder")
nest.Connect(neuron, sr)


spike_times = nest.GetStatus(sr, keys='events')[0]['times']

fig, ax = plt.subplots(nrows=2)
ax[0].plot(voltmeter.get("events")["times"], voltmeter.get("events")["v"])
ax[1].plot(voltmeter.get("events")["times"], voltmeter.get("events")["u"])
ax[0].scatter(spike_times, 30 * np.ones_like(spike_times), marker="d", c="orange", alpha=.8, zorder=99)
for _ax in ax:
ax[0].set_ylabel("v [mV]")
ax[-1].set_xlabel("Time [ms]")
<ipython-input-4-ecc8223e4ba1>:30: UserWarning:Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure.

Task 2: Parameter space exploration

Perform a parameter space exploration to reproduce the bottom eight panels from [1], figure 2.


[1] Eugene M. Izhikevich, “Simple Model of Spiking Neurons”, IEEE Transactions on Neural Networks, Vol. 14, No. 6, November 2003