|
15 | 15 | import pyNN.utility.plotting as plot |
16 | 16 | import matplotlib.pyplot as plt |
17 | 17 |
|
18 | | -p.setup(0.1) |
19 | | -runtime = 50 |
20 | | -populations = [] |
21 | | -title = "PyNN0.8 alpha synapse testing" |
22 | 18 |
|
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 |
25 | 22 |
|
26 | | -populations.append(p.Population(1, p.IF_curr_alpha, {}, label="test")) |
| 23 | + The default setting cause this script to split. |
27 | 24 |
|
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" |
30 | 33 |
|
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)) |
40 | 44 |
|
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) |
43 | 47 |
|
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") |
48 | 55 |
|
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() |
0 commit comments