Skip to content

Commit 98aed42

Browse files
authored
Merge pull request #114 from SpiNNakerManchester/intro_lab
Merge in Intro lab
2 parents 4742e34 + 6364552 commit 98aed42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3146
-23
lines changed

.github/workflows/python_actions.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ jobs:
5353
uses: ./support/actions/install-matplotlib
5454

5555
- name: Lint with flake8
56-
run: flake8 examples
56+
run: flake8 examples balanced_random learning sudoku synfire
5757

5858
- name: Lint with pylint
5959
uses: ./support/actions/pylint
6060
with:
61-
package: examples
61+
package: examples balanced_random learning sudoku synfire
6262
exitcheck: 39
6363

6464
validate:
@@ -72,9 +72,11 @@ jobs:
7272
repository: SpiNNakerManchester/SupportScripts
7373
path: support
7474
- name: Run rat copyright enforcement
75+
if: matrix.python-version == 3.12
7576
uses: ./support/actions/check-copyrights
7677
with:
7778
config_file: rat_asl20.xml
7879

7980
- name: Validate CITATION.cff
81+
if: matrix.python-version == 3.12
8082
uses: dieghernan/cff-validator@main

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ __pycache__
77
.pytest_cache
88
*application_generated_data_files/
99
*reports/
10+
.cache/
1011
.mypy_cache/

.ratexcludes

+7
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88
**/SpiNNFrontEndCommon/**
99
**/sPyNNaker/**
1010
**/sPyNNaker8/**
11+
**/.pylintrc
12+
**/*.dll
13+
**/*.exe
14+
**/*.png
15+
**/*linux
16+
**/*osx
17+
**/*.exe
1118
**/.pylintrc

CITATION.cff

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ contact:
105105
name: SpiNNaker Software Team
106106
post-code: M13 9PL
107107
license: Apache-2.0
108-
repository: https://github.com/SpiNNakerManchester/PyNN8Examples
108+
repository: https://github.com/SpiNNakerManchester/PyNNExamples

balanced_random/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2017 The University of Manchester
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

balanced_random/balanced_random.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Copyright (c) 2017 The University of Manchester
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import matplotlib.pyplot as pylab
16+
import numpy
17+
from pyNN.random import RandomDistribution
18+
from pyNN.utility.plotting import Figure, Panel
19+
import pyNN.spiNNaker as p
20+
21+
p.setup(timestep=0.1)
22+
p.set_number_of_neurons_per_core(p.IF_curr_exp, 64)
23+
p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 64)
24+
n_neurons = 500
25+
n_exc = int(round(n_neurons * 0.8))
26+
n_inh = int(round(n_neurons * 0.2))
27+
weight_exc = 0.1
28+
weight_inh = -5.0 * weight_exc
29+
weight_input = 0.001
30+
31+
pop_input = p.Population(100, p.SpikeSourcePoisson(rate=0.0),
32+
additional_parameters={
33+
"max_rate": 50.0,
34+
"seed": 0},
35+
label="Input")
36+
37+
pop_exc = p.Population(n_exc, p.IF_curr_exp, label="Excitatory", seed=1)
38+
pop_inh = p.Population(n_inh, p.IF_curr_exp, label="Inhibitory", seed=2)
39+
stim_exc = p.Population(
40+
n_exc, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Exc",
41+
additional_parameters={"seed": 3})
42+
stim_inh = p.Population(
43+
n_inh, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Inh",
44+
additional_parameters={"seed": 4})
45+
46+
delays_exc = RandomDistribution(
47+
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
48+
weights_exc = RandomDistribution(
49+
"normal_clipped", mu=weight_exc, sigma=0.1, low=0, high=numpy.inf)
50+
conn_exc = p.FixedProbabilityConnector(0.1)
51+
synapse_exc = p.StaticSynapse(weight=weights_exc, delay=delays_exc)
52+
delays_inh = RandomDistribution(
53+
"normal_clipped", mu=0.75, sigma=0.375, low=1.0, high=1.6)
54+
weights_inh = RandomDistribution(
55+
"normal_clipped", mu=weight_inh, sigma=0.1, low=-numpy.inf, high=0)
56+
conn_inh = p.FixedProbabilityConnector(0.1)
57+
synapse_inh = p.StaticSynapse(weight=weights_inh, delay=delays_inh)
58+
p.Projection(
59+
pop_exc, pop_exc, conn_exc, synapse_exc, receptor_type="excitatory")
60+
p.Projection(
61+
pop_exc, pop_inh, conn_exc, synapse_exc, receptor_type="excitatory")
62+
p.Projection(
63+
pop_inh, pop_inh, conn_inh, synapse_inh, receptor_type="inhibitory")
64+
p.Projection(
65+
pop_inh, pop_exc, conn_inh, synapse_inh, receptor_type="inhibitory")
66+
67+
conn_stim = p.OneToOneConnector()
68+
synapse_stim = p.StaticSynapse(weight=weight_exc, delay=1.0)
69+
p.Projection(
70+
stim_exc, pop_exc, conn_stim, synapse_stim, receptor_type="excitatory")
71+
p.Projection(
72+
stim_inh, pop_inh, conn_stim, synapse_stim, receptor_type="excitatory")
73+
74+
delays_input = RandomDistribution(
75+
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
76+
weights_input = RandomDistribution(
77+
"normal_clipped", mu=weight_input, sigma=0.01, low=0, high=numpy.inf)
78+
p.Projection(pop_input, pop_exc, p.AllToAllConnector(), p.StaticSynapse(
79+
weight=weights_input, delay=delays_input))
80+
81+
pop_exc.initialize(
82+
v=RandomDistribution("uniform", low=-65.0, high=-55.0))
83+
pop_inh.initialize(
84+
v=RandomDistribution("uniform", low=-65.0, high=-55.0))
85+
86+
pop_exc.record("spikes")
87+
88+
p.run(1000)
89+
90+
pop_input.set(rate=50.0)
91+
p.run(1000)
92+
93+
pop_input.set(rate=10.0)
94+
p.run(1000)
95+
96+
pop_input.set(rate=20.0)
97+
p.run(1000)
98+
99+
data = pop_exc.get_data("spikes")
100+
end_time = p.get_current_time()
101+
102+
p.end()
103+
104+
Figure(
105+
# raster plot of the presynaptic neuron spike times
106+
Panel(data.segments[0].spiketrains,
107+
yticks=True, markersize=2.0, xlim=(0, end_time)),
108+
title="Balanced Random Network",
109+
annotations="Simulated with {}".format(p.name())
110+
)
111+
pylab.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import pylab
2+
import numpy
3+
from pyNN.random import RandomDistribution
4+
from pyNN.utility.plotting import Figure, Panel
5+
import pyNN.spiNNaker as p
6+
from spynnaker.pyNN.extra_algorithms.splitter_components import (
7+
SplitterPoissonDelegate, SplitterAbstractPopulationVertexNeuronsSynapses)
8+
9+
p.setup(timestep=0.1, time_scale_factor=1)
10+
p.set_number_of_neurons_per_core(p.IF_curr_exp, 64)
11+
p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 64)
12+
n_neurons = 500
13+
n_exc = int(round(n_neurons * 0.8))
14+
n_inh = int(round(n_neurons * 0.2))
15+
weight_exc = 0.1
16+
weight_inh = -5.0 * weight_exc
17+
weight_input = 0.001
18+
19+
pop_input_splitter = SplitterPoissonDelegate()
20+
pop_input = p.Population(100, p.SpikeSourcePoisson(rate=0.0),
21+
additional_parameters={
22+
"max_rate": 50.0,
23+
"seed": 0,
24+
"splitter": pop_input_splitter},
25+
label="Input")
26+
27+
pop_exc_splitter = \
28+
SplitterAbstractPopulationVertexNeuronsSynapses(1, 128, False)
29+
pop_exc = p.Population(n_exc, p.IF_curr_exp, label="Excitatory",
30+
additional_parameters={"splitter": pop_exc_splitter,
31+
"seed": 1})
32+
pop_inh_splitter = \
33+
SplitterAbstractPopulationVertexNeuronsSynapses(1, 128, False)
34+
pop_inh = p.Population(n_inh, p.IF_curr_exp, label="Inhibitory",
35+
additional_parameters={"splitter": pop_inh_splitter,
36+
"seed": 2})
37+
stim_exc_splitter = SplitterPoissonDelegate()
38+
stim_exc = p.Population(
39+
n_exc, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Exc",
40+
additional_parameters={"seed": 3, "splitter": stim_exc_splitter})
41+
stim_inh_splitter = SplitterPoissonDelegate()
42+
stim_inh = p.Population(
43+
n_inh, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Inh",
44+
additional_parameters={"seed": 4, "splitter": stim_inh_splitter})
45+
46+
delays_exc = RandomDistribution(
47+
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
48+
weights_exc = RandomDistribution(
49+
"normal_clipped", mu=weight_exc, sigma=0.1, low=0, high=numpy.inf)
50+
conn_exc = p.FixedProbabilityConnector(0.1)
51+
synapse_exc = p.StaticSynapse(weight=weights_exc, delay=delays_exc)
52+
delays_inh = RandomDistribution(
53+
"normal_clipped", mu=0.75, sigma=0.375, low=1.0, high=1.6)
54+
weights_inh = RandomDistribution(
55+
"normal_clipped", mu=weight_inh, sigma=0.1, low=-numpy.inf, high=0)
56+
conn_inh = p.FixedProbabilityConnector(0.1)
57+
synapse_inh = p.StaticSynapse(weight=weights_inh, delay=delays_inh)
58+
p.Projection(
59+
pop_exc, pop_exc, conn_exc, synapse_exc, receptor_type="excitatory",
60+
label="exc_exc")
61+
p.Projection(
62+
pop_exc, pop_inh, conn_exc, synapse_exc, receptor_type="excitatory",
63+
label="exc_inh")
64+
p.Projection(
65+
pop_inh, pop_inh, conn_inh, synapse_inh, receptor_type="inhibitory",
66+
label="inh_inh")
67+
p.Projection(
68+
pop_inh, pop_exc, conn_inh, synapse_inh, receptor_type="inhibitory",
69+
label="inh_exc")
70+
71+
conn_stim = p.OneToOneConnector()
72+
synapse_stim = p.StaticSynapse(weight=weight_exc, delay=1.0)
73+
p.Projection(
74+
stim_exc, pop_exc, conn_stim, synapse_stim, receptor_type="excitatory",
75+
label="stim_exc_exc")
76+
p.Projection(
77+
stim_inh, pop_inh, conn_stim, synapse_stim, receptor_type="excitatory",
78+
label="stim_inh_inh")
79+
80+
delays_input = RandomDistribution(
81+
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
82+
weights_input = RandomDistribution(
83+
"normal_clipped", mu=weight_input, sigma=0.01, low=0, high=numpy.inf)
84+
p.Projection(pop_input, pop_exc, p.AllToAllConnector(), p.StaticSynapse(
85+
weight=weights_input, delay=delays_input),
86+
label="input_exc")
87+
88+
pop_exc.initialize(
89+
v=RandomDistribution("uniform", low=-65.0, high=-55.0))
90+
pop_inh.initialize(
91+
v=RandomDistribution("uniform", low=-65.0, high=-55.0))
92+
93+
pop_exc.record("spikes")
94+
95+
p.run(1000)
96+
97+
pop_input.set(rate=50.0)
98+
p.run(1000)
99+
100+
pop_input.set(rate=10.0)
101+
p.run(1000)
102+
103+
pop_input.set(rate=20.0)
104+
p.run(1000)
105+
106+
data = pop_exc.get_data("spikes")
107+
end_time = p.get_current_time()
108+
109+
p.end()
110+
111+
Figure(
112+
# raster plot of the presynaptic neuron spike times
113+
Panel(data.segments[0].spiketrains,
114+
yticks=True, markersize=2.0, xlim=(0, end_time)),
115+
title="Balanced Random Network",
116+
annotations="Simulated with {}".format(p.name())
117+
)
118+
pylab.show()

balanced_random/split/spynnaker.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Mode]
2+
violate_1ms_wall_clock_restriction = True

integration_tests/script_builder.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def build_scripts(self):
3333
too_long = {}
3434
too_long["stdp_triplet.py"] = "10 minutes"
3535

36-
self.create_test_scripts(["examples"], too_long, exceptions)
36+
self.create_test_scripts(
37+
["examples","balanced_random", "learning", "synfire"],
38+
too_long, exceptions)
3739

3840

3941
if __name__ == '__main__':

0 commit comments

Comments
 (0)