diff --git a/neurodamus/connection.py b/neurodamus/connection.py index 3f9f6308..e60634c0 100644 --- a/neurodamus/connection.py +++ b/neurodamus/connection.py @@ -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 @@ -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 @@ -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""" diff --git a/tests/integration-e2e/test_connection.py b/tests/integration-e2e/test_connection.py index fa075a88..a32ab599 100644 --- a/tests/integration-e2e/test_connection.py +++ b/tests/integration-e2e/test_connection.py @@ -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 @@ -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)