Last modified by adavison on 2022/10/04 13:55

From version 10.2
edited by adavison
on 2021/08/04 16:19
Change comment: There is no comment for this version
To version 14.1
edited by adavison
on 2021/09/30 15:27
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -106,37 +106,324 @@
106 106  (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
107 107  (% style="color:#e74c3c" %)population1 = sim.Population(100, cell_type, label="Population 1")
108 108  population1.record("v")
109 -sim.run(100.0)
109 +sim.run(100.0)(%%)
110 +\\**Run script in terminal**
110 110  )))
111 111  
112 112  PyNN has some built-in tools for making simple plots, so let's import those, and plot the membrane voltage of the zeroth neuron in our population (remember Python starts counting at zero).
113 113  
115 +(% class="box infomessage" %)
116 +(((
117 +**Screencast** - current state of editor
118 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
119 +\\import pyNN.nest as sim(%%)
120 +(% style="color:#e74c3c" %)from pyNN.utility.plotting import Figure, Panel(%%)
121 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
122 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
123 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
124 +population1.record("v")
125 +sim.run(100.0)(%%)
126 +(% style="color:#e74c3c" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
127 +Figure(
128 + Panel(
129 + data_v[:, 0],
130 + xticks=True, xlabel="Time (ms)",
131 + yticks=True, ylabel="Membrane potential (mV)"
132 + ),
133 + title="Response of neuron #0",
134 + annotations="Simulated with NEST"
135 +).show()(%%)
136 +\\**Run script in terminal, show figure**
137 +)))
138 +
114 114  As you'd expect, the bias current causes the membrane voltage to increase until it reaches threshold~-~--it doesn't increase in a straight line because it's a //leaky// integrate-and-fire neuron~-~--then once it hits the threshold the voltage is reset, and then stays at the same level for a short time~-~--this is the refractory period~-~--before it starts to increase again.
115 115  
116 116  Now, all 100 neurons in our population are identical, so if we plotted the first neuron, the second neuron, ..., we'd get the same trace.
117 117  
118 -Let's change that. In nature every neuron is a little bit different, so let's set the resting membrane potential and the spike threshold randomly from a Gaussian distribution, and let's plot membrane voltage from _all_ the  neurons.
143 +(% class="box infomessage" %)
144 +(((
145 +**Screencast** - current state of editor
146 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
147 +\\import pyNN.nest as sim(%%)
148 +(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
149 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
150 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
151 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
152 +population1.record("v")
153 +sim.run(100.0)(%%)
154 +(% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
155 +Figure(
156 + Panel(
157 + data_v[:, (% style="color:#e74c3c" %)0:5(% style="color:#000000" %)],
158 + xticks=True, xlabel="Time (ms)",
159 + yticks=True, ylabel="Membrane potential (mV)"
160 + ),
161 + title="Response of (% style="color:#e74c3c" %)first five neurons(% style="color:#000000" %)",
162 + annotations="Simulated with NEST"
163 +).show()(%%)
164 +\\**Run script in terminal, show figure**
165 +)))
119 119  
167 +Let's change that. In nature every neuron is a little bit different, so let's set the resting membrane potential and the spike threshold randomly from a Gaussian distribution.
168 +
169 +(% class="box infomessage" %)
170 +(((
171 +**Screencast** - current state of editor
172 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
173 +\\import pyNN.nest as sim(%%)
174 +(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
175 +(% style="color:#e74c3c" %)from pyNN.random import RandomDistribution(%%)
176 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
177 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
178 + (% style="color:#e74c3c" %) v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
179 + v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
180 + v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
181 +(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
182 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
183 +population1.record("v")
184 +sim.run(100.0)(%%)
185 +(% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
186 +Figure(
187 + Panel(
188 + data_v[:, 0:5],
189 + xticks=True, xlabel="Time (ms)",
190 + yticks=True, ylabel="Membrane potential (mV)"
191 + ),
192 + title="Response of first five neurons (% style="color:#e74c3c" %)with heterogeneous parameters(% style="color:#000000" %)",
193 + annotations="Simulated with NEST"
194 +).show()(%%)
195 +\\**Run script in terminal, show figure**
196 +)))
197 +
120 120  Now if we run our simulation again, we can see the effect of this heterogeneity in the neuron population.
121 121  
122 -TO BE COMPLETED
200 +(% class="box successmessage" %)
201 +(((
202 +**Slide** showing addition of second population, and of connections between them
203 +)))
123 123  
124 -(% class="wikigeneratedid" id="HSummary28Inthistutorial2CyouhavelearnedtodoX202629" %)
125 -(% class="small" %)**Summary (In this tutorial, you have learned to do X…)**
205 +(% class="wikigeneratedid" %)
206 +So far we have a population of neurons, but there are no connections between them, we don't have a network. Let's add a second population of the same size as the first, but we'll set the offset current to zero, so they don't fire action potentials spontaneously.
126 126  
127 -.
208 +(% class="box infomessage" %)
209 +(((
210 +**Screencast** - current state of editor
211 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
212 +\\import pyNN.nest as sim(%%)
213 +(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
214 +(% style="color:#000000" %)from pyNN.random import RandomDistribution(%%)
215 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
216 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
217 + (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
218 + v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
219 + v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
220 +(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
221 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
222 +(% style="color:#e74c3c" %)population2 = sim.Population(100, cell_type, label="Population 2")
223 +population2.set(i_offset=0)(%%)
224 +(% style="color:#000000" %)population1.record("v")(%%)
225 +(% style="color:#e74c3c" %)population2.record("v")(%%)
226 +(% style="color:#000000" %)sim.run(100.0)(%%)
227 +(% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
228 +Figure(
229 + Panel(
230 + data_v[:, 0:5],
231 + xticks=True, xlabel="Time (ms)",
232 + yticks=True, ylabel="Membrane potential (mV)"
233 + ),
234 + title="Response of first five neurons with heterogeneous parameters",
235 + annotations="Simulated with NEST"
236 +).show()
237 +)))
128 128  
129 -(% class="wikigeneratedid" id="HAcknowledgementsifappropriate" %)
130 -(% class="small" %)**Acknowledgements if appropriate**
239 +Now we want to create synaptic connections between the neurons in Population 1 and those in Population 2. There are lots of different ways these could be connected.
131 131  
132 -.
241 +(% class="box successmessage" %)
242 +(((
243 +**Slide** showing all-to-all connections
244 +)))
133 133  
134 -(% class="wikigeneratedid" id="HReferencestowebsites28Formoreinformation2Cvisitusat202629" %)
135 -(% class="small" %)**References to websites (For more information, visit us at…)**
246 +We could connect all neurons in Population 1 to all those in Population 2.
136 136  
137 -.
248 +(% class="box successmessage" %)
249 +(((
250 +**Slide** showing random connections
251 +)))
138 138  
139 -(% class="wikigeneratedid" id="HContactinformation28Forquestions2Ccontactusat202629" %)
140 -(% class="small" %)**Contact information (For questions, contact us at…)**
253 +We could connect the populations randomly, in several different ways.
141 141  
142 -.
255 +(% class="box successmessage" %)
256 +(((
257 +**Slide** showing distance-dependent connections
258 +)))
259 +
260 +(% class="wikigeneratedid" %)
261 +We could connect the populations randomly, but with a probability of connection that depends on the distance between the neurons.
262 +
263 +(% class="box successmessage" %)
264 +(((
265 +**Slide** showing explicit lists of connections
266 +)))
267 +
268 +(% class="wikigeneratedid" %)
269 +Or we could connect the neurons in a very specific manner, based on an explicit list of connections.
270 +
271 +(% class="wikigeneratedid" %)
272 +Just as PyNN provides a variety of neuron models, so it comes with a range of connection algorithms built in. You can also add your own connection methods.
273 +
274 +(% class="box successmessage" %)
275 +(((
276 +**Slide** showing addition of second population, and of connections between them, labelled as a Projection.
277 +)))
278 +
279 +(% class="wikigeneratedid" %)
280 +In PyNN, we call a group of connections between two populations a _Projection_. To create a Projection, we need to specify the presynaptic population, the postsynaptic population, the connection algorithm, and the synapse model. Here we're using the simplest synapse model available in PyNN, for which the synaptic weight is constant over time, there is no plasticity.
281 +
282 +(% class="box infomessage" %)
283 +(((
284 +**Screencast** - current state of editor
285 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
286 +\\import pyNN.nest as sim(%%)
287 +(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
288 +(% style="color:#000000" %)from pyNN.random import RandomDistribution(%%)
289 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
290 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
291 + (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
292 + v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
293 + v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
294 +(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
295 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
296 +(% style="color:#000000" %)population2 = sim.Population(100, cell_type, label="Population 2")
297 +population2.set(i_offset=0)
298 +population1.record("v")
299 +population2.record("v")(%%)
300 +(% style="color:#e74c3c" %)connection_algorithm = sim.FixedProbabilityConnector(p=0.5)
301 +synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5)
302 +connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%)
303 +(% style="color:#000000" %)sim.run(100.0)(%%)
304 +(% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
305 +Figure(
306 + Panel(
307 + data_v[:, 0:5],
308 + xticks=True, xlabel="Time (ms)",
309 + yticks=True, ylabel="Membrane potential (mV)"
310 + ),
311 + title="Response of first five neurons with heterogeneous parameters",
312 + annotations="Simulated with NEST"
313 +).show()
314 +)))
315 +
316 +(% class="wikigeneratedid" %)
317 +Finally, let's update our figure, by adding a second panel to show the responses of Population 2.
318 +
319 +(% class="box infomessage" %)
320 +(((
321 +**Screencast** - current state of editor
322 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
323 +\\import pyNN.nest as sim(%%)
324 +(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
325 +(% style="color:#000000" %)from pyNN.random import RandomDistribution(%%)
326 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
327 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
328 + (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
329 + v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
330 + v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
331 +(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
332 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
333 +(% style="color:#000000" %)population2 = sim.Population(100, cell_type, label="Population 2")
334 +population2.set(i_offset=0)
335 +population1.record("v")
336 +population2.record("v")(%%)
337 +(% style="color:#000000" %)connection_algorithm = sim.FixedProbabilityConnector(p=0.5)
338 +synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5)
339 +connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%)
340 +(% style="color:#000000" %)sim.run(100.0)(%%)
341 +(% style="color:#e74c3c" %)data1_v(% style="color:#000000" %) = population1.get_data().segments[0].filter(name='v')[0](%%)
342 +(% style="color:#e74c3c" %)data2_v = population2.get_data().segments[0].filter(name='v')[0](%%)
343 +(% style="color:#000000" %)Figure(
344 + Panel(
345 + (% style="color:#e74c3c" %)data1_v(% style="color:#000000" %)[:, 0:5],
346 + xticks=True, (% style="color:#e74c3c" %)--xlabel="Time (ms)",--(%%)
347 +(% style="color:#000000" %) yticks=True, ylabel="Membrane potential (mV)"
348 + ),
349 + (% style="color:#e74c3c" %)Panel(
350 + data2_v[:, 0:5],
351 + xticks=True, xlabel="Time (ms)",
352 + yticks=True"
353 + ),(%%)
354 +(% style="color:#000000" %) title="Response of (% style="color:#e74c3c" %)simple network(% style="color:#000000" %)",
355 + annotations="Simulated with NEST"
356 +).show()
357 +
358 +**Run script in terminal, show figure**
359 +)))
360 +
361 +(% class="wikigeneratedid" %)
362 +and there we have it, our simple neuronal network of integrate-and-fire neurons, written in PyNN, simulated with NEST. If you prefer to use the NEURON simulator, PyNN makes this very simple, we import the PyNN-for-NEURON module instead.
363 +
364 +(% class="box infomessage" %)
365 +(((
366 +**Screencast** - current state of editor
367 +\\(% style="color:#000000" %)"""Simple network model using PyNN"""
368 +\\import pyNN.(% style="color:#e74c3c" %)neuron(% style="color:#000000" %) as sim(%%)
369 +(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
370 +(% style="color:#000000" %)from pyNN.random import RandomDistribution(%%)
371 +(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
372 +(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
373 + (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
374 + v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
375 + v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
376 +(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
377 +(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
378 +(% style="color:#000000" %)population2 = sim.Population(100, cell_type, label="Population 2")
379 +population2.set(i_offset=0)
380 +population1.record("v")
381 +population2.record("v")(%%)
382 +(% style="color:#000000" %)connection_algorithm = sim.FixedProbabilityConnector(p=0.5)
383 +synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5)
384 +connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%)
385 +(% style="color:#000000" %)sim.run(100.0)(%%)
386 +(% style="color:#000000" %)data1_v = population1.get_data().segments[0].filter(name='v')[0]
387 +data2_v = population2.get_data().segments[0].filter(name='v')[0]
388 +Figure(
389 + Panel(
390 + data1_v[:, 0:5],
391 + xticks=True,
392 + yticks=True, ylabel="Membrane potential (mV)"
393 + ),
394 + Panel(
395 + data2_v[:, 0:5],
396 + xticks=True, xlabel="Time (ms)",
397 + yticks=True"
398 + ),(%%)
399 +(% style="color:#000000" %) title="Response of simple network",
400 + annotations="Simulated with (% style="color:#e74c3c" %)NEURON(% style="color:#000000" %)"
401 +).show()
402 +
403 +**Run script in terminal, show figure**
404 +)))
405 +
406 +(% class="wikigeneratedid" %)
407 +As you would hope, NEST and NEURON give essentially identical results.
408 +
409 +(% class="box successmessage" %)
410 +(((
411 +**Slide** recap of learning objectives
412 +)))
413 +
414 +That is the end of this tutorial, in which I've demonstrated how to build a simple network using PyNN, and to simulate it using two different simulators, NEST and NEURON.
415 +
416 +Of course, PyNN allows you to create much more complex networks than this, with more realistic neuron models, synaptic plasticity, spatial structure, and so on. You can also use other simulators, such as Brian or SpiNNaker, and you can run simulations in parallel on clusters or supercomputers.
417 +
418 +We will be releasing a series of tutorials, throughout the rest of 2021 and 2022, to introduce these more advanced features of PyNN, so keep an eye on the EBRAINS website.
419 +
420 +(% class="box successmessage" %)
421 +(((
422 +**Slide** acknowledgements, contact information
423 +)))
424 +
425 +(% class="wikigeneratedid" %)
426 +PyNN has been developed by many different people, with financial support from several different organisations. I'd like to mention in particular the CNRS and the European Commission, through the FACETS, BrainScaleS and Human Brain Project grants.
427 +
428 +(% class="wikigeneratedid" %)
429 +For more information visit neuralensemble.org/PyNN. If you have questions you can contact us through the PyNN Github project, the NeuralEnsemble forum, EBRAINS support, or the EBRAINS Community.