nest / nestml

A domain specific language for neuron and synapse models in spiking neural network simulation
GNU General Public License v2.0
46 stars 45 forks source link

Ability to bind variables to shapes #373

Open jougs opened 7 years ago

jougs commented 7 years ago

In order to make shape declarations more generic and re-usable, I think it would be nice to support a new notation in addition to the existing notation. The new notation should allow to parametrize the shape with one or more variables. Here is an example of what this could look like:

equations:
  shape alpha<tau> = (e / tau) * t * exp( -t / tau)
  function I_syn_ex pA = convolve(alpha<tau_syn_ex>, spikes_ex)
  function I_syn_in pA = convolve(alpha<tau_syn_in>, spikes_in)
  V_m' = - (I_syn_ex + I_syn_in) / C_m

@ingablundell, @DimitriPlotnikov, @Silmathoron

Silmathoron commented 7 years ago

This indeed looks very handy!

DimitriPlotnikov commented 7 years ago

Hello, I advocate to reuse the existing syntactical style. The @jougs proposal misses for example the type of the tau. The syntax looks like C++ templates, but it is hardly related to it (and at least for me is confusing therefore). Thus, it is not possible to check the type correctness of the expression on the righthand side.

I composed several alternative which (imho) don't have these disadvantages. However you can still make your own proposals.

equations:
  # 1
  shape alpha(tau ms) = (e / tau) * t * exp( -t / tau)

  # 2
  function alpha(tau ms) = (e / tau) * t * exp( -t / tau)

  # 3
  shape alpha(tau ms):
    return (e / tau) * t * exp( -t / tau)
  end

  function I_syn_ex pA = convolve(alpha(tau_syn_ex), spikes_ex)
  function I_syn_in pA = convolve(alpha(tau_syn_in), spikes_in)
end

or as an external block:

# 4
shape alpha(tau ms):
    return (e / tau) * t * exp( -t / tau)
end

# 5
shape alpha(tau ms):
    (e / tau) * t * exp( -t / tau)
end

equations:
  function I_syn_ex pA = convolve(alpha(tau_syn_ex), spikes_ex)
  function I_syn_in pA = convolve(alpha(tau_syn_in), spikes_in)
end
jougs commented 7 years ago

@DimitriPlotnikov: I like your suggestion #1 most. Clear and simple.

Silmathoron commented 7 years ago

@DimitriPlotnikov I think the proposition from @jougs had the advantage that the < . > markers made it standout from the rest, so you can immediately notice that it is a shape with parameters.

It indeed reuses the same structure as c++ templates, but I don't really see how anyone might confuse the two given the context...

On the other hand, using the parentheses make it look as if alpha is in fact a function of tau here...

Between all suggestions, I would thus prefer the one from @jougs , then your #1, but especially not #2 which might confuse users a lot, I think.

Silmathoron commented 7 years ago

Alternatively, we could use other notations as [ . ] or { . } to avoid the ambiguity...

DimitriPlotnikov commented 7 years ago

We can use the one from @jougs, but then as:

shape alpha<tau ms> = (e / tau) * t * exp( -t / tau)