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

[BBPBGLIB-1110] Error now raised when executeConfigure is returned with errors #120

Merged
merged 4 commits into from
Feb 13, 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
11 changes: 8 additions & 3 deletions neurodamus/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
from enum import Enum
from .core import NeurodamusCore as Nd
from .core.configuration import GlobalConfig, SimConfig
from .core.configuration import GlobalConfig, SimConfig, ConfigurationError
from .utils import compat
from .utils.logging import log_all
from .utils.pyutils import append_recarray
Expand Down Expand Up @@ -556,12 +556,17 @@ def _update_conductance_ratio(self, syn_obj, is_inhibitory, value):
else:
syn_obj.NMDA_ratio = value

def _configure(self, synapses, configuration):
res = self.ConnUtils.executeConfigure(synapses, configuration)
if res > 0:
raise ConfigurationError(f"Errors found in configuration: {configuration}")

def _configure_cell(self, cell):
""" Internal helper to apply all the configuration statements on
a given cell synapses
"""
for config in self._configurations:
self.ConnUtils.executeConfigure(cell.CellRef.synlist, config)
self._configure(cell.CellRef.synlist, config)

def _configure_synapses(self):
""" Internal helper to apply all the configuration statements to
Expand All @@ -574,7 +579,7 @@ def configure_synapses(self, configuration):
""" Helper function to execute a configuration statement (hoc)
on all connection synapses.
"""
self.ConnUtils.executeConfigure(self._synapses, configuration)
self._configure(self._synapses, configuration)

def restart_events(self):
"""Restart the artificial events, coming from Replay or Spont-Minis"""
Expand Down
37 changes: 36 additions & 1 deletion tests/integration-e2e/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import json
import os
import pytest
from pathlib import Path

from neurodamus.core.configuration import ConfigurationError
from neurodamus.io.synapse_reader import SynapseParameters
from neurodamus.node import Node

from tempfile import NamedTemporaryFile

SIM_DIR = Path(__file__).parent.parent.absolute() / "simulations" / "v5_sonata"
CONFIG_FILE_MINI = SIM_DIR / "simulation_config_mini.json"


@pytest.fixture
def sonata_config_file_err(sonata_config):
extra_config = {"connection_overrides": [
{
"name": "config_ERR",
"source": "nodesPopB",
"target": "nodesPopB",
"synapse_configure": "%s.dummy=1"
}
]}

sonata_config.update(extra_config)

with NamedTemporaryFile("w", suffix='.json', delete=False) as config_file:
json.dump(sonata_config, config_file)

yield config_file
os.unlink(config_file.name)


@pytest.mark.slow
# This test is to mimic the error reported in HPCTM-1687 during connection.add_syanpses()
# when detecting conn._synapse_params with more than one element is not None
Expand All @@ -26,3 +50,14 @@ def test_add_synapses():
assert len(conn._synapse_params) == n_syns + 1
for syn_manager in n._circuits.all_synapse_managers():
syn_manager.finalize(0, False)


@pytest.mark.slow
def test_config_error(sonata_config_file_err):
with pytest.raises(ConfigurationError):
n = Node(str(sonata_config_file_err.name))
n.load_targets()
n.create_cells()
n.create_synapses()
for syn_manager in n._circuits.all_synapse_managers():
syn_manager.finalize(0, False)