Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in using sine and cosine functions in kernel definition #1074

Open
Geenetto opened this issue Jul 3, 2024 · 2 comments
Open

Issue in using sine and cosine functions in kernel definition #1074

Geenetto opened this issue Jul 3, 2024 · 2 comments

Comments

@Geenetto
Copy link

Geenetto commented Jul 3, 2024

Hi!
I am using the latest version of the NESTML master branch, with the sine and cosine implementation.
I wrote two NESTML codes for stdp synapses, which present sine and cosine functions in the kernel function.
the synapses equations are the following:
kernel K = (1. / C) * exp((-t-t0)/tau) * sin(2*pi*((t-t0)/tau)) for sine stdp synapse

kernel K =exp(-abs(t)/tau) * cos(t/tau) * cos(t/tau) for the cosine stdp synapse

Also, for both of the kernel equations, I did the convolution with the presynaptic spike:
inline w_conv real = convolve(K, pre_spikes)

It happens that building the models gives me two different results:
-the code execution just keeps running indefinetly without generating anything
-only in the sine stdp gives me this error
File "~/Documents/workspace/bsb-nest/lib/python3.10/site-packages/odetoolbox/system_of_shapes.py", line 193, in generate_propagator_solver raise PropagatorGenerationException("The imaginary unit was found in the propagator matrix. This can happen if the dynamical system that was passed to ode-toolbox is unstable, i.e. one or more state variables will diverge to minus or positive infinity.") odetoolbox.system_of_shapes.PropagatorGenerationException: The imaginary unit was found in the propagator matrix. This can happen if the dynamical system that was passed to ode-toolbox is unstable, i.e. one or more state variables will diverge to minus or positive infinity.

Also, if I remove the sine or cosine functions from the kernel equations, or if I put only a constant in the functions' argument (i.e. sin(100)), the models build correctly

What can I do to solve this problem? Is it a syntax issue in the kernel equation or is something else?

@clinssen
Copy link
Contributor

clinssen commented Jul 4, 2024

Hi, thanks again for writing in! Sorry, I did not realise you wanted to use sin() and cos() in a kernel inside a synapse. This runs into the following issue: for computational efficiency reasons, NEST Simulator only updates the synapse state when a spike is processed, rather than at every simulation timestep. This means that by default, no numeric solver (like forward Euler or Runge-Kutta) is supported for numerics in the synapse; only "propagator" solvers are supported. (This is a limitation of NEST and not NESTML per se.)

There are several ways to work around this issue:

  1. if you can derive a propagator by algebraic means, you can program this directly into the update block of the synapse model.
  2. a workaround is to write your own little forward Euler integrator inside the update block, which steps in small constant timestep between the spike times (it's like an integration loop inside an integration loop). I have attached an example that implements this: forward_euler_in_synapse.tar.gz
  3. we could try to add proper GSL solver support to synapses. However, note that memory consumption and compute time could become very large for larger networks.

@Geenetto
Copy link
Author

Geenetto commented Jul 4, 2024

Thank you very much. I'll try the first and second solution that you proposed and I'll let you know if everything goes well.

Thanks again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants