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

From version 28.1
edited by adavison
on 2022/10/04 13:55
Change comment: There is no comment for this version
To version 10.2
edited by adavison
on 2021/08/04 16:19
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,7 +1,6 @@
1 -
2 -(% class="box successmessage" %)
1 +(% class="box warningmessage" %)
3 3  (((
4 -[[https:~~/~~/www.youtube.com/watch?v=zBLNfJiEvRc>>https://www.youtube.com/watch?v=zBLNfJiEvRc]]
3 +tutorial under development
5 5  )))
6 6  
7 7  == Learning objectives ==
... ... @@ -10,11 +10,11 @@
10 10  
11 11  == Audience ==
12 12  
13 -This tutorial is intended for people with at least a basic knowledge of neuroscience (high-school level or above) and basic familiarity with the Python programming language. It should also be helpful for people who already have advanced knowledge of neuroscience and neural simulation, who simply wish to learn how to use PyNN and how it differs from other simulation tools they know.
12 +This tutorial is intended for people with at least a basic knowledge of neuroscience (high school level or above) and basic familiarity with the Python programming language. It should also be helpful for people who already have advanced knowledge of neuroscience and neural simulation, who simply wish to learn how to use PyNN, and how it differs from other simulation tools they know.
14 14  
15 15  == Prerequisites ==
16 16  
17 -To follow this tutorial, you need a basic knowledge of neuroscience (high-school level or greater), basic familiarity with the Python programming language, and either a computer with PyNN, NEST, NEURON, and Brian 2 installed or an EBRAINS account and basic familiarity with Jupyter notebooks. If you don't have these tools installed, see one of our previous tutorials which guide you through the installation.
16 +To follow this tutorial, you need a basic knowledge of neuroscience (high-school level or greater), basic familiarity with the Python programming language, and either a computer with PyNN, NEST, NEURON and Brian 2 installed, or an EBRAINS account and basic familiarity with Jupyter notebooks. If you don't have these tools installed, see one of our previous tutorials which guide you through the installation.
18 18  
19 19  == Format ==
20 20  
... ... @@ -45,7 +45,7 @@
45 45  **Slide** listing prerequisites
46 46  )))
47 47  
48 -To follow this tutorial, you need a basic knowledge of neuroscience (high-school level or higher), basic familiarity with the Python programming language, and you should have already followed our earlier tutorial video which guides you through the installation process.
47 +To follow this tutorial, you need a basic knowledge of neuroscience (high-school level or greater), basic familiarity with the Python programming language, and you should have already followed our earlier tutorial video which guides you through the installation process.
49 49  
50 50  This video covers PyNN 0.10. If you've installed a more recent version of PyNN, you might want to look for an updated version of this video.
51 51  
... ... @@ -67,13 +67,13 @@
67 67  **Screencast** - blank document in editor
68 68  )))
69 69  
70 -In this video, you'll see my editor on the left and my terminal and my file browser on the right. I'll be writing code in the editor and then running my scripts in the terminal. You're welcome to follow along~-~--you can pause the video at any time if I'm going too fast~-~--or you can just watch.
69 +In this video, you'll see my editor on the left, and on the right my terminal and my file browser. I'll be writing code in the editor, and then running my scripts in the terminal. You're welcome to follow along~-~--you can pause the video at any time if I'm going too fast~-~--or you can just watch.
71 71  
72 -Let's start by writing a docstring "Simple network model using PyNN".
71 +Let's start by writing a docstring, "Simple network model using PyNN".
73 73  
74 -For now, we're going to use the NEST simulator to simulate this model; so, we import the PyNN-for-NEST module.
73 +For now, we're going to use the NEST simulator to simulate this model, so we import the PyNN-for-NEST module.
75 75  
76 -Like with any numerical model, we need to break time down into small steps; so let's set that up with steps of 0.1 milliseconds.
75 +Like with any numerical model, we need to break time down into small steps, so let's set that up with steps of 0.1 milliseconds.
77 77  
78 78  (% class="box infomessage" %)
79 79  (((
... ... @@ -85,7 +85,7 @@
85 85  
86 86  PyNN comes with a selection of integrate-and-fire models. We're going to use the IF_curr_exp model, where "IF" is for integrate-and-fire, "curr" means that synaptic responses are changes in current, and "exp" means that the shape of the current is a decaying exponential function.
87 87  
88 -This is where we set the parameters of the model: the resting membrane potential is -65 millivolts, the spike threshold is -55 millivolts, the reset voltage after a spike is again -65 millivolts, the refractory period after a spike is one millisecond, the membrane time constant is 10 milliseconds, and the membrane capacitance is 1 nanofarad. We're also going to inject a constant bias current of 1.1 nanoamps into these neurons, so that we get some action potentials.
87 +This is where we set the parameters of the model: the resting membrane potential is -65 millivolts, the spike threshold is -55 millivolts, the reset voltage after a spike is again -65 millivolts, the refractory period after a spike is one millisecond, the membrane time constant is 10 milliseconds, and the membrane capacitance is 1 nanofarad. We're also going to inject a constant bias current of 0.1 nanoamps into these neurons, so that we get some action potentials.
89 89  
90 90  (% class="box infomessage" %)
91 91  (((
... ... @@ -93,10 +93,10 @@
93 93  \\(% style="color:#000000" %)"""Simple network model using PyNN"""
94 94  \\import pyNN.nest as sim
95 95  sim.setup(timestep=0.1)(%%)
96 -(% style="color:#e74c3c" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, tau_refrac=1, tau_m=10, cm=1, i_offset=1.1)
95 +(% style="color:#e74c3c" %)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)
97 97  )))
98 98  
99 -Let's create 100 of these neurons; then, we're going to record the membrane voltage and run a simulation for 100 milliseconds.
98 +Let's create 100 of these neurons, then we're going to record the membrane voltage, and run a simulation for 100 milliseconds.
100 100  
101 101  (% class="box infomessage" %)
102 102  (((
... ... @@ -104,268 +104,40 @@
104 104  \\(% style="color:#000000" %)"""Simple network model using PyNN"""
105 105  \\import pyNN.nest as sim
106 106  sim.setup(timestep=0.1)(%%)
107 -(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, tau_refrac=1, tau_m=10, cm=1, i_offset=1.1)(%%)
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)(%%)
108 108  (% style="color:#e74c3c" %)population1 = sim.Population(100, cell_type, label="Population 1")
109 109  population1.record("v")
110 -sim.run(100.0)(%%)
111 -\\**Run script in terminal**
109 +sim.run(100.0)
112 112  )))
113 113  
114 114  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).
115 115  
116 -(% class="box infomessage" %)
117 -(((
118 -**Screencast** - current state of editor
119 -\\(% style="color:#000000" %)"""Simple network model using PyNN"""
120 -\\import pyNN.nest as sim(%%)
121 -(% style="color:#e74c3c" %)from pyNN.utility.plotting import Figure, Panel(%%)
122 -(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
123 -(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, tau_refrac=1, tau_m=10, cm=1, i_offset=1.1)(%%)
124 -(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
125 -population1.record("v")
126 -sim.run(100.0)(%%)
127 -(% style="color:#e74c3c" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
128 -Figure(
129 - Panel(
130 - data_v[:, 0],
131 - xticks=True, xlabel="Time (ms)",
132 - yticks=True, ylabel="Membrane potential (mV)"
133 - ),
134 - title="Response of neuron #0",
135 - annotations="Simulated with NEST"
136 -).show()(%%)
137 -\\**Run script in terminal, show figure**
138 -)))
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.
139 139  
140 -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.
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.
141 141  
142 -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.
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 143  
144 -(% class="box infomessage" %)
145 -(((
146 -**Screencast** - changes in editor
147 -
120 +Now if we run our simulation again, we can see the effect of this heterogeneity in the neuron population.
148 148  
149 -**...**
150 -(% style="color:#000000" %)Figure(
151 - Panel(
152 - data_v[:, (% style="color:#e74c3c" %)0:5(% style="color:#000000" %)],
153 - xticks=True, xlabel="Time (ms)",
154 - yticks=True, ylabel="Membrane potential (mV)"
155 - ),
156 - title="Response of (% style="color:#e74c3c" %)first five neurons(% style="color:#000000" %)",
157 - annotations="Simulated with NEST"
158 -).show()(%%)
159 -\\**Run script in terminal, show figure**
160 -)))
122 +TO BE COMPLETED
161 161  
162 -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.
124 +(% class="wikigeneratedid" id="HSummary28Inthistutorial2CyouhavelearnedtodoX202629" %)
125 +(% class="small" %)**Summary (In this tutorial, you have learned to do X…)**
163 163  
164 -(% class="box infomessage" %)
165 -(((
166 -**Screencast** - changes in editor
167 -\\(% style="color:#000000" %)"""Simple network model using PyNN"""
168 -\\import pyNN.nest as sim(%%)
169 -(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
170 -(% style="color:#e74c3c" %)from pyNN.random import RandomDistribution, NumpyRNG(%%)
171 -(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
172 -(% style="color:#e74c3c" %)rng = NumpyRNG(seed=1)(%%)
173 -(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
174 - (% style="color:#e74c3c" %) v_rest=RandomDistribution('normal', mu=-65.0, sigma=1.0, rng=rng),
175 - v_thresh=RandomDistribution('normal', mu=-55.0, sigma=1.0, rng=rng),
176 - v_reset=RandomDistribution('normal', mu=-65.0, sigma=1.0, rng=rng), (%%)
177 -(% style="color:#000000" %) tau_refrac=1, tau_m=10, cm=1, i_offset=1.1)
127 +.
178 178  
179 -**...**
180 -
129 +(% class="wikigeneratedid" id="HAcknowledgementsifappropriate" %)
130 +(% class="small" %)**Acknowledgements if appropriate**
181 181  
182 -(% style="color:#000000" %)Figure(
183 - Panel(
184 - data_v[:, 0:5],
185 - xticks=True, xlabel="Time (ms)",
186 - yticks=True, ylabel="Membrane potential (mV)"
187 - ),
188 - title="Response of first five neurons (% style="color:#e74c3c" %)with heterogeneous parameters(% style="color:#000000" %)",
189 - annotations="Simulated with NEST"
190 -).show()(%%)
191 -\\**Run script in terminal, show figure**
192 -)))
132 +.
193 193  
194 -Now, if we run our simulation again, we can see the effect of this heterogeneity in the neuron population.
134 +(% class="wikigeneratedid" id="HReferencestowebsites28Formoreinformation2Cvisitusat202629" %)
135 +(% class="small" %)**References to websites (For more information, visit us at…)**
195 195  
196 -(% class="box successmessage" %)
197 -(((
198 -**Slide** showing addition of second population and of connections between them
199 -)))
137 +.
200 200  
201 -(% class="wikigeneratedid" %)
202 -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.
139 +(% class="wikigeneratedid" id="HContactinformation28Forquestions2Ccontactusat202629" %)
140 +(% class="small" %)**Contact information (For questions, contact us at…)**
203 203  
204 -(% class="box infomessage" %)
205 -(((
206 -**Screencast** - changes in editor
207 -\\**...**
208 -(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
209 -(% style="color:#e74c3c" %)population2 = sim.Population(100, cell_type, label="Population 2")
210 -population2.set(i_offset=0)(%%)
211 -(% style="color:#000000" %)population1.record("v")(%%)
212 -(% style="color:#e74c3c" %)population2.record("v")(%%)
213 -(% style="color:#000000" %)sim.run(100.0)(%%)
214 -**...**
215 -)))
216 -
217 -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.
218 -
219 -(% class="box successmessage" %)
220 -(((
221 -**Slide** showing all-to-all connections
222 -)))
223 -
224 -We could connect all neurons in Population 1 to all those in Population 2.
225 -
226 -(% class="box successmessage" %)
227 -(((
228 -**Slide** showing random connections
229 -)))
230 -
231 -We could connect the populations randomly, in several different ways.
232 -
233 -(% class="box successmessage" %)
234 -(((
235 -**Slide** showing distance-dependent connections
236 -)))
237 -
238 -(% class="wikigeneratedid" %)
239 -We could connect the populations randomly, but with a probability of connection that depends on the distance between the neurons.
240 -
241 -(% class="box successmessage" %)
242 -(((
243 -**Slide** showing explicit lists of connections
244 -)))
245 -
246 -(% class="wikigeneratedid" %)
247 -Or we could connect the neurons in a very specific manner, based on an explicit list of connections.
248 -
249 -(% class="wikigeneratedid" %)
250 -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.
251 -
252 -(% class="box successmessage" %)
253 -(((
254 -**Slide** showing addition of second population, and of connections between them, labelled as a Projection.
255 -)))
256 -
257 -(% class="wikigeneratedid" %)
258 -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.
259 -
260 -(% class="box infomessage" %)
261 -(((
262 -**Screencast** - changes in editor
263 -
264 -
265 -**...**
266 -(% style="color:#000000" %)population2.record("v")(%%)
267 -(% style="color:#e74c3c" %)connection_algorithm = sim.FixedProbabilityConnector(p_connect=0.5, rng=rng)
268 -synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5)
269 -connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%)
270 -(% style="color:#000000" %)sim.run(100.0)(%%)
271 -**...**
272 -)))
273 -
274 -(% class="wikigeneratedid" %)
275 -Finally, let's update our figure, by adding a second panel to show the responses of Population 2.
276 -
277 -(% class="box infomessage" %)
278 -(((
279 -**Screencast** - changes in editor
280 -\\**...**
281 -(% style="color:#000000" %)sim.run(100.0)(%%)
282 -(% style="color:#e74c3c" %)data1_v(% style="color:#000000" %) = population1.get_data().segments[0].filter(name='v')[0](%%)
283 -(% style="color:#e74c3c" %)data2_v = population2.get_data().segments[0].filter(name='v')[0](%%)
284 -(% style="color:#000000" %)Figure(
285 - Panel(
286 - (% style="color:#e74c3c" %)data1_v(% style="color:#000000" %)[:, 0:5],
287 - xticks=True, (% style="color:#e74c3c" %)--xlabel="Time (ms)",--(%%)
288 -(% style="color:#000000" %) yticks=True, ylabel="Membrane potential (mV)"
289 - ),
290 - (% style="color:#e74c3c" %)Panel(
291 - data2_v[:, 0:5],
292 - xticks=True, xlabel="Time (ms)",
293 - yticks=True
294 - ),(%%)
295 -(% style="color:#000000" %) title="Response of (% style="color:#e74c3c" %)simple network(% style="color:#000000" %)",
296 - annotations="Simulated with NEST"
297 -).show()
298 -
299 -**Run script in terminal, show figure**
300 -)))
301 -
302 -(% class="wikigeneratedid" %)
303 -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.
304 -
305 -(% class="box infomessage" %)
306 -(((
307 -**Screencast** - final state of editor
308 -\\(% style="color:#000000" %)"""Simple network model using PyNN"""
309 -\\import pyNN.(% style="color:#e74c3c" %)neuron(% style="color:#000000" %) as sim(%%)
310 -(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
311 -(% style="color:#000000" %)from pyNN.random import RandomDistribution, NumpyRNG(%%)
312 -(% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
313 -(% style="color:#000000" %)rng = NumpyRNG(seed=1)(%%)
314 -(% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
315 - v_rest=RandomDistribution('normal', mu=-65.0, sigma=1.0, rng=rng),
316 - v_thresh=RandomDistribution('normal', mu=-55.0, sigma=1.0, rng=rng),
317 - v_reset=RandomDistribution('normal', mu=-65.0, sigma=1.0, rng=rng), 
318 - tau_refrac=1, tau_m=10, cm=1, i_offset=1.1)
319 -population1 = sim.Population(100, cell_type, label="Population 1")
320 -population2 = sim.Population(100, cell_type, label="Population 2")
321 -population2.set(i_offset=0)
322 -population1.record("v")
323 -population2.record("v")
324 -connection_algorithm = sim.FixedProbabilityConnector(p_connect=0.5, rng=rng)
325 -synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5)
326 -connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%)
327 -(% style="color:#000000" %)sim.run(100.0)(%%)
328 -(% style="color:#000000" %)data1_v = population1.get_data().segments[0].filter(name='v')[0]
329 -data2_v = population2.get_data().segments[0].filter(name='v')[0]
330 -Figure(
331 - Panel(
332 - data1_v[:, 0:5],
333 - xticks=True,
334 - yticks=True, ylabel="Membrane potential (mV)"
335 - ),
336 - Panel(
337 - data2_v[:, 0:5],
338 - xticks=True, xlabel="Time (ms)",
339 - yticks=True
340 - ),(%%)
341 -(% style="color:#000000" %) title="Response of simple network",
342 - annotations="Simulated with (% style="color:#e74c3c" %)NEURON(% style="color:#000000" %)"
343 -).show()
344 -
345 -**Run script in terminal, show figure**
346 -)))
347 -
348 -(% class="wikigeneratedid" %)
349 -As you would hope, NEST and NEURON give essentially identical results.
350 -
351 -(% class="box successmessage" %)
352 -(((
353 -**Slide** recap of learning objectives
354 -)))
355 -
356 -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.
357 -
358 -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.
359 -
360 -We will be releasing a series of tutorials, throughout this year, to introduce these more advanced features of PyNN, so keep an eye on the EBRAINS website.
361 -
362 -(% class="box successmessage" %)
363 -(((
364 -**Slide** acknowledgements, contact information
365 -)))
366 -
367 -(% class="wikigeneratedid" %)
368 -PyNN has been developed by many different people, with financial support from several organisations. I'd like to mention in particular the CNRS and the European Commission, through the FACETS, BrainScaleS, and Human Brain Project grants.
369 -
370 -(% class="wikigeneratedid" %)
371 -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.
142 +.