Skip to content

Commit

Permalink
Fix the case that there is a complex neuron model and a simple synaps…
Browse files Browse the repository at this point in the history
…e model that does not transfer any variables (#1067)

* fix template in case of no transferred variables
---------

Co-authored-by: C.A.P. Linssen <charl@turingbirds.com>
  • Loading branch information
clinssen and C.A.P. Linssen authored Jun 19, 2024
1 parent fef2d71 commit ac1bf14
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void {{neuronName}}::pre_run_hook()
{%- include "directives_cpp/GSLDifferentiationFunction.jinja2" %}
{%- endfor %}

{%- if paired_synapse is defined %}
{%- if paired_synapse is defined and (purely_numeric_state_variables_moved + analytic_state_variables_moved) | length > 0 %}
{# for neuron-synapse co-generation: separate integrator for the emulated integrate_odes() calls below in this template #}
{%- set args = utils.resolve_variables_to_expressions(astnode, purely_numeric_state_variables_moved + analytic_state_variables_moved) %}
{%- set ast = ASTNodeFactory.create_ast_function_call("integrate_odes", args) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ namespace {{names_namespace}}
}


{% if uses_numeric_solver %}
{% if uses_numeric_solver %}

{%- for s in utils.create_integrate_odes_combinations(astnode) %}
{%- for s in utils.create_integrate_odes_combinations(astnode) %}
/**
* Function computing right-hand side of ODE for GSL solver.
* @note Must be declared here so we can befriend it in class.
Expand All @@ -136,9 +136,9 @@ namespace {{names_namespace}}
* Integrate the variables: {{ s }}
**/
extern "C" inline int {{neuronName}}_dynamics{% if s | length > 0 %}_{{ s }}{% endif %}( double, const double ode_state[], double f[], void* pnode );
{%- endfor %}
{%- endfor %}

{%- if paired_synapse is defined %}
{%- if paired_synapse is defined and (purely_numeric_state_variables_moved + analytic_state_variables_moved) | length > 0 %}
{# for neuron-synapse co-generation: separate integrator for the emulated/dummy integrate_odes() below in NeuronClass.jinja2 #}
{%- set args = utils.resolve_variables_to_expressions(astnode, purely_numeric_state_variables_moved + analytic_state_variables_moved) %}
{%- set ast = ASTNodeFactory.create_ast_function_call("integrate_odes", args) %}
Expand Down
6 changes: 3 additions & 3 deletions pynestml/utils/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,10 @@ def _visit(self, node):
model.integrate_odes_combinations = visitor.all_args

# always ensure code is generated for an integrate_odes() call without any arguments. This is needed, for example, for gap junctions support
if not [] in model.integrate_odes_combinations:
model.integrate_odes_combinations.append([])
if not "" in model.integrate_odes_combinations:
model.integrate_odes_combinations.append("")

return visitor.all_args
return model.integrate_odes_combinations

@classmethod
def get_all_integrate_odes_calls_unique(cls, model: ASTModel) -> None:
Expand Down
50 changes: 50 additions & 0 deletions tests/nest_tests/test_co_generation_static_synapse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
#
# test_co_generation_static_synapse.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

import os

from pynestml.codegeneration.nest_tools import NESTTools
from pynestml.frontend.pynestml_frontend import generate_nest_target

try:
import matplotlib
matplotlib.use("Agg")
import matplotlib.ticker
import matplotlib.pyplot as plt
TEST_PLOTS = True
except Exception:
TEST_PLOTS = False


def test_co_generation_static_synapse():
r"""This tests the case that there is a complex neuron model and a simple synapse model that does not transfer any variables."""

files = [os.path.join("models", "neurons", "hill_tononi_neuron.nestml"),
os.path.join("models", "synapses", "static_synapse.nestml")]
input_path = [os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.join(
os.pardir, os.pardir, s))) for s in files]
generate_nest_target(input_path=input_path,
logging_level="INFO",
suffix="_nestml",
codegen_opts={"neuron_synapse_pairs": [{"neuron": "hill_tononi_neuron",
"synapse": "static_synapse"}],
"delay_variable": {"static_synapse": "d"},
"weight_variable": {"static_synapse": "w"}})

0 comments on commit ac1bf14

Please sign in to comment.