|
23 | 23 | import matplotlib.pyplot as plt |
24 | 24 | from pyNN.utility.plotting import Figure, Panel |
25 | 25 |
|
26 | | -# variables |
27 | | -weights = 1 |
28 | | -spike_time_facilitation = 4 |
29 | | -spike_time_trigger = 20 |
30 | | - |
31 | | -# set up simulation |
32 | | -simulation_timestep = 1 # ms |
33 | | -simulation_runtime = 100 # ms |
34 | | -p.setup(timestep=simulation_timestep) |
35 | | - |
36 | | -# neuron parameters |
37 | | -cell_params_semd = {'cm': 0.25, |
38 | | - 'i_offset': 0, # offset current |
39 | | - 'tau_m': 10, # membrane potential time constant |
40 | | - 'tau_refrac': 1, # refractory period time constant |
41 | | - 'tau_syn_E': 20, # excitatory current time constant |
42 | | - 'tau_syn_I': 20, # inhibitory current time constant |
43 | | - 'v_reset': -85, # reset potential |
44 | | - 'v_rest': -60, # resting potential |
45 | | - 'v_thresh': -50, # spiking threshold |
46 | | - 'scaling_factor': 100.0 # scaling factor for 2nd response |
47 | | - } |
48 | | - |
49 | | -# neuron populations |
50 | | -# (population size, neuron type, cell parameters, label) |
51 | | -sEMD = p.Population(1, p.extra_models.IF_curr_exp_sEMD, |
52 | | - cell_params_semd, label="sEMD") |
53 | | -input_facilitation = p.Population(1, p.SpikeSourceArray, |
54 | | - {'spike_times': [[spike_time_facilitation]]}, |
55 | | - label="input_facilitation") |
56 | | -input_trigger = p.Population(1, p.SpikeSourceArray, |
57 | | - {'spike_times': [[spike_time_trigger]]}, |
58 | | - label="input_trigger") |
59 | | - |
60 | | -sEMD.initialize(v=-60.0) |
61 | | - |
62 | | -# projections |
63 | | -p.Projection(input_facilitation, sEMD, p.OneToOneConnector(), |
64 | | - p.StaticSynapse(weight=weights, delay=1), |
65 | | - receptor_type='excitatory') |
66 | | -p.Projection(input_trigger, sEMD, p.OneToOneConnector(), |
67 | | - p.StaticSynapse(weight=weights, delay=1), |
68 | | - receptor_type='excitatory2') |
69 | | - |
70 | | -# records |
71 | | -sEMD.record(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) |
72 | | - |
73 | | -# run simulation |
74 | | -p.run(simulation_runtime) |
75 | | - |
76 | | -# receive data from neurons |
77 | | -spikes = sEMD.get_data(['spikes']) |
78 | | -v = sEMD.get_data(['v']) |
79 | | -current_exc = sEMD.get_data(['gsyn_exc']) |
80 | | -current_inh = sEMD.get_data(['gsyn_inh']) |
81 | | - |
82 | | -# plots |
83 | | -Figure( |
84 | | - # raster plot of the neuron spike times |
85 | | - Panel(spikes.segments[0].spiketrains, |
86 | | - yticks=True, markersize=4, xlim=(0, simulation_runtime)), |
87 | | - # membrane potential |
88 | | - Panel(v.segments[0].filter(name='v')[0], |
89 | | - ylabel="Membrane potential (mV)", |
90 | | - data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)), |
91 | | - # excitatory current |
92 | | - Panel(current_exc.segments[0].filter(name='gsyn_exc')[0], |
93 | | - ylabel="gsyn excitatory (mV)", |
94 | | - data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)), |
95 | | - # inhibitory current |
96 | | - Panel(current_inh.segments[0].filter(name='gsyn_inh')[0], |
97 | | - xlabel="Time (ms)", xticks=True, |
98 | | - ylabel="gsyn inhibitory (mV)", |
99 | | - data_labels=[sEMD.label], yticks=True, xlim=(0, simulation_runtime)), |
100 | | - title="SEMD example", |
101 | | - annotations=f"Simulated with {p.name()}" |
102 | | -) |
103 | | -plt.show() |
104 | | - |
105 | | -# end |
106 | | -p.end() |
| 26 | +def run_script(*, split: bool = False) -> None: |
| 27 | + """ |
| 28 | + Runs the example script |
| 29 | +
|
| 30 | + :param split: If True will split the Populations that receive data |
| 31 | + into synapse and neuron cores. |
| 32 | + This requires more cores but allows more spikes to be received. |
| 33 | + """ |
| 34 | + # variables |
| 35 | + weights = 1 |
| 36 | + spike_time_facilitation = 4 |
| 37 | + spike_time_trigger = 20 |
| 38 | + |
| 39 | + # set up simulation |
| 40 | + simulation_timestep = 1 # ms |
| 41 | + simulation_runtime = 100 # ms |
| 42 | + p.setup(timestep=simulation_timestep) |
| 43 | + |
| 44 | + if split: |
| 45 | + p.extra_models.IF_curr_exp_sEMD.set_model_n_synapse_cores(1) |
| 46 | + |
| 47 | + # neuron parameters |
| 48 | + cell_params_semd = { |
| 49 | + 'cm': 0.25, |
| 50 | + 'i_offset': 0, # offset current |
| 51 | + 'tau_m': 10, # membrane potential time constant |
| 52 | + 'tau_refrac': 1, # refractory period time constant |
| 53 | + 'tau_syn_E': 20, # excitatory current time constant |
| 54 | + 'tau_syn_I': 20, # inhibitory current time constant |
| 55 | + 'v_reset': -85, # reset potential |
| 56 | + 'v_rest': -60, # resting potential |
| 57 | + 'v_thresh': -50, # spiking threshold |
| 58 | + 'scaling_factor': 100.0 # scaling factor for 2nd response |
| 59 | + } |
| 60 | + |
| 61 | + # neuron populations |
| 62 | + # (population size, neuron type, cell parameters, label) |
| 63 | + sEMD = p.Population(1, p.extra_models.IF_curr_exp_sEMD, |
| 64 | + cell_params_semd, label="sEMD") |
| 65 | + input_facilitation = p.Population( |
| 66 | + 1, p.SpikeSourceArray, {'spike_times': [[spike_time_facilitation]]}, |
| 67 | + label="input_facilitation") |
| 68 | + input_trigger = p.Population( |
| 69 | + 1, p.SpikeSourceArray, {'spike_times': [[spike_time_trigger]]}, |
| 70 | + label="input_trigger") |
| 71 | + |
| 72 | + sEMD.initialize(v=-60.0) |
| 73 | + |
| 74 | + # projections |
| 75 | + p.Projection(input_facilitation, sEMD, p.OneToOneConnector(), |
| 76 | + p.StaticSynapse(weight=weights, delay=1), |
| 77 | + receptor_type='excitatory') |
| 78 | + p.Projection(input_trigger, sEMD, p.OneToOneConnector(), |
| 79 | + p.StaticSynapse(weight=weights, delay=1), |
| 80 | + receptor_type='excitatory2') |
| 81 | + |
| 82 | + # records |
| 83 | + sEMD.record(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) |
| 84 | + |
| 85 | + # run simulation |
| 86 | + p.run(simulation_runtime) |
| 87 | + |
| 88 | + # receive data from neurons |
| 89 | + spikes = sEMD.get_data(['spikes']) |
| 90 | + v = sEMD.get_data(['v']) |
| 91 | + current_exc = sEMD.get_data(['gsyn_exc']) |
| 92 | + current_inh = sEMD.get_data(['gsyn_inh']) |
| 93 | + |
| 94 | + # plots |
| 95 | + Figure( |
| 96 | + # raster plot of the neuron spike times |
| 97 | + Panel(spikes.segments[0].spiketrains, |
| 98 | + yticks=True, markersize=4, xlim=(0, simulation_runtime)), |
| 99 | + # membrane potential |
| 100 | + Panel(v.segments[0].filter(name='v')[0], |
| 101 | + ylabel="Membrane potential (mV)", |
| 102 | + data_labels=[sEMD.label], |
| 103 | + yticks=True, xlim=(0, simulation_runtime)), |
| 104 | + # excitatory current |
| 105 | + Panel(current_exc.segments[0].filter(name='gsyn_exc')[0], |
| 106 | + ylabel="gsyn excitatory (mV)", |
| 107 | + data_labels=[sEMD.label], |
| 108 | + yticks=True, xlim=(0, simulation_runtime)), |
| 109 | + # inhibitory current |
| 110 | + Panel(current_inh.segments[0].filter(name='gsyn_inh')[0], |
| 111 | + xlabel="Time (ms)", xticks=True, |
| 112 | + ylabel="gsyn inhibitory (mV)", |
| 113 | + data_labels=[sEMD.label], |
| 114 | + yticks=True, xlim=(0, simulation_runtime)), |
| 115 | + title="SEMD example", |
| 116 | + annotations=f"Simulated with {p.name()}" |
| 117 | + ) |
| 118 | + plt.show() |
| 119 | + |
| 120 | + # end |
| 121 | + p.end() |
| 122 | + |
| 123 | + |
| 124 | +# combined binaries [IF_curr_exp_sEMD.aplx] |
| 125 | +# split binaries [IF_curr_exp_sEMD_neuron.aplx] |
| 126 | + |
| 127 | + |
| 128 | +if __name__ == "__main__": |
| 129 | + run_script() |
| 130 | + |
0 commit comments