Skip to content

Commit 8919a69

Browse files
authored
Merge pull request #145 from SpiNNakerManchester/check_binaries_called
Check binaries called
2 parents a4570bb + 85701a0 commit 8919a69

3 files changed

Lines changed: 124 additions & 63 deletions

File tree

examples/extra_models_examples/vogels_2011.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import os
15+
from typing import Optional
1516
import pyNN.spiNNaker as sim
1617
import numpy
1718
import matplotlib.pyplot as pylab
@@ -41,6 +42,12 @@ class Vogels2011(object):
4142
To reproduce the experiment from their paper
4243
"""
4344

45+
def __init__(self, split: bool = False):
46+
if split:
47+
self._n_synapse_cores: Optional[int] = 1
48+
else:
49+
self._n_synapse_cores = None
50+
4451
# Population parameters
4552
MODEL = sim.IF_curr_exp
4653
CELL_PARAMETERS = {
@@ -119,7 +126,8 @@ def _build_network(self, uses_stdp, slow_down):
119126
# Create excitatory and inhibitory populations of neurons
120127
ex_pop = sim.Population(
121128
self.NUM_EXCITATORY, self.MODEL(**self.CELL_PARAMETERS),
122-
label="excit_pop", seed=rng_seed)
129+
label="excit_pop", seed=rng_seed,
130+
n_synapse_cores=self._n_synapse_cores)
123131
in_pop = sim.Population(
124132
self.NUM_INHIBITORY, self.MODEL(**self.CELL_PARAMETERS),
125133
label="inhib_pop", seed=rng_seed)
@@ -344,8 +352,24 @@ def plot(
344352
pylab.show()
345353

346354

347-
x = Vogels2011()
348-
result_weights, static, plastic = x.run(
349-
SLOWDOWN_STATIC, SLOWDOWN_PLASTIC, EXTRACT_WEIGHTS)
350-
if GENERATE_PLOT:
351-
x.plot(result_weights, static, plastic)
355+
def run_script(*, split: bool = False) -> None:
356+
"""
357+
Runs the example script
358+
359+
:param split: If True will split the Populations that receive data
360+
into synapse and neuron cores.
361+
This requires more cores but allows more spikes to be received.
362+
"""
363+
x = Vogels2011(split)
364+
result_weights, static, plastic = x.run(
365+
SLOWDOWN_STATIC, SLOWDOWN_PLASTIC, EXTRACT_WEIGHTS)
366+
if GENERATE_PLOT:
367+
x.plot(result_weights, static, plastic)
368+
369+
# combined binaries [IF_curr_exp_stdp_mad_vogels_2011_additive.aplx]
370+
# split binaries [IF_curr_exp_neuron.aplx,
371+
# synapses_stdp_mad_vogels_2011_additive.aplx]
372+
373+
374+
if __name__ == "__main__":
375+
run_script(split=True)

examples/if_curr_alpha.py

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,75 @@
1515
import pyNN.utility.plotting as plot
1616
import matplotlib.pyplot as plt
1717

18-
p.setup(0.1)
19-
runtime = 50
20-
populations = []
21-
title = "PyNN0.8 alpha synapse testing"
2218

23-
pop_src1 = p.Population(1, p.SpikeSourceArray,
24-
{'spike_times': [[5, 15, 20, 30]]}, label="src1")
19+
def run_script(*, split: bool = True) -> None:
20+
"""
21+
Runs the example script
2522
26-
populations.append(p.Population(1, p.IF_curr_alpha, {}, label="test"))
23+
The default setting cause this script to split.
2724
28-
populations[0].set(tau_syn_E=2)
29-
populations[0].set(tau_syn_I=4)
25+
:param split: If True will split the Populations that receive data
26+
into synapse and neuron cores.
27+
This requires more cores but allows more spikes to be received.
28+
"""
29+
p.setup(0.1)
30+
runtime = 50
31+
populations = []
32+
title = "PyNN alpha synapse testing"
3033

31-
# define the projections
32-
exc_proj = p.Projection(pop_src1, populations[0],
33-
p.OneToOneConnector(),
34-
p.StaticSynapse(weight=1, delay=1),
35-
receptor_type="excitatory")
36-
inh_proj = p.Projection(pop_src1, populations[0],
37-
p.OneToOneConnector(),
38-
p.StaticSynapse(weight=1, delay=10),
39-
receptor_type="inhibitory")
34+
pop_src1 = p.Population(1, p.SpikeSourceArray,
35+
{'spike_times': [[5, 15, 20, 30]]}, label="src1")
36+
if split:
37+
# Due to the timestep of 0.1 by default
38+
# this splits into synapses and neuron cores
39+
populations.append(p.Population(1, p.IF_curr_alpha, {}, label="test"))
40+
else:
41+
# can be forced to not split this way
42+
populations.append(p.Population(1, p.IF_curr_alpha, {}, label="test",
43+
n_synapse_cores=0))
4044

41-
populations[0].record("all")
42-
p.run(runtime)
45+
populations[0].set(tau_syn_E=2)
46+
populations[0].set(tau_syn_I=4)
4347

44-
v = populations[0].get_data("v")
45-
gsyn_exc = populations[0].get_data("gsyn_exc")
46-
gsyn_inh = populations[0].get_data("gsyn_inh")
47-
spikes = populations[0].get_data("spikes")
48+
# define the projections
49+
p.Projection(
50+
pop_src1, populations[0], p.OneToOneConnector(),
51+
p.StaticSynapse(weight=1, delay=1), receptor_type="excitatory")
52+
p.Projection(
53+
pop_src1, populations[0], p.OneToOneConnector(),
54+
p.StaticSynapse(weight=1, delay=10), receptor_type="inhibitory")
4855

49-
plot.Figure(
50-
plot.Panel(v.segments[0].filter(name='v')[0],
51-
ylabel="Membrane potential (mV)",
52-
data_labels=[populations[0].label],
53-
yticks=True, xlim=(0, runtime)),
54-
plot.Panel(gsyn_exc.segments[0].filter(name='gsyn_exc')[0],
55-
ylabel="gsyn excitatory (mV)",
56-
data_labels=[populations[0].label],
57-
yticks=True, xlim=(0, runtime)),
58-
plot.Panel(gsyn_inh.segments[0].filter(name='gsyn_inh')[0],
59-
ylabel="gsyn inhibitory (mV)",
60-
data_labels=[populations[0].label],
61-
yticks=True, xlim=(0, runtime)),
62-
title=title,
63-
annotations=f"Simulated with {p.name()}"
64-
)
65-
plt.show()
66-
p.end()
56+
populations[0].record("all")
57+
p.run(runtime)
58+
59+
v = populations[0].get_data("v")
60+
gsyn_exc = populations[0].get_data("gsyn_exc")
61+
gsyn_inh = populations[0].get_data("gsyn_inh")
62+
spikes = populations[0].get_data("spikes")
63+
print(spikes)
64+
65+
plot.Figure(
66+
plot.Panel(v.segments[0].filter(name='v')[0],
67+
ylabel="Membrane potential (mV)",
68+
data_labels=[populations[0].label],
69+
yticks=True, xlim=(0, runtime)),
70+
plot.Panel(gsyn_exc.segments[0].filter(name='gsyn_exc')[0],
71+
ylabel="gsyn excitatory (mV)",
72+
data_labels=[populations[0].label],
73+
yticks=True, xlim=(0, runtime)),
74+
plot.Panel(gsyn_inh.segments[0].filter(name='gsyn_inh')[0],
75+
ylabel="gsyn inhibitory (mV)",
76+
data_labels=[populations[0].label],
77+
yticks=True, xlim=(0, runtime)),
78+
title=title,
79+
annotations=f"Simulated with {p.name()}"
80+
)
81+
plt.show()
82+
p.end()
83+
84+
# combined binaries [IF_curr_alpha.aplx]
85+
# split binaries [IF_curr_alpha_neuron.aplx, synapses.aplx]
86+
87+
88+
if __name__ == "__main__":
89+
run_script()

integration_tests/test_scripts.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,15 @@ def test_examples_external_devices_examples_live_examples_balanced_random_live_r
9696
def test_examples_external_devices_examples_pushbot_spinnaker_link_example(self):
9797
self.check_script("examples/external_devices_examples/pushbot_spinnaker_link_example.py")
9898

99-
def test_examples_if_curr_alpha(self):
100-
self.check_script("examples/if_curr_alpha.py")
99+
def test_examples_if_curr_alpha_combined(self):
100+
from examples.if_curr_alpha import run_script
101+
run_script(split=False)
102+
self.check_binaries_used(["IF_curr_alpha.aplx"])
103+
104+
def test_examples_if_curr_alpha_split(self):
105+
from examples.if_curr_alpha import run_script
106+
run_script(split=True)
107+
self.check_binaries_used(["IF_curr_alpha_neuron.aplx", "synapses.aplx"])
101108

102109
def test_examples_stdp_example_izk(self):
103110
self.check_script("examples/stdp_example_izk.py")
@@ -150,19 +157,6 @@ def test_examples_stdp_example_get_plastic_params(self):
150157
def test_examples_extra_models_examples_LGN_Izhikevich(self):
151158
self.check_script("examples/extra_models_examples/LGN_Izhikevich.py")
152159

153-
def test_examples_extra_models_examples_vogel_2011_vogels_2011_live_combined(self):
154-
from examples.extra_models_examples.vogel_2011.vogels_2011_live import run_script
155-
run_script(split=False)
156-
self.check_binaries_used(["IF_curr_exp_stdp_mad_vogels_2011_additive"])
157-
158-
def test_examples_extra_models_examples_vogel_2011_vogels_2011_live_split(self):
159-
from examples.extra_models_examples.vogel_2011.vogels_2011_live import run_script
160-
run_script(split=True)
161-
self.check_binaries_used(["synapses_stdp_mad_vogels_2011_additive"])
162-
163-
# Not testing file due to: Unhandled main
164-
# examples/extra_models_examples/vogel_2011/vogels_2011.py
165-
166160
def test_examples_extra_models_examples_stdp_associative_memory(self):
167161
self.check_script("examples/extra_models_examples/stdp_associative_memory.py")
168162

@@ -196,6 +190,26 @@ def test_examples_extra_models_examples_IF_curr_exp_sEMD_split(self):
196190
def test_examples_extra_models_examples_IF_curr_delta(self):
197191
self.check_script("examples/extra_models_examples/IF_curr_delta.py")
198192

193+
def test_examples_extra_models_examples_vogels_2011_live_combined(self):
194+
from examples.extra_models_examples.vogels_2011_live import run_script
195+
run_script(split=False)
196+
self.check_binaries_used(["IF_curr_exp_stdp_mad_vogels_2011_additive"])
197+
198+
def test_examples_extra_models_examples_vogels_2011_live_split(self):
199+
from examples.extra_models_examples.vogels_2011_live import run_script
200+
run_script(split=True)
201+
self.check_binaries_used(["synapses_stdp_mad_vogels_2011_additive"])
202+
203+
def test_examples_extra_models_examples_vogels_2011_combined(self):
204+
from examples.extra_models_examples.vogels_2011 import run_script
205+
run_script(split=False)
206+
self.check_binaries_used(["IF_curr_exp_stdp_mad_vogels_2011_additive.aplx"])
207+
208+
def test_examples_extra_models_examples_vogels_2011_split(self):
209+
from examples.extra_models_examples.vogels_2011 import run_script
210+
run_script(split=True)
211+
self.check_binaries_used(["IF_curr_exp_neuron.aplx", "synapses_stdp_mad_vogels_2011_additive.aplx"])
212+
199213
def test_examples_extra_models_examples_stdp_example_izk_cond(self):
200214
self.check_script("examples/extra_models_examples/stdp_example_izk_cond.py")
201215

0 commit comments

Comments
 (0)