Skip to content

Commit

Permalink
improve handling of NEST synaptic delay parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Sep 13, 2023
1 parent 5ccfdfd commit 46670cb
Show file tree
Hide file tree
Showing 30 changed files with 362 additions and 228 deletions.
5 changes: 4 additions & 1 deletion doc/nestml_language/synapses_in_nestml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,13 @@ The synapse is allowed to contain an ``update`` block. Statements in the ``updat
Dendritic delay
~~~~~~~~~~~~~~~

In NEST, all synapses are expected to specify a nonzero dendritic delay, that is, the delay between arrival of a spike at the dendritic spine and the time at which its effects are felt at the soma (or conversely, the delay between a somatic action potential and the arrival at the dendritic spine due to dendritic backpropagation). To indicate that a given parameter is specifying this NEST-specific delay value, use an annotation:
In NEST, all synapses are expected to specify a nonzero dendritic delay, that is, the delay between arrival of a spike at the dendritic spine and the time at which its effects are felt at the soma (or conversely, the delay between a somatic action potential and the arrival at the dendritic spine due to dendritic backpropagation). As delays and weights are hard-wired into the NEST C++ base classes for the NESTML synapse classes, special annotations must be made in the NESTML model to indicate which state variables or parameters correspond to weight and delay. To indicate the correspondence, use an annotation:

.. code:: nestml
state:
w ms = 1 ms @nest::weight
parameters:
dend_delay ms = 1 ms @nest::delay
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/neuromodulated_stdp.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ References
"""
synapse neuromodulated_stdp:
state:
w real = 1.
w real = 1. @nest::weight # Synaptic weight
n real = 0. # Neuromodulator concentration
c real = 0. # Eligibility trace
pre_tr real = 0.
post_tr real = 0.

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay
tau_tr_pre ms = 20 ms # STDP time constant for weight changes caused by pre-before-post spike pairings.
tau_tr_post ms = 20 ms # STDP time constant for weight changes caused by post-before-pre spike pairings.
tau_c ms = 1000 ms # Time constant of eligibility trace
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/noisy_synapse.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Each presynaptic spike is passed to the postsynaptic partner with a weight sampl
"""
synapse noisy_synapse:
parameters:
w real = 1 # Synaptic weight
d ms = 1 ms @nest::delay # Synaptic transmission delay
w real = 1. @nest::weight # Synaptic weight
d ms = 1 ms @nest::delay # Synaptic transmission delay
A_noise real = .4

input:
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/stdp_nn_pre_centered.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ References
"""
synapse stdp_nn_pre_centered:
state:
w real = 1 # Synaptic weight
w real = 1. @nest::weight # Synaptic weight
pre_trace real = 0.
post_trace real = 0.

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay
lambda real = .01
tau_tr_pre ms = 20 ms
tau_tr_post ms = 20 ms
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/stdp_nn_restr_symm.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ References
"""
synapse stdp_nn_restr_symm:
state:
w real = 1. # Synaptic weight
w real = 1. @nest::weight # Synaptic weight
pre_trace real = 0.
post_trace real = 0.
pre_handled boolean = True

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay
lambda real = .01
tau_tr_pre ms = 20 ms
tau_tr_post ms = 20 ms
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/stdp_nn_symm.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ References
"""
synapse stdp_nn_symm:
state:
w real = 1. # Synaptic weight
w real = 1. @nest::weight # Synaptic weight
pre_trace real = 0.
post_trace real = 0.

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay
lambda real = .01
tau_tr_pre ms = 20 ms
tau_tr_post ms = 20 ms
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/stdp_triplet_naive.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ References
"""
synapse stdp_triplet:
state:
w nS = 1 nS # Synaptic weight
w real = 1. @nest::weight # Synaptic weight

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay

tau_plus ms = 16.8 ms # time constant for tr_r1
tau_x ms = 101 ms # time constant for tr_r2
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/third_factor_stdp_synapse.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ References
"""
synapse third_factor_stdp:
state:
w real = 1. # Synaptic weight
w real = 1. @nest::weight # Synaptic weight

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay
lambda real = .01
tau_tr_pre ms = 20 ms
tau_tr_post ms = 20 ms
Expand Down
4 changes: 2 additions & 2 deletions models/synapses/triplet_stdp_synapse.nestml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ References
"""
synapse stdp_triplet_nn:
state:
w nS = 1 nS # Synaptic weight
w real = 1. @nest::weight # Synaptic weight

tr_r1 real = 0.
tr_r2 real = 0.
tr_o1 real = 0.
tr_o2 real = 0.

parameters:
d ms = 1 ms @nest::delay # Synaptic transmission delay
d ms = 1 ms @nest::delay # Synaptic transmission delay

tau_plus ms = 16.8 ms # time constant for tr_r1
tau_x ms = 101 ms # time constant for tr_r2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# co_co_nest_delay_decorator_specified.py
# co_co_nest_decorators_specified.py
#
# This file is part of NEST.
#
Expand All @@ -25,9 +25,9 @@
from pynestml.utils.messages import Messages


class CoCoNESTDelayDecoratorSpecified(CoCo):
class CoCoNESTDecoratorsSpecified(CoCo):
"""
This CoCo ensures that there is precisely one parameter decorated as "@nest::delay".
This CoCo ensures that there is precisely one variable decorated as "@nest::delay" and one as "@nest::weight".
"""

@classmethod
Expand All @@ -36,14 +36,23 @@ def check_co_co(cls, node: ASTNeuronOrSynapse):
Checks if the coco applies for the node.
:param node:
"""
decorator_found = False
for variable in node.get_parameter_symbols() + node.get_internal_symbols():
delay_decorator_found = False
weight_decorator_found = False
for variable in node.get_state_symbols() + node.get_parameter_symbols() + node.get_internal_symbols():
if variable.get_namespace_decorator("nest") == "delay":
decorator_found = True
break
delay_decorator_found = True

if not decorator_found:
if variable.get_namespace_decorator("nest") == "weight":
weight_decorator_found = True

if not delay_decorator_found:
code, message = Messages.get_nest_delay_decorator_not_found()
Logger.log_message(node=node, error_position=None,
code=code, message=message,
log_level=LoggingLevel.ERROR)

if not weight_decorator_found:
code, message = Messages.get_nest_weight_decorator_not_found()
Logger.log_message(node=node, error_position=None,
code=code, message=message,
log_level=LoggingLevel.ERROR)
1 change: 1 addition & 0 deletions pynestml/codegeneration/nest_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def build(self) -> None:
n_cpu = len(os.sched_getaffinity(0)) # only available on Linux
except AttributeError:
n_cpu = os.cpu_count()
n_cpu = 8

nest_config_path = f"-Dwith-nest={os.path.join(nest_path, 'bin', 'nest-config')}"
cmake_cmd = ['cmake', nest_config_path, install_prefix, '.']
Expand Down
4 changes: 2 additions & 2 deletions pynestml/codegeneration/nest_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import odetoolbox
import pynestml

from pynestml.cocos.co_co_nest_delay_decorator_specified import CoCoNESTDelayDecoratorSpecified
from pynestml.cocos.co_co_nest_decorators_specified import CoCoNESTDecoratorsSpecified
from pynestml.codegeneration.code_generator import CodeGenerator
from pynestml.codegeneration.nest_assignments_helper import NestAssignmentsHelper
from pynestml.codegeneration.nest_code_generator_utils import NESTCodeGeneratorUtils
Expand Down Expand Up @@ -212,7 +212,7 @@ def set_options(self, options: Mapping[str, Any]) -> Mapping[str, Any]:

def run_nest_target_specific_cocos(self, neurons: Sequence[ASTNeuron], synapses: Sequence[ASTSynapse]):
for synapse in synapses:
CoCoNESTDelayDecoratorSpecified.check_co_co(synapse)
CoCoNESTDecoratorsSpecified.check_co_co(synapse)
if Logger.has_errors(synapse):
raise Exception("Error(s) occurred during code generation")

Expand Down
Loading

0 comments on commit 46670cb

Please sign in to comment.