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: Empty connection sets #10

Merged
merged 5 commits into from
Aug 14, 2024
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
5 changes: 4 additions & 1 deletion bsb_nest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def create_connections(self, simdata, pre_nodes, post_nodes, cs):
pre_nodes, post_nodes, cs
):
MPI.barrier()
if len(pre_locs) == 0 or len(post_locs) == 0:
continue
cell_pairs, multiplicity = np.unique(
np.column_stack((pre_locs[:, 0], post_locs[:, 0])),
return_counts=True,
Expand All @@ -95,7 +97,8 @@ def predict_mem_iterator(self, pre_nodes, post_nodes, cs):
predicted_all_mem = (
len(pre_nodes) * 8 * 2 + len(post_nodes) * 8 * 2 + len(cs) * 6 * 8 * (16 + 2)
) * MPI.get_size()
predicted_local_mem = predicted_all_mem / len(cs.get_local_chunks("out"))
n_chunks = len(cs.get_local_chunks("out"))
predicted_local_mem = (predicted_all_mem / n_chunks) if n_chunks > 0 else 0.0
if predicted_local_mem > avmem / 2:
# Iterate block-by-block
return self.block_iterator(cs)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_nest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from unittest.mock import patch

import nest
import numpy as np
Expand Down Expand Up @@ -98,6 +99,18 @@ def spy(_):
self.assertGreaterEqual(err_mean, abs(mean_rate - expected_rate))
self.assertGreaterEqual(err_var, var_rate - expected_var)

@patch("bsb_hdf5.connectivity_set.ConnectivitySet.get_local_chunks")
def test_regression_issue_9(self, get_content_mock):
# Override get_local_chunks to test empty connection sets
get_content_mock.return_value = []
cfg = get_test_config("gif_pop_psc_exp")
# we delete the NEST connectivity rule
cfg.simulations["test_nest"].connection_models["gif_pop_psc_exp"].rule = None
network = Scaffold(cfg, self.storage)
network.compile()
# The simulation should run despite the absence of connections
network.run_simulation("test_nest")
drodarie marked this conversation as resolved.
Show resolved Hide resolved

def test_brunel(self):
cfg = get_test_config("brunel")
simcfg = cfg.simulations.test_nest
Expand Down