Skip to content

Commit

Permalink
Don't return early from target_gids, enable intersection (#198)
Browse files Browse the repository at this point in the history
## Context

`connection_override` blocks may define a source and target nodeset
which will filter the corresponding cells and associated connections.

However, under some circumstances the filter was not being applied,
which could potentially lead to more connections being instantiated.
When applied the filter it was noticeable it would consider all
populations.
It is unclear whether that actually could happen in current circuits,
but in unit tests that was observable when a nodeset spanned over
multiple populations.

## Scope

 - Apply the intersection of current cell target 
 - Make each ConnectionManager filter the target by its populations.
 
## Testing
 - Unit test reviewed (started failing)
 - blueconfig tests don't seem to get impacted

## Review
* [x] PR description is complete
* [x] Coding style (imports, function length, New functions, classes or
files) are good
  • Loading branch information
ferdonline authored Oct 17, 2024
1 parent a8e715e commit 73f2648
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 10 additions & 7 deletions neurodamus/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,14 @@ def connect_group(self, conn_source, conn_destination, synapse_type_restrict=Non
mod_override (str): ModOverride given for this connection group
"""
conn_kwargs = {}
pop = self._cur_population
conn_pop = self._cur_population
dst_pop_name = self._cell_manager.population_name
src_pop_name = self._src_cell_manager.population_name
logging.debug("Connecting group %s -> %s", conn_source, conn_destination)
src_tspec = TargetSpec(conn_source)
dst_tspec = TargetSpec(conn_destination)
src_target = src_tspec.name and self._target_manager.get_target(src_tspec)
dst_target = dst_tspec.name and self._target_manager.get_target(dst_tspec)
src_target = src_tspec.name and self._target_manager.get_target(src_tspec, src_pop_name)
dst_target = dst_tspec.name and self._target_manager.get_target(dst_tspec, dst_pop_name)

if src_target and src_target.is_void() or dst_target and dst_target.is_void():
logging.debug("Skip void connectivity for current connectivity: %s - %s",
Expand All @@ -573,7 +575,7 @@ def connect_group(self, conn_source, conn_destination, synapse_type_restrict=Non

if SimConfig.dry_run:
syn_count = self._get_conn_stats(dst_target, src_target)
log_all(VERBOSE_LOGLEVEL, "%s -> %s: %d", pop.src_name, conn_destination, syn_count)
log_all(VERBOSE_LOGLEVEL, "%s-> %s: %d", conn_pop.src_name, conn_destination, syn_count)
self._dry_run_stats.synapse_counts[self.CONNECTIONS_TYPE] += syn_count
return

Expand All @@ -584,7 +586,7 @@ def connect_group(self, conn_source, conn_destination, synapse_type_restrict=Non
if self._load_offsets:
conn_kwargs["synapses_offset"] = extra_params["synapse_index"][0]

cur_conn = pop.get_or_create_connection(sgid, tgid, **conn_kwargs)
cur_conn = conn_pop.get_or_create_connection(sgid, tgid, **conn_kwargs)
if cur_conn.locked:
continue
self._add_synapses(cur_conn, syns_params, synapse_type_restrict, offset)
Expand Down Expand Up @@ -644,8 +646,9 @@ def _iterate_conn_params(self, src_target, dst_target, gids=None, show_progress=

def target_gids(gids):
if gids is None:
return self._raw_gids
gids = numpy.intersect1d(gids, self._raw_gids)
gids = self._raw_gids
else:
gids = numpy.intersect1d(gids, self._raw_gids)
if dst_target:
gids = numpy.intersect1d(gids, dst_target.get_raw_gids())
return gids
Expand Down
5 changes: 2 additions & 3 deletions tests/scientific/test_spont_minis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ def test_spont_minis(sonata_config_file):
)

edges_a: SynapseRuleManager = nd.circuits.get_edge_manager("NodeA", "NodeA")
assert len(list(edges_a.all_connections())) == 2
# Note: Before #198 we would instantiate a projection conn as being internal
assert len(list(edges_a.all_connections())) == 1
conn_2_1 = next(edges_a.get_connections(1, 2))
conn_1_2 = next(edges_a.get_connections(2, 1))
assert conn_2_1._spont_minis.rate == SPONT_RATE
assert conn_1_2._spont_minis is None

c1 = edges_a.cell_manager.get_cellref(1)
voltage_vec = Nd.Vector()
Expand Down

0 comments on commit 73f2648

Please sign in to comment.