33except ImportError :
44 import unittest
55
6- # import pyNN.nest as sim
76import pyNN .mock as sim
8-
7+ import numpy as np
98from pyNN .utility import Timer
109
1110
@@ -16,42 +15,61 @@ def do_scaling_per_population_test(N):
1615 timer .start ()
1716 sim .setup ()
1817 timer .mark ("setup" )
19- p = sim .Population (N , sim .IF_curr_exp ())
18+ sim .Population (N , sim .IF_curr_exp ())
2019 timer .mark ("Population: " + str (N ))
2120 sim .end ()
2221 timer .mark ("end" )
2322 elapsed_time = timer .elapsed_time ()
2423 relative_elapsed_time = elapsed_time / N
2524 print (
2625 "Creating a {}-sized population took {}s ({}s per neuron)" .format (
27- N , elapsed_time , relative_elapsed_time
28- )
29- )
26+ N , elapsed_time , relative_elapsed_time ))
3027
3128 def test_scaling_per_population (self , sim = sim ):
3229 for powerN in range (13 ):
3330 N = 2 ** powerN
3431 with self .subTest (N = N ):
3532 self .do_scaling_per_population_test (N )
3633
34+ @staticmethod
35+ def do_scaling_per_population_view_test (N , M ):
36+ sim .setup ()
37+ pop = sim .Population (2 ** M , sim .IF_curr_exp ())
38+ timer = Timer ()
39+ timer .start ()
40+ sim .PopulationView (pop , np .array (range (N )))
41+ timer .mark ("PopulationView size: " + str (N ))
42+ sim .end ()
43+ timer .mark ("end" )
44+ elapsed_time = timer .elapsed_time ()
45+ relative_elapsed_time = elapsed_time / N
46+ print ("Creating a {}-sized population view took {}s "
47+ "({}s per view)" .format (
48+ N , elapsed_time , relative_elapsed_time ))
49+
50+ def test_scaling_per_population_view (self , sim = sim ):
51+ M = 13
52+ for powerN in range (M ):
53+ N = 2 ** powerN
54+ with self .subTest (N = N ):
55+ self .do_scaling_per_population_view_test (N , M )
56+
3757 @staticmethod
3858 def do_scaling_test (N ):
3959 timer = Timer ()
4060 timer .start ()
4161 sim .setup ()
4262 timer .mark ("setup" )
4363 for _ in range (N ):
44- p = sim .Population (1 , sim .IF_curr_exp ())
64+ sim .Population (1 , sim .IF_curr_exp ())
4565 timer .mark ("Population: " + str (N ))
4666 sim .end ()
4767 timer .mark ("end" )
4868 elapsed_time = timer .elapsed_time ()
4969 relative_elapsed_time = elapsed_time / N
5070 print (
5171 "Creating {} populations took {}s ({}s per population)" .format (
52- N , elapsed_time , relative_elapsed_time
53- )
54- )
72+ N , elapsed_time , relative_elapsed_time ))
5573
5674 def test_scaling (self , sim = sim ):
5775 for powerN in range (13 ):
@@ -80,60 +98,45 @@ def _remove_dummy_parameters(celltype, M):
8098 del celltype .translations [pname ]
8199
82100 @staticmethod
83- def do_scaling_cellparams_test ( N , M ):
101+ def do_scaling_cellparams_id_to_index_test ( N ):
84102 # copy.deepcopy doesn't help here => we add and restore manually
85103 celltype = sim .IF_cond_exp
86104 assert len (celltype .get_parameter_names ()) < 100
87- PopulationTest ._add_dummy_parameters (celltype , M )
105+ PopulationTest ._add_dummy_parameters (celltype , N )
106+ num_params = len (celltype .get_parameter_names ())
88107 sim .setup ()
89- t0 = Timer ()
90- t0 .start ()
91- pop = sim .Population (N , celltype ()) # this is the culprit
92- elapsed_time = t0 .elapsed_time ()
93- relative_elapsed_time = elapsed_time / M
94- print (
95- "Creating a population with {} parameters took {} ({} per parameter)" .format (
96- len (celltype .get_parameter_names ()), elapsed_time , relative_elapsed_time
97- )
98- )
99- sim .end ()
100- PopulationTest ._remove_dummy_parameters (celltype , M )
101-
102- def test_scaling_cellparams (self , sim = sim ):
103- for powerN in range (16 ):
104- N = 2 ** powerN
105- with self .subTest (N = N ):
106- self .do_scaling_cellparams_test (1 , N )
107-
108- @staticmethod
109- def do_scaling_cellparams_popview_test (N , M ):
110- # copy.deepcopy doesn't help here => we add and restore manually
111- celltype = sim .IF_cond_exp
112- assert len (celltype .get_parameter_names ()) < 100
113- PopulationTest ._add_dummy_parameters (celltype , M )
114- sim .setup ()
115- pop = sim .Population (N , celltype ())
108+ pop = sim .Population (1 , celltype ())
116109 pview = sim .PopulationView (pop , [0 ])
110+ # we specifically create an ID to check that having a parent leads to
111+ # the extreme slow down of id_to_index
117112 post_cell = sim .simulator .ID (pview .first_id )
118113 post_cell .parent = pop # this is the culprit
119114 t0 = Timer ()
120115 t0 .start ()
121- post_index = pview .id_to_index (post_cell )
116+ pop .id_to_index (post_cell )
122117 elapsed_time = t0 .elapsed_time ()
123- relative_elapsed_time = elapsed_time / M
124- print (
125- "Calling id_to_index on a view into a population with {} parameters took {} ({} per parameter)" .format (
126- len (celltype .get_parameter_names ()), elapsed_time , relative_elapsed_time
127- )
128- )
118+ relative_elapsed_time = elapsed_time / num_params
119+ print ("Calling id_to_index on a population with {} "
120+ "parameters took {} ({} per parameter)" .format (
121+ num_params ,
122+ elapsed_time , relative_elapsed_time ))
123+ t1 = Timer ()
124+ t1 .start ()
125+ pview .id_to_index (post_cell )
126+ elapsed_time = t1 .elapsed_time ()
127+ relative_elapsed_time = elapsed_time / num_params
128+ print ("Calling id_to_index on a view into a population with {} "
129+ "parameters took {} ({} per parameter)" .format (
130+ num_params ,
131+ elapsed_time , relative_elapsed_time ))
129132 sim .end ()
130- PopulationTest ._remove_dummy_parameters (celltype , M )
133+ PopulationTest ._remove_dummy_parameters (celltype , N )
131134
132- def test_scaling_cellparams_popview (self , sim = sim ):
135+ def test_scaling_cellparams_id_to_index (self , sim = sim ):
133136 for powerN in range (8 ):
134137 N = 2 ** powerN
135138 with self .subTest (N = N ):
136- self .do_scaling_cellparams_popview_test ( 1 , N )
139+ self .do_scaling_cellparams_id_to_index_test ( N )
137140
138141
139142class ProjectionTest (unittest .TestCase ):
@@ -145,8 +148,11 @@ def do_scaling_per_projection_test(N):
145148
146149 timer = Timer ()
147150 timer .start ()
148- proj = sim .Projection (
149- pre , post , sim .OneToOneConnector (), synapse_type = sim .StaticSynapse (weight = 1.0 )
151+ sim .Projection (
152+ pre ,
153+ post ,
154+ sim .OneToOneConnector (),
155+ synapse_type = sim .StaticSynapse (weight = 1.0 )
150156 )
151157 timer .mark ("Projection: " + str (N ))
152158 elapsed_time = timer .elapsed_time ()
@@ -155,9 +161,7 @@ def do_scaling_per_projection_test(N):
155161 sim .end ()
156162 print (
157163 "Creating {}-sized projection took {}s ({}s per synapse)" .format (
158- N , elapsed_time , relative_elapsed_time
159- )
160- )
164+ N , elapsed_time , relative_elapsed_time ))
161165
162166 def test_scaling_per_projection (self , sim = sim ):
163167 for powerN in range (13 ):
@@ -174,13 +178,11 @@ def do_scaling_test(N):
174178 timer = Timer ()
175179 timer .start ()
176180 for i in range (N ):
177-
178- # FIXME: add check for class-vs-instance in connector, it fails if the connector is a class
179- proj = sim .Projection (
180- pre [i : i + 1 ],
181- post [i : i + 1 ],
181+ sim .Projection (
182+ pre [i : i + 1 ],
183+ post [i : i + 1 ],
182184 sim .OneToOneConnector (),
183- synapse_type = sim .StaticSynapse (weight = 1.0 ),
185+ synapse_type = sim .StaticSynapse (weight = 1.0 )
184186 )
185187 timer .mark ("Projection: " + str (N ))
186188 elapsed_time = timer .elapsed_time ()
@@ -190,9 +192,7 @@ def do_scaling_test(N):
190192
191193 print (
192194 "Creating {} projections took {}s ({}s per projection)" .format (
193- N , elapsed_time , relative_elapsed_time
194- )
195- )
195+ N , elapsed_time , relative_elapsed_time ))
196196
197197 def test_scaling (self , sim = sim ):
198198 for powerN in range (13 ):
@@ -201,7 +201,5 @@ def test_scaling(self, sim=sim):
201201 self .do_scaling_test (N )
202202
203203
204- # import profile
205204if __name__ == "__main__" :
206205 unittest .main ()
207- # profile.run('print(PopulationTest.do_scaling_cellparams_popview_test(1, 100))')
0 commit comments