|
33 | 33 | from pyNN.utility.plotting import Figure, Panel |
34 | 34 | import matplotlib.pyplot as plt |
35 | 35 |
|
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() |
0 commit comments