Skip to content

Commit

Permalink
Merge pull request #114 from SpiNNakerManchester/intro_lab
Browse files Browse the repository at this point in the history
Merge in Intro lab
  • Loading branch information
rowleya committed May 9, 2024
2 parents 4742e34 + 6364552 commit 98aed42
Show file tree
Hide file tree
Showing 42 changed files with 3,146 additions and 23 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ jobs:
uses: ./support/actions/install-matplotlib

- name: Lint with flake8
run: flake8 examples
run: flake8 examples balanced_random learning sudoku synfire

- name: Lint with pylint
uses: ./support/actions/pylint
with:
package: examples
package: examples balanced_random learning sudoku synfire
exitcheck: 39

validate:
Expand All @@ -72,9 +72,11 @@ jobs:
repository: SpiNNakerManchester/SupportScripts
path: support
- name: Run rat copyright enforcement
if: matrix.python-version == 3.12
uses: ./support/actions/check-copyrights
with:
config_file: rat_asl20.xml

- name: Validate CITATION.cff
if: matrix.python-version == 3.12
uses: dieghernan/cff-validator@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ __pycache__
.pytest_cache
*application_generated_data_files/
*reports/
.cache/
.mypy_cache/
7 changes: 7 additions & 0 deletions .ratexcludes
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
**/SpiNNFrontEndCommon/**
**/sPyNNaker/**
**/sPyNNaker8/**
**/.pylintrc
**/*.dll
**/*.exe
**/*.png
**/*linux
**/*osx
**/*.exe
**/.pylintrc
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ contact:
name: SpiNNaker Software Team
post-code: M13 9PL
license: Apache-2.0
repository: https://github.com/SpiNNakerManchester/PyNN8Examples
repository: https://github.com/SpiNNakerManchester/PyNNExamples
13 changes: 13 additions & 0 deletions balanced_random/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2017 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
111 changes: 111 additions & 0 deletions balanced_random/balanced_random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Copyright (c) 2017 The University of Manchester
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import matplotlib.pyplot as pylab
import numpy
from pyNN.random import RandomDistribution
from pyNN.utility.plotting import Figure, Panel
import pyNN.spiNNaker as p

p.setup(timestep=0.1)
p.set_number_of_neurons_per_core(p.IF_curr_exp, 64)
p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 64)
n_neurons = 500
n_exc = int(round(n_neurons * 0.8))
n_inh = int(round(n_neurons * 0.2))
weight_exc = 0.1
weight_inh = -5.0 * weight_exc
weight_input = 0.001

pop_input = p.Population(100, p.SpikeSourcePoisson(rate=0.0),
additional_parameters={
"max_rate": 50.0,
"seed": 0},
label="Input")

pop_exc = p.Population(n_exc, p.IF_curr_exp, label="Excitatory", seed=1)
pop_inh = p.Population(n_inh, p.IF_curr_exp, label="Inhibitory", seed=2)
stim_exc = p.Population(
n_exc, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Exc",
additional_parameters={"seed": 3})
stim_inh = p.Population(
n_inh, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Inh",
additional_parameters={"seed": 4})

delays_exc = RandomDistribution(
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
weights_exc = RandomDistribution(
"normal_clipped", mu=weight_exc, sigma=0.1, low=0, high=numpy.inf)
conn_exc = p.FixedProbabilityConnector(0.1)
synapse_exc = p.StaticSynapse(weight=weights_exc, delay=delays_exc)
delays_inh = RandomDistribution(
"normal_clipped", mu=0.75, sigma=0.375, low=1.0, high=1.6)
weights_inh = RandomDistribution(
"normal_clipped", mu=weight_inh, sigma=0.1, low=-numpy.inf, high=0)
conn_inh = p.FixedProbabilityConnector(0.1)
synapse_inh = p.StaticSynapse(weight=weights_inh, delay=delays_inh)
p.Projection(
pop_exc, pop_exc, conn_exc, synapse_exc, receptor_type="excitatory")
p.Projection(
pop_exc, pop_inh, conn_exc, synapse_exc, receptor_type="excitatory")
p.Projection(
pop_inh, pop_inh, conn_inh, synapse_inh, receptor_type="inhibitory")
p.Projection(
pop_inh, pop_exc, conn_inh, synapse_inh, receptor_type="inhibitory")

conn_stim = p.OneToOneConnector()
synapse_stim = p.StaticSynapse(weight=weight_exc, delay=1.0)
p.Projection(
stim_exc, pop_exc, conn_stim, synapse_stim, receptor_type="excitatory")
p.Projection(
stim_inh, pop_inh, conn_stim, synapse_stim, receptor_type="excitatory")

delays_input = RandomDistribution(
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
weights_input = RandomDistribution(
"normal_clipped", mu=weight_input, sigma=0.01, low=0, high=numpy.inf)
p.Projection(pop_input, pop_exc, p.AllToAllConnector(), p.StaticSynapse(
weight=weights_input, delay=delays_input))

pop_exc.initialize(
v=RandomDistribution("uniform", low=-65.0, high=-55.0))
pop_inh.initialize(
v=RandomDistribution("uniform", low=-65.0, high=-55.0))

pop_exc.record("spikes")

p.run(1000)

pop_input.set(rate=50.0)
p.run(1000)

pop_input.set(rate=10.0)
p.run(1000)

pop_input.set(rate=20.0)
p.run(1000)

data = pop_exc.get_data("spikes")
end_time = p.get_current_time()

p.end()

Figure(
# raster plot of the presynaptic neuron spike times
Panel(data.segments[0].spiketrains,
yticks=True, markersize=2.0, xlim=(0, end_time)),
title="Balanced Random Network",
annotations="Simulated with {}".format(p.name())
)
pylab.show()
118 changes: 118 additions & 0 deletions balanced_random/split/balanced_random_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import pylab
import numpy
from pyNN.random import RandomDistribution
from pyNN.utility.plotting import Figure, Panel
import pyNN.spiNNaker as p
from spynnaker.pyNN.extra_algorithms.splitter_components import (
SplitterPoissonDelegate, SplitterAbstractPopulationVertexNeuronsSynapses)

p.setup(timestep=0.1, time_scale_factor=1)
p.set_number_of_neurons_per_core(p.IF_curr_exp, 64)
p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 64)
n_neurons = 500
n_exc = int(round(n_neurons * 0.8))
n_inh = int(round(n_neurons * 0.2))
weight_exc = 0.1
weight_inh = -5.0 * weight_exc
weight_input = 0.001

pop_input_splitter = SplitterPoissonDelegate()
pop_input = p.Population(100, p.SpikeSourcePoisson(rate=0.0),
additional_parameters={
"max_rate": 50.0,
"seed": 0,
"splitter": pop_input_splitter},
label="Input")

pop_exc_splitter = \
SplitterAbstractPopulationVertexNeuronsSynapses(1, 128, False)
pop_exc = p.Population(n_exc, p.IF_curr_exp, label="Excitatory",
additional_parameters={"splitter": pop_exc_splitter,
"seed": 1})
pop_inh_splitter = \
SplitterAbstractPopulationVertexNeuronsSynapses(1, 128, False)
pop_inh = p.Population(n_inh, p.IF_curr_exp, label="Inhibitory",
additional_parameters={"splitter": pop_inh_splitter,
"seed": 2})
stim_exc_splitter = SplitterPoissonDelegate()
stim_exc = p.Population(
n_exc, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Exc",
additional_parameters={"seed": 3, "splitter": stim_exc_splitter})
stim_inh_splitter = SplitterPoissonDelegate()
stim_inh = p.Population(
n_inh, p.SpikeSourcePoisson(rate=1000.0), label="Stim_Inh",
additional_parameters={"seed": 4, "splitter": stim_inh_splitter})

delays_exc = RandomDistribution(
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
weights_exc = RandomDistribution(
"normal_clipped", mu=weight_exc, sigma=0.1, low=0, high=numpy.inf)
conn_exc = p.FixedProbabilityConnector(0.1)
synapse_exc = p.StaticSynapse(weight=weights_exc, delay=delays_exc)
delays_inh = RandomDistribution(
"normal_clipped", mu=0.75, sigma=0.375, low=1.0, high=1.6)
weights_inh = RandomDistribution(
"normal_clipped", mu=weight_inh, sigma=0.1, low=-numpy.inf, high=0)
conn_inh = p.FixedProbabilityConnector(0.1)
synapse_inh = p.StaticSynapse(weight=weights_inh, delay=delays_inh)
p.Projection(
pop_exc, pop_exc, conn_exc, synapse_exc, receptor_type="excitatory",
label="exc_exc")
p.Projection(
pop_exc, pop_inh, conn_exc, synapse_exc, receptor_type="excitatory",
label="exc_inh")
p.Projection(
pop_inh, pop_inh, conn_inh, synapse_inh, receptor_type="inhibitory",
label="inh_inh")
p.Projection(
pop_inh, pop_exc, conn_inh, synapse_inh, receptor_type="inhibitory",
label="inh_exc")

conn_stim = p.OneToOneConnector()
synapse_stim = p.StaticSynapse(weight=weight_exc, delay=1.0)
p.Projection(
stim_exc, pop_exc, conn_stim, synapse_stim, receptor_type="excitatory",
label="stim_exc_exc")
p.Projection(
stim_inh, pop_inh, conn_stim, synapse_stim, receptor_type="excitatory",
label="stim_inh_inh")

delays_input = RandomDistribution(
"normal_clipped", mu=1.5, sigma=0.75, low=1.0, high=1.6)
weights_input = RandomDistribution(
"normal_clipped", mu=weight_input, sigma=0.01, low=0, high=numpy.inf)
p.Projection(pop_input, pop_exc, p.AllToAllConnector(), p.StaticSynapse(
weight=weights_input, delay=delays_input),
label="input_exc")

pop_exc.initialize(
v=RandomDistribution("uniform", low=-65.0, high=-55.0))
pop_inh.initialize(
v=RandomDistribution("uniform", low=-65.0, high=-55.0))

pop_exc.record("spikes")

p.run(1000)

pop_input.set(rate=50.0)
p.run(1000)

pop_input.set(rate=10.0)
p.run(1000)

pop_input.set(rate=20.0)
p.run(1000)

data = pop_exc.get_data("spikes")
end_time = p.get_current_time()

p.end()

Figure(
# raster plot of the presynaptic neuron spike times
Panel(data.segments[0].spiketrains,
yticks=True, markersize=2.0, xlim=(0, end_time)),
title="Balanced Random Network",
annotations="Simulated with {}".format(p.name())
)
pylab.show()
2 changes: 2 additions & 0 deletions balanced_random/split/spynnaker.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Mode]
violate_1ms_wall_clock_restriction = True
4 changes: 3 additions & 1 deletion integration_tests/script_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def build_scripts(self):
too_long = {}
too_long["stdp_triplet.py"] = "10 minutes"

self.create_test_scripts(["examples"], too_long, exceptions)
self.create_test_scripts(
["examples","balanced_random", "learning", "synfire"],
too_long, exceptions)


if __name__ == '__main__':
Expand Down

0 comments on commit 98aed42

Please sign in to comment.