Skip to content

Commit

Permalink
add user-friendly error message in case of unspecified or incorrectly…
Browse files Browse the repository at this point in the history
… specified weight or delay variable (#1098)
  • Loading branch information
clinssen authored Sep 17, 2024
1 parent 726cffc commit eaf1b3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
7 changes: 1 addition & 6 deletions pynestml/cocos/co_co_nest_synapse_delay_not_assigned_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

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


Expand Down
23 changes: 14 additions & 9 deletions pynestml/codegeneration/nest_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit eaf1b3c

Please sign in to comment.