Skip to content

Commit a4570bb

Browse files
authored
Merge pull request #142 from SpiNNakerManchester/daul_test
test script combined and split
2 parents ad28450 + 9ad2251 commit a4570bb

7 files changed

Lines changed: 673 additions & 388 deletions

File tree

examples/extra_models_examples/IF_cond_exp_stoc.py

Lines changed: 104 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -33,88 +33,107 @@
3333
from pyNN.utility.plotting import Figure, Panel
3434
import matplotlib.pyplot as plt
3535

36-
sim.setup(timestep=1.0, min_delay=1.0)
37-
38-
stoc_cell = sim.Population(1, sim.extra_models.IFCondExpStoc(**{
39-
'i_offset': 0.1,
40-
'tau_refrac': 3.0,
41-
'v_thresh': -51.0,
42-
'v_reset': -70.0,
43-
'tau_syn_E': 5.0,
44-
'tau_syn_I': 5.0}))
45-
46-
exp_cell = sim.Population(1, sim.IF_cond_exp(**{
47-
'i_offset': 0.1,
48-
'tau_refrac': 3.0,
49-
'v_thresh': -51.0,
50-
'v_reset': -70.0,
51-
'tau_syn_E': 5.0,
52-
'tau_syn_I': 5.0}))
53-
54-
55-
spike_sourceE = sim.Population(1, sim.SpikeSourceArray(**{
56-
'spike_times': [float(i) for i in range(5, 105, 10)]}))
57-
spike_sourceI = sim.Population(1, sim.SpikeSourceArray(**{
58-
'spike_times': [float(i) for i in range(155, 255, 10)]}))
59-
60-
sim.Projection(spike_sourceE, exp_cell,
61-
sim.OneToOneConnector(),
62-
synapse_type=sim.StaticSynapse(weight=0.15, delay=2.0),
63-
receptor_type='excitatory')
64-
sim.Projection(spike_sourceI, exp_cell,
65-
sim.OneToOneConnector(),
66-
synapse_type=sim.StaticSynapse(weight=-0.15, delay=4.0),
67-
receptor_type='inhibitory')
68-
sim.Projection(spike_sourceE, stoc_cell,
69-
sim.OneToOneConnector(),
70-
synapse_type=sim.StaticSynapse(weight=0.15, delay=2.0),
71-
receptor_type='excitatory')
72-
sim.Projection(spike_sourceI, stoc_cell,
73-
sim.OneToOneConnector(),
74-
synapse_type=sim.StaticSynapse(weight=-0.15, delay=4.0),
75-
receptor_type='inhibitory')
76-
77-
stoc_cell.record('all')
78-
exp_cell.record('all')
79-
80-
runtime = 200.0
81-
82-
sim.run(runtime)
83-
84-
stoc_data = stoc_cell.get_data()
85-
exp_data = exp_cell.get_data()
86-
87-
# Plot
88-
Figure(
89-
# raster plot of the presynaptic neuron spike times
90-
Panel(stoc_data.segments[0].spiketrains,
91-
yticks=True, markersize=0.2, xlim=(0, runtime)),
92-
Panel(exp_data.segments[0].spiketrains,
93-
yticks=True, markersize=0.2, xlim=(0, runtime)),
94-
# membrane potential of the postsynaptic neuron
95-
Panel(stoc_data.segments[0].filter(name='v')[0],
96-
ylabel="Membrane potential (mV)",
97-
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
98-
Panel(stoc_data.segments[0].filter(name='gsyn_exc')[0],
99-
ylabel="gsyn excitatory (mV)",
100-
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
101-
Panel(stoc_data.segments[0].filter(name='gsyn_inh')[0],
102-
ylabel="gsyn inhibitory (mV)",
103-
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
104-
# membrane potential of the postsynaptic neuron
105-
Panel(exp_data.segments[0].filter(name='v')[0],
106-
ylabel="Membrane potential (mV)",
107-
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
108-
Panel(exp_data.segments[0].filter(name='gsyn_exc')[0],
109-
ylabel="gsyn excitatory (mV)",
110-
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
111-
Panel(exp_data.segments[0].filter(name='gsyn_inh')[0],
112-
ylabel="gsyn inhibitory (mV)",
113-
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
114-
title="IF_cond_exp_stoc example",
115-
annotations=f"Simulated with {sim.name()}"
116-
)
117-
plt.show()
118-
119-
sim.end()
120-
pylab.show()
36+
37+
def run_script(*, split: bool = False) -> None:
38+
"""
39+
Runs the example script
40+
41+
:param split: If True will split the Populations that receive data
42+
into synapse and neuron cores.
43+
This requires more cores but allows more spikes to be received.
44+
"""
45+
sim.setup(timestep=1.0, min_delay=1.0)
46+
47+
if split:
48+
sim.extra_models.IFCondExpStoc.set_model_n_synapse_cores(1)
49+
sim.IF_cond_exp.set_model_n_synapse_cores(1)
50+
51+
stoc_cell = sim.Population(1, sim.extra_models.IFCondExpStoc(**{
52+
'i_offset': 0.1,
53+
'tau_refrac': 3.0,
54+
'v_thresh': -51.0,
55+
'v_reset': -70.0,
56+
'tau_syn_E': 5.0,
57+
'tau_syn_I': 5.0}))
58+
59+
exp_cell = sim.Population(1, sim.IF_cond_exp(**{
60+
'i_offset': 0.1,
61+
'tau_refrac': 3.0,
62+
'v_thresh': -51.0,
63+
'v_reset': -70.0,
64+
'tau_syn_E': 5.0,
65+
'tau_syn_I': 5.0}))
66+
67+
spike_sourceE = sim.Population(1, sim.SpikeSourceArray(**{
68+
'spike_times': [float(i) for i in range(5, 105, 10)]}))
69+
spike_sourceI = sim.Population(1, sim.SpikeSourceArray(**{
70+
'spike_times': [float(i) for i in range(155, 255, 10)]}))
71+
72+
sim.Projection(spike_sourceE, exp_cell,
73+
sim.OneToOneConnector(),
74+
synapse_type=sim.StaticSynapse(weight=0.15, delay=2.0),
75+
receptor_type='excitatory')
76+
sim.Projection(spike_sourceI, exp_cell,
77+
sim.OneToOneConnector(),
78+
synapse_type=sim.StaticSynapse(weight=-0.15, delay=4.0),
79+
receptor_type='inhibitory')
80+
sim.Projection(spike_sourceE, stoc_cell,
81+
sim.OneToOneConnector(),
82+
synapse_type=sim.StaticSynapse(weight=0.15, delay=2.0),
83+
receptor_type='excitatory')
84+
sim.Projection(spike_sourceI, stoc_cell,
85+
sim.OneToOneConnector(),
86+
synapse_type=sim.StaticSynapse(weight=-0.15, delay=4.0),
87+
receptor_type='inhibitory')
88+
89+
stoc_cell.record('all')
90+
exp_cell.record('all')
91+
92+
runtime = 200.0
93+
94+
sim.run(runtime)
95+
96+
stoc_data = stoc_cell.get_data()
97+
exp_data = exp_cell.get_data()
98+
99+
# Plot
100+
Figure(
101+
# raster plot of the presynaptic neuron spike times
102+
Panel(stoc_data.segments[0].spiketrains,
103+
yticks=True, markersize=0.2, xlim=(0, runtime)),
104+
Panel(exp_data.segments[0].spiketrains,
105+
yticks=True, markersize=0.2, xlim=(0, runtime)),
106+
# membrane potential of the postsynaptic neuron
107+
Panel(stoc_data.segments[0].filter(name='v')[0],
108+
ylabel="Membrane potential (mV)",
109+
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
110+
Panel(stoc_data.segments[0].filter(name='gsyn_exc')[0],
111+
ylabel="gsyn excitatory (mV)",
112+
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
113+
Panel(stoc_data.segments[0].filter(name='gsyn_inh')[0],
114+
ylabel="gsyn inhibitory (mV)",
115+
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
116+
# membrane potential of the postsynaptic neuron
117+
Panel(exp_data.segments[0].filter(name='v')[0],
118+
ylabel="Membrane potential (mV)",
119+
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
120+
Panel(exp_data.segments[0].filter(name='gsyn_exc')[0],
121+
ylabel="gsyn excitatory (mV)",
122+
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
123+
Panel(exp_data.segments[0].filter(name='gsyn_inh')[0],
124+
ylabel="gsyn inhibitory (mV)",
125+
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
126+
title="IF_cond_exp_stoc example",
127+
annotations=f"Simulated with {sim.name()}"
128+
)
129+
plt.show()
130+
131+
sim.end()
132+
pylab.show()
133+
134+
# combined binaries [IF_cond_exp_stoc.aplx, IF_cond_exp.aplx]
135+
# split binaries [IF_cond_exp_stoc_neuron.aplx, IF_cond_exp_neuron.aplx]
136+
137+
138+
if __name__ == "__main__":
139+
run_script()

examples/extra_models_examples/IF_curr_exp_ca2_adaptive.py

Lines changed: 108 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -25,91 +25,111 @@
2525
import matplotlib.pyplot as pylab
2626
import pyNN.spiNNaker as sim
2727

28-
# Timestep (ms)
29-
# **NOTE** the 2.5Khz input frequency is not going to work particularly well
30-
# at 1ms
31-
dt = 0.1
32-
33-
# Number of neurons - used to gather enough ISIs to get a smooth estimate
34-
N = 300
35-
36-
# Time (ms) to simulate for
37-
T = 250
38-
39-
# Setup simulator
40-
sim.setup(timestep=dt, min_delay=1.0)
41-
42-
# Create population of neurons
43-
cell = sim.Population(N, sim.extra_models.IFCurrExpCa2Adaptive(**{
44-
"tau_m": 20.0, "cm": 0.5,
45-
"v_rest": -70.0,
46-
"v_reset": -60.0,
47-
"v_thresh": -54.0,
48-
"i_alpha": 0.1,
49-
"tau_ca2": 50.0}))
50-
51-
# Create poisson spike source
52-
spike_source = sim.Population(N, sim.SpikeSourcePoisson(rate=2500.0))
53-
54-
sim.Projection(spike_source, cell,
55-
sim.OneToOneConnector(),
56-
sim.StaticSynapse(weight=0.1, delay=0.1),
57-
receptor_type="excitatory")
58-
59-
cell.record('spikes')
60-
# cell.record_gsyn()
61-
62-
sim.run(T)
63-
64-
spike_times = cell.spinnaker_get_data('spikes')
65-
# ca2 = cell.get_gsyn(compatible_output=True)
66-
67-
# Split into list of spike times for each neuron
68-
neuron_spikes = [spike_times[spike_times[:, 0] == n, 1] for n in range(N)]
69-
70-
# Calculate interspike intervals
71-
# and pair these with bin index of last spike time in pair
72-
# **NOTE** using first spike time in pair leads to a dip at the
73-
# end as the end of long pairs goes off the end of the simulation
74-
binned_isis = numpy.hstack([
75-
numpy.vstack(
76-
(t[1:] - t[:-1],
77-
numpy.digitize(t[1:], numpy.arange(T)) - 1))
78-
for t in neuron_spikes])
79-
80-
# Split interspike intervals into separate array for each time bin
81-
time_binned_isis = [binned_isis[0, binned_isis[1] == t] for t in range(T)]
82-
83-
# Create a dictionary of non-empty time bins to mean interspike interval
84-
mean_isis = {t: numpy.average(i)
85-
for (t, i) in enumerate(time_binned_isis) if len(i) > 0}
86-
87-
# Calculate the coefficient of variance for each time bin
88-
isi_cv = {t: math.sqrt(
89-
numpy.sum(numpy.power(time_binned_isis[t] - mean_isi, 2)) /
90-
float(len(time_binned_isis[t]))) / mean_isi
91-
for (t, mean_isi) in mean_isis.items()}
92-
93-
# Take average CA2 level across all neurons
94-
# average_ca2 = numpy.average(numpy.reshape(ca2[:,2], (N, int(T / dt))),
95-
# axis=0)
96-
97-
# Plot
98-
fig, axes = pylab.subplots(2, sharex=True)
99-
100-
axes[0].scatter(mean_isis.keys(),
101-
[1000.0 / i for i in mean_isis.values()], s=2)
102-
axes[0].set_ylabel("Firing rate/Hz")
103-
104-
# axes[1].scatter(numpy.arange(0.0, T, dt), average_ca2, s=2)
105-
# axes[1].set_ylabel("CA2/mA")
106-
# axes[1].set_ylim((0.0, numpy.amax(average_ca2) * 1.25))
107-
108-
axes[1].scatter(isi_cv.keys(), isi_cv.values(), s=2)
109-
axes[1].set_ylabel("Coefficient of ISI variance")
110-
111-
axes[1].set_xlim((0.0, T))
112-
axes[1].set_xlabel("Time/ms")
113-
114-
sim.end()
115-
pylab.show()
28+
29+
def run_script(*, split: bool = False) -> None:
30+
"""
31+
Runs the example script
32+
33+
:param split: If True will split the Populations that receive data
34+
into synapse and neuron cores.
35+
This requires more cores but allows more spikes to be received.
36+
"""
37+
# Timestep (ms)
38+
# **NOTE**
39+
# the 2.5Khz input frequency is not going to work particularly well at 1ms
40+
dt = 0.1
41+
42+
# Number of neurons - used to gather enough ISIs to get a smooth estimate
43+
N = 300
44+
45+
# Time (ms) to simulate for
46+
T = 250
47+
48+
# Setup simulator
49+
sim.setup(timestep=dt, min_delay=1.0)
50+
51+
if split:
52+
sim.extra_models.IFCurrExpCa2Adaptive.set_model_n_synapse_cores(1)
53+
54+
# Create population of neurons
55+
cell = sim.Population(N, sim.extra_models.IFCurrExpCa2Adaptive(**{
56+
"tau_m": 20.0, "cm": 0.5,
57+
"v_rest": -70.0,
58+
"v_reset": -60.0,
59+
"v_thresh": -54.0,
60+
"i_alpha": 0.1,
61+
"tau_ca2": 50.0}))
62+
63+
# Create poisson spike source
64+
spike_source = sim.Population(N, sim.SpikeSourcePoisson(rate=2500.0))
65+
66+
sim.Projection(spike_source, cell,
67+
sim.OneToOneConnector(),
68+
sim.StaticSynapse(weight=0.1, delay=0.1),
69+
receptor_type="excitatory")
70+
71+
cell.record('spikes')
72+
# cell.record_gsyn()
73+
74+
sim.run(T)
75+
76+
spike_times = cell.spinnaker_get_data('spikes')
77+
# ca2 = cell.get_gsyn(compatible_output=True)
78+
79+
# Split into list of spike times for each neuron
80+
neuron_spikes = [spike_times[spike_times[:, 0] == n, 1] for n in range(N)]
81+
82+
# Calculate interspike intervals
83+
# and pair these with bin index of last spike time in pair
84+
# **NOTE** using first spike time in pair leads to a dip at the
85+
# end as the end of long pairs goes off the end of the simulation
86+
binned_isis = numpy.hstack([
87+
numpy.vstack(
88+
(t[1:] - t[:-1],
89+
numpy.digitize(t[1:], numpy.arange(T)) - 1))
90+
for t in neuron_spikes])
91+
92+
# Split interspike intervals into separate array for each time bin
93+
time_binned_isis = [binned_isis[0, binned_isis[1] == t] for t in range(T)]
94+
95+
# Create a dictionary of non-empty time bins to mean interspike interval
96+
mean_isis = {t: numpy.average(i)
97+
for (t, i) in enumerate(time_binned_isis) if len(i) > 0}
98+
99+
# Calculate the coefficient of variance for each time bin
100+
isi_cv = {t: math.sqrt(
101+
numpy.sum(numpy.power(time_binned_isis[t] - mean_isi, 2)) /
102+
float(len(time_binned_isis[t]))) / mean_isi
103+
for (t, mean_isi) in mean_isis.items()}
104+
105+
# Take average CA2 level across all neurons
106+
# average_ca2 = numpy.average(numpy.reshape(ca2[:,2], (N, int(T / dt))),
107+
# axis=0)
108+
109+
# Plot
110+
_, axes = pylab.subplots(2, sharex=True)
111+
112+
axes[0].scatter(mean_isis.keys(),
113+
[1000.0 / i for i in mean_isis.values()], s=2)
114+
axes[0].set_ylabel("Firing rate/Hz")
115+
116+
# axes[1].scatter(numpy.arange(0.0, T, dt), average_ca2, s=2)
117+
# axes[1].set_ylabel("CA2/mA")
118+
# axes[1].set_ylim((0.0, numpy.amax(average_ca2) * 1.25))
119+
120+
axes[1].scatter(isi_cv.keys(), isi_cv.values(), s=2)
121+
axes[1].set_ylabel("Coefficient of ISI variance")
122+
123+
axes[1].set_xlim((0.0, T))
124+
axes[1].set_xlabel("Time/ms")
125+
126+
sim.end()
127+
pylab.show()
128+
129+
130+
# combined binaries [IF_curr_exp_ca2_adaptive.aplx]
131+
# split binaries [IF_curr_exp_ca2_adaptive_neuron.aplx]
132+
133+
134+
if __name__ == "__main__":
135+
run_script()

0 commit comments

Comments
 (0)