Skip to content

Commit

Permalink
Merge branch 'master' into better_board_testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Sep 15, 2023
2 parents 98623bf + f11f300 commit 69205ba
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/c_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Checkout SupportScripts
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Checkout SupportScripts
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Checkout SupportScripts
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support
Expand Down Expand Up @@ -97,9 +97,9 @@ jobs:
python-version: ["3.8"]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Checkout SupportScripts
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: SpiNNakerManchester/SupportScripts
path: support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

APP = $(notdir $(CURDIR))

NEURON_MODEL_H = $(NEURON_DIR)/neuron/models/neuron_model_lif_impl.h
INPUT_TYPE_H = $(NEURON_DIR)/neuron/input_types/input_type_delta.h
NEURON_IMPL_H = $(NEURON_DIR)/neuron/implementations/neuron_impl_standard.h
THRESHOLD_TYPE_H = $(NEURON_DIR)/neuron/threshold_types/threshold_type_static.h
SYNAPSE_TYPE_H = $(NEURON_DIR)/neuron/synapse_types/synapse_types_delta_impl.h
SYNAPSE_DYNAMICS = $(NEURON_DIR)/neuron/plasticity/stdp/synapse_dynamics_stdp_mad_impl.c
TIMING_DEPENDENCE = $(NEURON_DIR)/neuron/plasticity/stdp/timing_dependence/timing_nearest_pair_impl.c
TIMING_DEPENDENCE_H = $(NEURON_DIR)/neuron/plasticity/stdp/timing_dependence/timing_nearest_pair_impl.h
WEIGHT_DEPENDENCE = $(NEURON_DIR)/neuron/plasticity/stdp/weight_dependence/weight_additive_one_term_impl.c
WEIGHT_DEPENDENCE_H = $(NEURON_DIR)/neuron/plasticity/stdp/weight_dependence/weight_additive_one_term_impl.h

include ../neural_build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

APP = $(notdir $(CURDIR))

NEURON_MODEL_H = $(NEURON_DIR)/neuron/models/neuron_model_lif_impl.h
INPUT_TYPE_H = $(NEURON_DIR)/neuron/input_types/input_type_delta.h
NEURON_IMPL_H = $(NEURON_DIR)/neuron/implementations/neuron_impl_standard.h
THRESHOLD_TYPE_H = $(NEURON_DIR)/neuron/threshold_types/threshold_type_static.h
SYNAPSE_TYPE_H = $(NEURON_DIR)/neuron/synapse_types/synapse_types_delta_impl.h
SYNAPSE_DYNAMICS = $(NEURON_DIR)/neuron/plasticity/stdp/synapse_dynamics_stdp_mad_impl.c
TIMING_DEPENDENCE = $(NEURON_DIR)/neuron/plasticity/stdp/timing_dependence/timing_pair_impl.c
TIMING_DEPENDENCE_H = $(NEURON_DIR)/neuron/plasticity/stdp/timing_dependence/timing_pair_impl.h
WEIGHT_DEPENDENCE = $(NEURON_DIR)/neuron/plasticity/stdp/weight_dependence/weight_additive_one_term_impl.c
WEIGHT_DEPENDENCE_H = $(NEURON_DIR)/neuron/plasticity/stdp/weight_dependence/weight_additive_one_term_impl.h

include ../neural_build.mk
2 changes: 2 additions & 0 deletions neural_modelling/makefiles/neuron/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ ifneq ($(SPYNNAKER_DEBUG), DEBUG)
IZK_cond_exp_stdp_mad_pair_additive \
IZK_cond_exp_dual_stdp_mad_pair_additive \
IF_curr_alpha_stdp_mad_pair_additive \
IF_curr_delta_stdp_mad_pair_additive \
IF_curr_delta_stdp_mad_nearest_pair_additive \
IF_curr_exp_stdp_mad_recurrent_pre_stochastic_multiplicative \
IF_curr_exp_stdp_mad_pfister_triplet_additive
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import logging
import os
from spinn_utilities.config_holder import get_config_str
from spinn_utilities.config_holder import get_config_str_or_none
from spinn_utilities.log import FormatAdapter
from spinn_utilities.progress_bar import ProgressBar
from spynnaker.pyNN.data import SpynnakerDataView
Expand Down Expand Up @@ -54,7 +54,7 @@ def spynnaker_neuron_graph_network_specification_report():
# create holders for data
dot_diagram, exeNotFoundExn = _get_diagram(_GRAPH_TITLE)

graph_format = get_config_str("Reports", "network_graph_format")
graph_format = get_config_str_or_none("Reports", "network_graph_format")
if graph_format is None:
if (SpynnakerDataView.get_n_vertices() +
SpynnakerDataView.get_n_partitions()) > CUTOFF:
Expand Down
5 changes: 3 additions & 2 deletions spynnaker/pyNN/spinnaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from pyNN import __version__ as pynn_version

from spinn_utilities.log import FormatAdapter
from spinn_utilities.config_holder import get_config_bool, get_config_str
from spinn_utilities.config_holder import (
get_config_bool, get_config_str_or_none)
from spinn_utilities.overrides import overrides

from spinn_front_end_common.interface.abstract_spinnaker_base import (
Expand Down Expand Up @@ -488,7 +489,7 @@ def _execute_delay_support_adder(self):
"""
Runs, times and logs the DelaySupportAdder if required.
"""
name = get_config_str("Mapping", "delay_support_adder")
name = get_config_str_or_none("Mapping", "delay_support_adder")
if name is None:
return
with FecTimer("DelaySupportAdder", TimerWork.OTHER):
Expand Down
223 changes: 223 additions & 0 deletions spynnaker_integration_tests/test_stdp/test_IF_curr_delta_stdp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# Copyright (c) 2023 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 numpy
import unittest
import pyNN.spiNNaker as sim
from spinnaker_testbase import BaseTestCase


class TestIFCurrDeltaSTDP(BaseTestCase):

def mad_pair_additive_delta(self):
timestep = 1
spike_current = 20
input_population_size = 2

# Spikes set so the calculated weights for each STDP projection
# should be identical
spike_times1 = [[1, 27, 55], [1, 27, 55]]
spike_times2 = [[1, 33, 59], [1, 33, 59]]
training_times = [28]
save_spike_times = [90]
runtime = save_spike_times[-1] + 10

sim.setup(timestep=timestep)

IF_curr_delta_model = sim.IF_curr_delta()

# Set up populations
ssa1 = sim.Population(
input_population_size, sim.SpikeSourceArray(spike_times1),
label='ssa1')
ssa2 = sim.Population(
input_population_size, sim.SpikeSourceArray(spike_times2),
label='ssa2')
save_neuron = sim.Population(
1, sim.SpikeSourceArray(save_spike_times), label='save_neuron')
injector_neurons_exc = sim.Population(
input_population_size, IF_curr_delta_model,
label='injector_neurons_exc')
injector_neurons_inh = sim.Population(
input_population_size, IF_curr_delta_model,
label='injector_neurons_inh')
teacher_population = sim.Population(
1, sim.SpikeSourceArray(training_times),
label='teacher_population')
output_neuron = sim.Population(
1, IF_curr_delta_model, label='output_neuron')

# Set up projections
static_synapse = sim.StaticSynapse(weight=spike_current, delay=1)
teaching_synapse = sim.StaticSynapse(weight=spike_current, delay=2)

# SSA -> injectors
sim.Projection(
ssa1, injector_neurons_exc, sim.OneToOneConnector(),
static_synapse, receptor_type='excitatory')
sim.Projection(
ssa2, injector_neurons_inh, sim.OneToOneConnector(),
static_synapse, receptor_type='excitatory')

# save -> injectors
sim.Projection(save_neuron, injector_neurons_exc,
sim.AllToAllConnector(allow_self_connections=True),
static_synapse, receptor_type='excitatory')
sim.Projection(save_neuron, injector_neurons_inh,
sim.AllToAllConnector(allow_self_connections=True),
static_synapse, receptor_type='excitatory')

# teacher -> output
sim.Projection(teacher_population, output_neuron,
sim.AllToAllConnector(allow_self_connections=True),
teaching_synapse, receptor_type='excitatory')

# stdp models for injector -> output
stdp_model = sim.STDPMechanism(
timing_dependence=sim.SpikePairRule(
tau_plus=10, tau_minus=12, A_plus=1, A_minus=-1),
weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=20),
weight=0, delay=1)
stdp_model2 = sim.STDPMechanism(
timing_dependence=sim.SpikePairRule(
tau_plus=10, tau_minus=12, A_plus=1, A_minus=-1),
weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=20),
weight=0, delay=1)

injector_proj_exc = sim.Projection(
injector_neurons_exc, output_neuron,
sim.AllToAllConnector(allow_self_connections=True),
stdp_model, receptor_type='excitatory')
injector_proj_inh = sim.Projection(
injector_neurons_inh, output_neuron,
sim.AllToAllConnector(allow_self_connections=True),
stdp_model2, receptor_type='inhibitory')

sim.run(runtime)

weights_exc = injector_proj_exc.get(["weight"], "list")
weights_inh = injector_proj_inh.get(["weight"], "list")

print(weights_exc)
print(weights_inh)

sim.end()

self.assertTrue(numpy.allclose(weights_exc, weights_inh, rtol=0.001))

def nearest_pair_additive_delta(self):
timestep = 1
spike_current = 20
input_population_size = 2

# Spikes set so the calculated weights for each STDP projection
# should be identical
spike_times1 = [[1, 27, 51], [1, 27, 51]]
spike_times2 = [[1, 33, 60], [1, 33, 60]]
training_times = [28]
save_spike_times = [90]
runtime = save_spike_times[-1] + 10

sim.setup(timestep=timestep)

IF_curr_delta_model = sim.IF_curr_delta()

# Set up populations
ssa1 = sim.Population(
input_population_size, sim.SpikeSourceArray(spike_times1),
label='ssa1')
ssa2 = sim.Population(
input_population_size, sim.SpikeSourceArray(spike_times2),
label='ssa2')
save_neuron = sim.Population(
1, sim.SpikeSourceArray(save_spike_times), label='save_neuron')
injector_neurons_exc = sim.Population(
input_population_size, IF_curr_delta_model,
label='injector_neurons_exc')
injector_neurons_inh = sim.Population(
input_population_size, IF_curr_delta_model,
label='injector_neurons_inh')
teacher_population = sim.Population(
1, sim.SpikeSourceArray(training_times),
label='teacher_population')
output_neuron = sim.Population(
1, IF_curr_delta_model, label='output_neuron')

# Set up projections
static_synapse = sim.StaticSynapse(weight=spike_current, delay=1)
teaching_synapse = sim.StaticSynapse(weight=spike_current, delay=2)

# SSA -> injectors
sim.Projection(
ssa1, injector_neurons_exc, sim.OneToOneConnector(),
static_synapse, receptor_type='excitatory')
sim.Projection(
ssa2, injector_neurons_inh, sim.OneToOneConnector(),
static_synapse, receptor_type='excitatory')

# save -> injectors
sim.Projection(save_neuron, injector_neurons_exc,
sim.AllToAllConnector(allow_self_connections=True),
static_synapse, receptor_type='excitatory')
sim.Projection(save_neuron, injector_neurons_inh,
sim.AllToAllConnector(allow_self_connections=True),
static_synapse, receptor_type='excitatory')

# teacher -> output
sim.Projection(teacher_population, output_neuron,
sim.AllToAllConnector(allow_self_connections=True),
teaching_synapse, receptor_type='excitatory')

# stdp models for injector -> output
stdp_model = sim.STDPMechanism(
timing_dependence=sim.extra_models.SpikeNearestPairRule(
tau_plus=10, tau_minus=12, A_plus=1, A_minus=-1),
weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=20),
weight=0, delay=1)
stdp_model2 = sim.STDPMechanism(
timing_dependence=sim.extra_models.SpikeNearestPairRule(
tau_plus=10, tau_minus=12, A_plus=1, A_minus=-1),
weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=20),
weight=0, delay=1)

injector_proj_exc = sim.Projection(
injector_neurons_exc, output_neuron,
sim.AllToAllConnector(allow_self_connections=True),
stdp_model, receptor_type='excitatory')
injector_proj_inh = sim.Projection(
injector_neurons_inh, output_neuron,
sim.AllToAllConnector(allow_self_connections=True),
stdp_model2, receptor_type='inhibitory')

sim.run(runtime)

weights_exc = injector_proj_exc.get(["weight"], "list")
weights_inh = injector_proj_inh.get(["weight"], "list")

print(weights_exc)
print(weights_inh)

sim.end()

self.assertTrue(numpy.allclose(weights_exc, weights_inh, rtol=0.001))

def test_mad_pair_additive_delta(self):
self.runsafe(self.mad_pair_additive_delta)

def test_nearest_pair_additive_delta(self):
self.runsafe(self.nearest_pair_additive_delta)


if __name__ == '__main__':
unittest.main()

0 comments on commit 69205ba

Please sign in to comment.