1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414import os
15+ from typing import Optional , Tuple
16+
1517import pyNN .spiNNaker as sim
1618import numpy
1719import matplotlib .pyplot as pylab
20+
21+ from spynnaker .pyNN .models .neuron import ConnectionHolder
22+ from spynnaker .pyNN .models .projection import Projection
23+ from spynnaker .pyNN .models .populations .population import Population
1824from spynnaker .pyNN .utilities import neo_convertor
1925
26+
2027# how much slowdown to put into the network to allow it to run without any
2128# runtime errors
2229
2532SLOWDOWN_PLASTIC = 10
2633
2734# bool hard code for extracting the weights or not
28- EXTRACT_WEIGHTS = False
35+ EXTRACT_WEIGHTS = True
2936GENERATE_PLOT = True
3037
3138# how many boards to use for this test
@@ -96,7 +103,9 @@ class Vogels2011(object):
96103 # file name for plastic in spikes
97104 PLASTIC_IN_SPIKES_FILE_NAME = "plasticInhibSpikes"
98105
99- def _build_network (self , uses_stdp , slow_down ):
106+ def _build_network (self , uses_stdp : bool , slow_down : int ) -> Tuple [
107+ Population , Population , Projection , Projection , Projection ,
108+ Projection ]:
100109 """ builds the network with either stdp or not, and with a given
101110 slowdown
102111
@@ -167,7 +176,7 @@ def _build_network(self, uses_stdp, slow_down):
167176 return ex_pop , in_pop , ie_projection , proj1 , proj2 , proj3
168177
169178 @staticmethod
170- def save_name (spike_name ) :
179+ def save_name (spike_name : str ) -> str :
171180 """
172181 Gets the name of a none existing file based on this name.
173182
@@ -184,7 +193,10 @@ def save_name(spike_name):
184193 file_name = spike_name + str (index )
185194 return file_name
186195
187- def run (self , slow_down_static , slow_down_plastic , extract_weights ):
196+ def run (self , slow_down_static : int , slow_down_plastic : int ,
197+ extract_weights : bool ) -> Tuple [
198+ Optional [ConnectionHolder ], Optional [numpy .ndarray ],
199+ Optional [numpy .ndarray ]]:
188200 """ builds and runs a network
189201
190202 :param slow_down_static: the slowdown for the network during \
@@ -195,10 +207,9 @@ def run(self, slow_down_static, slow_down_plastic, extract_weights):
195207 extraction
196208 :return: plastic weights, the static and plastic spikes.
197209 """
198-
199- static_ex_spikes_numpy = None
200- plastic_weights = None
201- plastic_spikes_numpy = None
210+ static_ex_spikes_numpy : Optional [numpy .ndarray ] = None
211+ plastic_weights : Optional [ConnectionHolder ] = None
212+ plastic_spikes_numpy : Optional [numpy .ndarray ] = None
202213
203214 if self .RUN_STATIC_VERSION :
204215 print ("Generating Static network" )
@@ -218,8 +229,7 @@ def run(self, slow_down_static, slow_down_plastic, extract_weights):
218229 index += 1
219230
220231 # Get static spikes
221- static_ex_spikes_numpy = None
222- static_in_spikes_numpy = None
232+ static_in_spikes_numpy : Optional [numpy .ndarray ] = None
223233 if self .EXTRACT_SPIKES :
224234 static_ex_spikes = static_ex_pop .get_data ('spikes' )
225235 static_ex_spikes_numpy = neo_convertor .convert_spikes (
@@ -228,10 +238,12 @@ def run(self, slow_down_static, slow_down_plastic, extract_weights):
228238 static_in_spikes_numpy = neo_convertor .convert_spikes (
229239 static_in_spikes )
230240
231- if self .SAVE_SPIKES :
241+ if self .EXTRACT_SPIKES and self . SAVE_SPIKES :
232242 ex_name = self .save_name (self .STATIC_EX_SPIKES_FILE_NAME )
233243 in_name = self .save_name (self .STATIC_IN_SPIKES_FILE_NAME )
244+ assert static_ex_spikes_numpy is not None # for mypy
234245 numpy .savetxt (ex_name , static_ex_spikes_numpy )
246+ assert static_in_spikes_numpy is not None # for mypy
235247 numpy .savetxt (in_name , static_in_spikes_numpy )
236248
237249 # end static simulation
@@ -259,8 +271,6 @@ def run(self, slow_down_static, slow_down_plastic, extract_weights):
259271 index += 1
260272
261273 # Get plastic spikes and save to disk
262- static_in_spikes_numpy = None
263- plastic_spikes_numpy = None
264274 if self .EXTRACT_SPIKES :
265275 plastic_spikes = plastic_ex_pop .get_data ('spikes' )
266276 plastic_spikes_numpy = (
@@ -269,10 +279,12 @@ def run(self, slow_down_static, slow_down_plastic, extract_weights):
269279 static_in_spikes_numpy = neo_convertor .convert_spikes (
270280 static_in_spikes )
271281
272- if self .SAVE_SPIKES :
282+ if self .EXTRACT_SPIKES and self . SAVE_SPIKES :
273283 ex_name = self .save_name (self .PLASTIC_EX_SPIKES_FILE_NAME )
274284 in_name = self .save_name (self .PLASTIC_IN_SPIKES_FILE_NAME )
285+ assert plastic_spikes_numpy is not None # for mypy
275286 numpy .savetxt (ex_name , plastic_spikes_numpy )
287+ assert static_in_spikes_numpy is not None # for mypy
276288 numpy .savetxt (in_name , static_in_spikes_numpy )
277289
278290 if extract_weights :
@@ -285,7 +297,9 @@ def run(self, slow_down_static, slow_down_plastic, extract_weights):
285297 return plastic_weights , static_ex_spikes_numpy , plastic_spikes_numpy
286298
287299 def plot (
288- self , plastic_weights , static_spikes_numpy , plastic_spikes_numpy ):
300+ self , plastic_weights : Optional [ConnectionHolder ],
301+ static_spikes_numpy : Optional [numpy .ndarray ],
302+ plastic_spikes_numpy : Optional [numpy .ndarray ]) -> None :
289303 """ generates plots for a paper
290304
291305 :param plastic_weights: the plastic weights.
0 commit comments