Skip to content

Commit

Permalink
[BBPBGLIB-1110] Error now raised when executeConfigure is returned wi…
Browse files Browse the repository at this point in the history
…th errors (#120)

## Context

In the simulation config, synapse_configure contains HOC code.
Neurodamus should fail fast when there is an error in configuration,
instead of passing it forward.

## Scope

Error check is added to connection.py

## Testing

TBD

## Review
* [X] PR description is complete
* [X] Coding style (imports, function length, New functions, classes or
files) are good
* [x] Unit/Scientific test added
* [N/A] Updated Readme, in-code, developer documentation
  • Loading branch information
atemerev committed Feb 13, 2024
1 parent 54dcb52 commit 9b904a8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
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)

0 comments on commit 9b904a8

Please sign in to comment.