Skip to content

Commit f5a9363

Browse files
committed
test script combined and split
1 parent a213a49 commit f5a9363

2 files changed

Lines changed: 117 additions & 87 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+
68+
spike_sourceE = sim.Population(1, sim.SpikeSourceArray(**{
69+
'spike_times': [float(i) for i in range(5, 105, 10)]}))
70+
spike_sourceI = sim.Population(1, sim.SpikeSourceArray(**{
71+
'spike_times': [float(i) for i in range(155, 255, 10)]}))
72+
73+
sim.Projection(spike_sourceE, exp_cell,
74+
sim.OneToOneConnector(),
75+
synapse_type=sim.StaticSynapse(weight=0.15, delay=2.0),
76+
receptor_type='excitatory')
77+
sim.Projection(spike_sourceI, exp_cell,
78+
sim.OneToOneConnector(),
79+
synapse_type=sim.StaticSynapse(weight=-0.15, delay=4.0),
80+
receptor_type='inhibitory')
81+
sim.Projection(spike_sourceE, stoc_cell,
82+
sim.OneToOneConnector(),
83+
synapse_type=sim.StaticSynapse(weight=0.15, delay=2.0),
84+
receptor_type='excitatory')
85+
sim.Projection(spike_sourceI, stoc_cell,
86+
sim.OneToOneConnector(),
87+
synapse_type=sim.StaticSynapse(weight=-0.15, delay=4.0),
88+
receptor_type='inhibitory')
89+
90+
stoc_cell.record('all')
91+
exp_cell.record('all')
92+
93+
runtime = 200.0
94+
95+
sim.run(runtime)
96+
97+
stoc_data = stoc_cell.get_data()
98+
exp_data = exp_cell.get_data()
99+
100+
# Plot
101+
Figure(
102+
# raster plot of the presynaptic neuron spike times
103+
Panel(stoc_data.segments[0].spiketrains,
104+
yticks=True, markersize=0.2, xlim=(0, runtime)),
105+
Panel(exp_data.segments[0].spiketrains,
106+
yticks=True, markersize=0.2, xlim=(0, runtime)),
107+
# membrane potential of the postsynaptic neuron
108+
Panel(stoc_data.segments[0].filter(name='v')[0],
109+
ylabel="Membrane potential (mV)",
110+
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
111+
Panel(stoc_data.segments[0].filter(name='gsyn_exc')[0],
112+
ylabel="gsyn excitatory (mV)",
113+
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
114+
Panel(stoc_data.segments[0].filter(name='gsyn_inh')[0],
115+
ylabel="gsyn inhibitory (mV)",
116+
data_labels=[stoc_cell.label], yticks=True, xlim=(0, runtime)),
117+
# membrane potential of the postsynaptic neuron
118+
Panel(exp_data.segments[0].filter(name='v')[0],
119+
ylabel="Membrane potential (mV)",
120+
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
121+
Panel(exp_data.segments[0].filter(name='gsyn_exc')[0],
122+
ylabel="gsyn excitatory (mV)",
123+
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
124+
Panel(exp_data.segments[0].filter(name='gsyn_inh')[0],
125+
ylabel="gsyn inhibitory (mV)",
126+
data_labels=[exp_cell.label], yticks=True, xlim=(0, runtime)),
127+
title="IF_cond_exp_stoc example",
128+
annotations=f"Simulated with {sim.name()}"
129+
)
130+
plt.show()
131+
132+
sim.end()
133+
pylab.show()
134+
135+
# combined binaries_used ['IF_cond_exp_stoc.aplx','IF_cond_exp.aplx']
136+
# split binaries used(['IF_cond_exp_stoc_neuron.aplx','IF_cond_exp_neuron.aplx'])
137+
138+
if __name__ == "__main__":
139+
run_script()

integration_tests/test_scripts.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,19 @@ def test_examples_extra_models_examples_stdp_example_izk_cond(self):
183183
def test_examples_extra_models_examples_IF_curr_exp_ca2_adaptive(self):
184184
self.check_script("examples/extra_models_examples/IF_curr_exp_ca2_adaptive.py")
185185

186-
def test_examples_extra_models_examples_IF_cond_exp_stoc(self):
187-
self.check_script("examples/extra_models_examples/IF_cond_exp_stoc.py")
186+
def test_examples_extra_models_examples_IF_cond_exp_stoc_combined(self):
187+
from examples.extra_models_examples.IF_cond_exp_stoc import run_script
188+
run_script(split=False)
189+
self.check_binaries_used([
190+
'IF_cond_exp_stoc.aplx',
191+
'IF_cond_exp.aplx'])
192+
193+
def test_examples_extra_models_examples_IF_cond_exp_stoc_split(self):
194+
from examples.extra_models_examples.IF_cond_exp_stoc import run_script
195+
run_script(split=True)
196+
self.check_binaries_used([
197+
'IF_cond_exp_stoc_neuron.aplx',
198+
'IF_cond_exp_neuron.aplx'])
188199

189200
def test_balanced_random_balanced_random(self):
190201
self.check_script("balanced_random/balanced_random.py")

0 commit comments

Comments
 (0)