Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array_connector max calculations #1104

Merged
merged 3 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _get_n_connections_from_pre_vertex_with_delay_maximum(
def get_n_connections_from_pre_vertex_maximum(
self, post_vertex_slice, synapse_info, min_delay=None,
max_delay=None):
""" Get the maximum number of connections between those from any
""" Get the maximum number of connections from any
neuron in the pre vertex to the neurons in the post_vertex_slice,
for connections with a delay between min_delay and max_delay
(inclusive) if both specified (otherwise all connections).
Expand All @@ -297,7 +297,7 @@ def get_n_connections_from_pre_vertex_maximum(

@abstractmethod
def get_n_connections_to_post_vertex_maximum(self, synapse_info):
""" Get the maximum number of connections between those to any neuron
""" Get the maximum number of connections to any neuron
in the post vertex from neurons in the pre vertex.

:param SynapseInformation synapse_info:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,40 @@ def get_delay_minimum(self, synapse_info):
def get_n_connections_from_pre_vertex_maximum(
self, post_vertex_slice, synapse_info, min_delay=None,
max_delay=None):
n_connections = 0
max_connections_row = 0
post_lo = post_vertex_slice.lo_atom
post_hi = post_vertex_slice.hi_atom
# Max number per row is required
for i in range(self.__array_dims[0]):
n_connections_row = 0
for j in range(post_lo, post_hi+1):
if self.__array[i, j] == 1:
n_connections += 1
n_connections_row += 1

if n_connections_row > max_connections_row:
max_connections_row = n_connections_row

if min_delay is None and max_delay is None:
return n_connections
return max_connections_row

return self._get_n_connections_from_pre_vertex_with_delay_maximum(
synapse_info.delays, self.__n_total_connections, n_connections,
min_delay, max_delay, synapse_info)
synapse_info.delays, self.__n_total_connections,
max_connections_row, min_delay, max_delay, synapse_info)

@overrides(AbstractConnector.get_n_connections_to_post_vertex_maximum)
def get_n_connections_to_post_vertex_maximum(self, synapse_info):
return self.__n_total_connections
# Max number per column is required
max_connections_col = 0
for j in range(self.__array_dims[1]):
n_connections_col = 0
for i in range(self.__array_dims[0]):
if self.__array[i, j] == 1:
n_connections_col = 0

if n_connections_col > max_connections_col:
max_connections_col = n_connections_col

return max_connections_col

@overrides(AbstractConnector.get_weight_maximum)
def get_weight_maximum(self, synapse_info):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,62 @@ def do_run(plot):
return v, spikes, v2, spikes2


def do_larger_array(plot):
p.setup(timestep=1.0)

n_i = 64
n_e = 64

spikeArray = {'spike_times': [0]}
input_pop = p.Population(n_e, p.SpikeSourceArray(**spikeArray),
label='inputSpikes')
excit_pop = p.Population(n_e, p.IF_curr_exp, label='excit')
inhit_pop = p.Population(n_i, p.IF_curr_exp, label='inhib')
p.Projection(input_pop, excit_pop, p.AllToAllConnector(),
synapse_type=p.StaticSynapse(weight=5),
receptor_type='excitatory')

ie_conn = numpy.ones((n_i, n_e))
for i in range(n_e):
ie_conn[i, i] = 0

p.Projection(excit_pop, inhit_pop, p.OneToOneConnector(),
synapse_type=p.StaticSynapse(weight=2),
receptor_type='inhibitory')

ie_projec = p.Projection(inhit_pop, excit_pop, p.ArrayConnector(ie_conn),
synapse_type=p.StaticSynapse(weight=3),
receptor_type='excitatory')

excit_pop.record(["spikes", "v"])

runtime = 1000
p.run(runtime)

ie_conns = ie_projec.get(['weight', 'delay'], 'list')
v = excit_pop.get_data("v")
spikes = excit_pop.get_data("spikes")

if plot:
Figure(
# raster plot of the presynaptic neurons' spike times
Panel(spikes.segments[0].spiketrains,
yticks=True, markersize=1.2, xlim=(0, runtime), xticks=True),
# membrane potential of the postsynaptic neurons
Panel(v.segments[0].filter(name='v')[0],
ylabel="Membrane potential (mV)",
data_labels=[inhit_pop.label], yticks=True,
xlim=(0, runtime), xticks=True),
title="Testing ArrayConnector",
annotations="Simulated with {}".format(p.name())
)
plt.show()

p.end()

return v, spikes, ie_conns


class ArrayConnectorTest(BaseTestCase):

def a_run(self):
Expand All @@ -133,6 +189,17 @@ def a_run(self):
def test_a_run(self):
self.runsafe(self.a_run)

def larger_array(self):
v, spikes, conns = do_larger_array(plot=False)
# checks go here
spikes_test = neo_convertor.convert_spikes(spikes)
self.assertEqual(4032, len(conns))
self.assertEqual(640, len(spikes_test))

def test_larger_array(self):
self.runsafe(self.larger_array)


if __name__ == '__main__':
v, spikes, v2, spikes2 = do_run(plot=True)
v, spikes, conns = do_larger_array(plot=True)