PyNEST - First Steps

Modeling networks of spiking neurons using NEST

Python Module of the Week, 03.05.2019

Alexander van Meegen

This notebook guides through your first steps using NEST. It shows

  • how to get help
  • how to create and simulate a single neuron
  • how to visualize the output

Essentially, this is a reproduction of the 'Hello World!' notebook with added explanations.

For more details see part 1 of the official PyNEST tutorial.


In [ ]:
# populate namespace with pylab functions and stuff
%pylab inline

In [ ]:
import nest # import NEST module

Getting help


In [ ]:
# information about functions with Python's help() ...
help(nest.Models)

In [ ]:
# ... or IPython's question mark
nest.Models?

In [ ]:
# list neuron models
nest.Models()

In [ ]:
# choose LIF neuron with exponential synaptic currents: 'iaf_psc_exp'
# look in documentation for model description
# or (if not compiled with MPI)
nest.help('iaf_psc_exp')

Creating a neuron


In [ ]:
# before creating a new network,
# reset the simulation kernel / remove all nodes
nest.ResetKernel()

In [ ]:
# create the neuron
neuron = nest.Create('iaf_psc_exp')

In [ ]:
# investigate the neuron

# Create() just returns a list (tuple) with handles to the new nodes
# (handles = integer numbers called ids)
neuron

In [ ]:
# current dynamical state/parameters of the neuron
# note that the membrane voltage is at -70 mV
nest.GetStatus(neuron)

Creating a spikegenerator


In [ ]:
# create a spike generator
spikegenerator = nest.Create('spike_generator')

In [ ]:
# check out 'spike_times' in its parameters
nest.GetStatus(spikegenerator)

In [ ]:
# set the spike times at 10 and 50 ms
nest.SetStatus(spikegenerator, {'spike_times': [10., 50.]})

Creating a voltmeter


In [ ]:
# create a voltmeter for recording
voltmeter = nest.Create('voltmeter')

In [ ]:
# investigate the voltmeter
voltmeter

In [ ]:
# see that it records membrane voltage, senders, times
nest.GetStatus(voltmeter)

Connecting


In [ ]:
# investigate Connect() function
nest.Connect?

In [ ]:
# connect spike generator and voltmeter to the neuron
nest.Connect(spikegenerator, neuron, syn_spec={'weight': 1e3})

In [ ]:
nest.Connect(voltmeter, neuron)

Simulating


In [ ]:
# run simulation for 100 ms
nest.Simulate(100.)

In [ ]:
# look at nest's KernelStatus:
# network_size (root node, neuron, spike generator, voltmeter)
# num_connections
# time (simulation duration)
nest.GetKernelStatus()

In [ ]:
# note that voltmeter has recorded 99 events
nest.GetStatus(voltmeter)

In [ ]:
# read out recording time and voltage from voltmeter
times = nest.GetStatus(voltmeter)[0]['events']['times']
voltages = nest.GetStatus(voltmeter)[0]['events']['V_m']

Plotting


In [ ]:
# plot results
# units can be found in documentation
pylab.plot(times, voltages, label='Neuron 1')
pylab.xlabel('Time (ms)')
pylab.ylabel('Membrane potential (mV)')
pylab.title('Membrane potential')
pylab.legend()

In [ ]:
# create the same plot with NEST's build-in plotting function
import nest.voltage_trace

In [ ]:
nest.voltage_trace.from_device(voltmeter)

Bored?

  • Try to make the neuron spike (maybe use 0_hello_world.ipynb)
  • Connect another neuron to the first neuron recieving that spike
  • Check out the official PyNEST tutorials, in particular
    • part 1: Neurons and simple neural networks
    • part 2: Populations of neurons