From eaf1b3cf8aa5170e6436c7a269047745640a621c Mon Sep 17 00:00:00 2001 From: clinssen Date: Tue, 17 Sep 2024 11:36:31 +0200 Subject: [PATCH] add user-friendly error message in case of unspecified or incorrectly specified weight or delay variable (#1098) --- ...o_co_nest_synapse_delay_not_assigned_to.py | 7 +----- .../codegeneration/nest_code_generator.py | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pynestml/cocos/co_co_nest_synapse_delay_not_assigned_to.py b/pynestml/cocos/co_co_nest_synapse_delay_not_assigned_to.py index 50c86cc72..ef379c498 100644 --- a/pynestml/cocos/co_co_nest_synapse_delay_not_assigned_to.py +++ b/pynestml/cocos/co_co_nest_synapse_delay_not_assigned_to.py @@ -19,15 +19,10 @@ # You should have received a copy of the GNU General Public License # along with NEST. If not, see . +from pynestml.cocos.co_co import CoCo from pynestml.meta_model.ast_assignment import ASTAssignment from pynestml.meta_model.ast_model import ASTModel -from pynestml.cocos.co_co import CoCo -from pynestml.symbol_table.scope import ScopeType -from pynestml.symbols.symbol import SymbolKind -from pynestml.symbols.variable_symbol import BlockType -from pynestml.utils.ast_utils import ASTUtils from pynestml.utils.logger import LoggingLevel, Logger -from pynestml.utils.messages import Messages from pynestml.visitors.ast_visitor import ASTVisitor diff --git a/pynestml/codegeneration/nest_code_generator.py b/pynestml/codegeneration/nest_code_generator.py index 13a69d95d..01a5a696d 100644 --- a/pynestml/codegeneration/nest_code_generator.py +++ b/pynestml/codegeneration/nest_code_generator.py @@ -172,10 +172,20 @@ def __init__(self, options: Optional[Mapping[str, Any]] = None): def run_nest_target_specific_cocos(self, neurons: Sequence[ASTModel], synapses: Sequence[ASTModel]): for synapse in synapses: synapse_name_stripped = removesuffix(removesuffix(synapse.name.split("_with_")[0], "_"), FrontendConfiguration.suffix) - delay_variable = self.get_option("delay_variable")[synapse_name_stripped] - CoCoNESTSynapseDelayNotAssignedTo.check_co_co(delay_variable, synapse) - if Logger.has_errors(synapse): - raise Exception("Error(s) occurred during code generation") + + # special case for NEST delay variable (state or parameter) + assert synapse_name_stripped in self.get_option("delay_variable").keys(), "Please specify a delay variable for synapse '" + synapse_name_stripped + "' in the code generator options (see https://nestml.readthedocs.io/en/latest/running/running_nest.html#dendritic-delay-and-synaptic-weight)" + assert ASTUtils.get_variable_by_name(synapse, self.get_option("delay_variable")[synapse_name_stripped]), "Delay variable '" + self.get_option("delay_variable")[synapse_name_stripped] + "' not found in synapse '" + synapse_name_stripped + "' (see https://nestml.readthedocs.io/en/latest/running/running_nest.html#dendritic-delay-and-synaptic-weight)" + + # special case for NEST weight variable (state or parameter) + assert synapse_name_stripped in self.get_option("weight_variable").keys(), "Please specify a weight variable for synapse '" + synapse_name_stripped + "' in the code generator options (see https://nestml.readthedocs.io/en/latest/running/running_nest.html#dendritic-delay-and-synaptic-weight)" + assert ASTUtils.get_variable_by_name(synapse, self.get_option("weight_variable")[synapse_name_stripped]), "Weight variable '" + self.get_option("weight_variable")[synapse_name_stripped] + "' not found in synapse '" + synapse_name_stripped + "' (see https://nestml.readthedocs.io/en/latest/running/running_nest.html#dendritic-delay-and-synaptic-weight)" + + if self.option_exists("delay_variable") and synapse_name_stripped in self.get_option("delay_variable").keys(): + delay_variable = self.get_option("delay_variable")[synapse_name_stripped] + CoCoNESTSynapseDelayNotAssignedTo.check_co_co(delay_variable, synapse) + if Logger.has_errors(synapse): + raise Exception("Error(s) occurred during code generation") def setup_printers(self): self._constant_printer = ConstantPrinter() @@ -430,12 +440,7 @@ def analyse_synapse(self, synapse: ASTModel) -> Dict[str, ASTAssignment]: ASTUtils.add_timestep_symbol(synapse) self.update_symbol_table(synapse) - synapse_name_stripped = removesuffix(removesuffix(synapse.name.split("_with_")[0], "_"), FrontendConfiguration.suffix) - # special case for NEST delay variable (state or parameter) - ASTUtils.update_blocktype_for_common_parameters(synapse) - assert synapse_name_stripped in self.get_option("delay_variable").keys(), "Please specify a delay variable for synapse '" + synapse_name_stripped + "' in the code generator options" - assert ASTUtils.get_variable_by_name(synapse, self.get_option("delay_variable")[synapse_name_stripped]), "Delay variable '" + self.get_option("delay_variable")[synapse_name_stripped] + "' not found in synapse '" + synapse_name_stripped + "'" return spike_updates