Skip to content

Commit

Permalink
Merge branch 'master' into ip_address_error_message
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfellows committed Sep 16, 2020
2 parents f01993d + 0d7f198 commit 5ed85d7
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ __pycache__
*.log
JobDestroyedError.txt
*.dat
/venv/
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
[Machine]
# Exact needs of extra monitor + SSA
max_sdram_allowed_per_chip = 1519836
max_sdram_allowed_per_chip = 1529836

[Buffers]
use_auto_pause_and_resume = True
# Lower than defaults
# This cause less partitioning and therefor more auto pause runs
minimum_auto_time_steps = 4000


[Simulation]

# performance controller to ensure only so many packets from a given
# app vertex happen at any given time (aka how many machine vertices
# from this app vertex can fire at same time)
app_machine_quantity = 5

time_between_cores = 1.2

# performance controller for how much of the time step to use for sending
fraction_of_time_spike_sending = 0.5

# performance controller for how much of the time step to use for before the
# TDMA
fraction_of_time_before_sending = 0.01
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def more_runs(self):
synfire_run.do_run(n_neurons, neurons_per_core=neurons_per_core,
run_times=[runtime])
spikes = synfire_run.get_output_pop_spikes_numpy()

# CB Currently eight but could change
# Needs to be larger than 1000 timesteps version
self.assert_logs_messages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,21 @@ use_auto_pause_and_resume = True
# Lower than defaults
# This cause less partitioning and therefor more auto pause runs
minimum_auto_time_steps = 1000


[Simulation]

# performance controller to ensure only so many packets from a given
# app vertex happen at any given time (aka how many machine vertices
# from this app vertex can fire at same time)
app_machine_quantity = 5

time_between_cores = 1.2

# performance controller for how much of the time step to use for sending
fraction_of_time_spike_sending = 0.5

# performance controller for how much of the time step to use for before the
# TDMA
fraction_of_time_before_sending = 0.01

Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ use_auto_pause_and_resume = True
# Lower than defaults
# This cause less partitioning and therefor more auto pause runs
minimum_auto_time_steps = 1000


[Simulation]

# performance controller to ensure only so many packets from a given
# app vertex happen at any given time (aka how many machine vertices
# from this app vertex can fire at same time)
app_machine_quantity = 5

time_between_cores = 2

# performance controller for how much of the time step to use for sending
fraction_of_time_spike_sending = 0.7

# performance controller for how much of the time step to use for before the
# TDMA
fraction_of_time_before_sending = 0.01
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,14 @@ def variable_rate_reset():
pop_2.record("spikes")

p.run(1000)
spikes_pop_2_1 = pop_2.get_data("spikes")
nump = [s.magnitude for s in spikes_pop_2_1.segments[0].spiketrains]
numpy.savetxt("spikesp2_1.txt", nump[0])
pop_2.set(rate=10)
p.run(1000)
spikes_pop_2_2 = pop_2.get_data("spikes")
nump = [s.magnitude for s in spikes_pop_2_2.segments[0].spiketrains]
numpy.savetxt("spikesp2_2.txt", nump[0])
pop_2.set(rate=100)
p.run(1000)
p.reset()
Expand All @@ -206,8 +212,11 @@ def variable_rate_reset():
spikes_p_2 = [s.magnitude for s in spikes_pop_2.segments[0].spiketrains]

print(spikes_1)
numpy.savetxt("spikes1.txt", spikes_1[0])
print(spikes_2)
numpy.savetxt("spikes2.txt", spikes_2[0])
print(spikes_p_2)
numpy.savetxt("spikesp2.txt", spikes_p_2[0])

for s1, s2, s3 in zip(spikes_1, spikes_2, spikes_p_2):
assert(numpy.array_equal(s1, s2))
Expand Down
230 changes: 147 additions & 83 deletions p8_integration_tests/quick_test/test_stdp/test_STDP_pair_additive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,103 +17,167 @@
from p8_integration_tests.base_test_case import BaseTestCase,\
calculate_spike_pair_additive_stdp_weight
import numpy
import unittest


class TestSTDPPairAdditive(BaseTestCase):

def potentiation_and_depression(self):
p.setup(1)
runtime = 100
initial_run = 1000 # to negate any initial conditions

# STDP parameters
a_plus = 0.01
a_minus = 0.01
tau_plus = 20
tau_minus = 20
plastic_delay = 3
initial_weight = 2.5
max_weight = 5
min_weight = 0

pre_spikes = [10, 50]
extra_spikes = [30]

for i in range(len(pre_spikes)):
pre_spikes[i] += initial_run

for i in range(len(extra_spikes)):
extra_spikes[i] += initial_run

# Spike source to send spike via plastic synapse
pre_pop = p.Population(1, p.SpikeSourceArray,
{'spike_times': pre_spikes}, label="pre")

# Spike source to send spike via static synapse to make
# post-plastic-synapse neuron fire
extra_pop = p.Population(1, p.SpikeSourceArray,
{'spike_times': extra_spikes}, label="extra")

# Post-plastic-synapse population
post_pop = p.Population(1, p.IF_curr_exp(), label="post")

# Create projections
p.Projection(
pre_pop, post_pop, p.OneToOneConnector(),
p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory")

p.Projection(
extra_pop, post_pop, p.OneToOneConnector(),
p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory")

syn_plas = p.STDPMechanism(
timing_dependence=p.SpikePairRule(tau_plus=tau_plus,
tau_minus=tau_minus,
A_plus=a_plus, A_minus=a_minus),
weight_dependence=p.AdditiveWeightDependence(w_min=min_weight,
w_max=max_weight),
def post_spike_same_time():
""" Check that the offsets between send times of different spike source
arrays don't change the outcome of STDP
"""

# STDP parameters
a_plus = 0.01
a_minus = 0.01
tau_plus = 20
tau_minus = 20
plastic_delay = 1
initial_weight = 4.0
max_weight = 5.0
min_weight = 0
pre_spikes = range(0, 10, 2)

p.setup(1)
pre_1 = p.Population(1, p.SpikeSourceArray(pre_spikes), label="pre_1")
pre_2 = p.Population(1, p.SpikeSourceArray(pre_spikes), label="pre_2")
post_1 = p.Population(1, p.IF_curr_exp(), label="post_1")
post_2 = p.Population(1, p.IF_curr_exp(), label="post_2")
post_1.record("spikes")
stdp = p.STDPMechanism(
timing_dependence=p.SpikePairRule(
tau_plus=tau_plus, tau_minus=tau_minus,
A_plus=a_plus, A_minus=a_minus),
weight_dependence=p.AdditiveWeightDependence(
w_min=min_weight, w_max=max_weight),
weight=initial_weight, delay=plastic_delay)
conn = p.OneToOneConnector()
proj_1 = p.Projection(pre_1, post_1, conn, stdp)
proj_2 = p.Projection(pre_2, post_2, conn, stdp)

p.run(12)

# Get the weights
weights_1 = list(proj_1.get('weight', 'list', with_address=False))
weights_2 = list(proj_2.get('weight', 'list', with_address=False))

# Get the spikes
post_spikes = numpy.array(
# pylint: disable=no-member
post_1.get_data('spikes').segments[0].spiketrains[0].magnitude)

p.end()

new_weight_exact = calculate_spike_pair_additive_stdp_weight(
pre_spikes, post_spikes, initial_weight, plastic_delay, max_weight,
a_plus, a_minus, tau_plus, tau_minus)

print(weights_1)
print(weights_2)
print(new_weight_exact)

assert(len(weights_1) == 1)
assert(len(weights_2) == 1)
assert(weights_1[0] == weights_2[0])
assert(numpy.allclose(weights_1, new_weight_exact, rtol=0.001))


def potentiation_and_depression():
p.setup(1)
runtime = 100
initial_run = 1000 # to negate any initial conditions

# STDP parameters
a_plus = 0.01
a_minus = 0.01
tau_plus = 20
tau_minus = 20
plastic_delay = 3
initial_weight = 2.5
max_weight = 5
min_weight = 0

pre_spikes = [10, 50]
extra_spikes = [30]

for i in range(len(pre_spikes)):
pre_spikes[i] += initial_run

plastic_synapse = p.Projection(pre_pop, post_pop,
p.OneToOneConnector(),
synapse_type=syn_plas,
receptor_type='excitatory')
for i in range(len(extra_spikes)):
extra_spikes[i] += initial_run

# Record the spikes
post_pop.record("spikes")
# Spike source to send spike via plastic synapse
pre_pop = p.Population(1, p.SpikeSourceArray,
{'spike_times': pre_spikes}, label="pre")

# Run
p.run(initial_run + runtime)
# Spike source to send spike via static synapse to make
# post-plastic-synapse neuron fire
extra_pop = p.Population(1, p.SpikeSourceArray,
{'spike_times': extra_spikes}, label="extra")

# Get the weights
weights = plastic_synapse.get('weight', 'list',
with_address=False)
# Post-plastic-synapse population
post_pop = p.Population(1, p.IF_curr_exp(), label="post")

# Get the spikes
post_spikes = numpy.array(
# pylint: disable=no-member
post_pop.get_data('spikes').segments[0].spiketrains[0].magnitude)
# Create projections
p.Projection(
pre_pop, post_pop, p.OneToOneConnector(),
p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory")

# End the simulation as all information gathered
p.end()
p.Projection(
extra_pop, post_pop, p.OneToOneConnector(),
p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory")

new_weight_exact = calculate_spike_pair_additive_stdp_weight(
pre_spikes, post_spikes, initial_weight, plastic_delay, max_weight,
a_plus, a_minus, tau_plus, tau_minus)
syn_plas = p.STDPMechanism(
timing_dependence=p.SpikePairRule(tau_plus=tau_plus,
tau_minus=tau_minus,
A_plus=a_plus, A_minus=a_minus),
weight_dependence=p.AdditiveWeightDependence(w_min=min_weight,
w_max=max_weight),
weight=initial_weight, delay=plastic_delay)

print("Pre neuron spikes at: {}".format(pre_spikes))
print("Post-neuron spikes at: {}".format(post_spikes))
target_spikes = [1014, 1032, 1053]
self.assertListEqual(list(post_spikes), target_spikes)
print("New weight exact: {}".format(new_weight_exact))
print("New weight SpiNNaker: {}".format(weights))
plastic_synapse = p.Projection(pre_pop, post_pop,
p.OneToOneConnector(),
synapse_type=syn_plas,
receptor_type='excitatory')

self.assertTrue(numpy.allclose(weights, new_weight_exact, rtol=0.001))
# Record the spikes
post_pop.record("spikes")

# Run
p.run(initial_run + runtime)

# Get the weights
weights = plastic_synapse.get('weight', 'list',
with_address=False)

# Get the spikes
post_spikes = numpy.array(
# pylint: disable=no-member
post_pop.get_data('spikes').segments[0].spiketrains[0].magnitude)

# End the simulation as all information gathered
p.end()

new_weight_exact = calculate_spike_pair_additive_stdp_weight(
pre_spikes, post_spikes, initial_weight, plastic_delay, max_weight,
a_plus, a_minus, tau_plus, tau_minus)

print("Pre neuron spikes at: {}".format(pre_spikes))
print("Post-neuron spikes at: {}".format(post_spikes))
target_spikes = [1014, 1032, 1053]
assert(all(s1 == s2
for s1, s2 in zip(list(post_spikes), target_spikes)))
print("New weight exact: {}".format(new_weight_exact))
print("New weight SpiNNaker: {}".format(weights))

assert(numpy.allclose(weights, new_weight_exact, rtol=0.001))


class TestSTDPPairAdditive(BaseTestCase):

def test_potentiation_and_depression(self):
self.runsafe(self.potentiation_and_depression)
self.runsafe(potentiation_and_depression)

def test_post_spike_same_time(self):
self.runsafe(post_spike_same_time)


if __name__ == '__main__':
unittest.main()
post_spike_same_time()
2 changes: 2 additions & 0 deletions p8_integration_tests/scripts_test/build_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def add_scripts(a_dir, prefix_len, test_file, exceptions, broken):
# exceptions.append("stdp_curve.py") # 118 seconds
# exceptions.append("stdp_curve_cond.py") # 121 seconds
exceptions.append("vogels_2011.py") # 698 seconds
# binary fail to compile
exceptions.append("structural_plasticity_with_stdp_2d.py")

with open(examples_script, "a") as examples_file:
examples_file.write("# flake8: noqa\n")
Expand Down
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ pytest-timeout
pytest-forked
pytest-progress
sphinx==1.5.3
testfixtures
testfixtures
statistics
Loading

0 comments on commit 5ed85d7

Please sign in to comment.