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

Use t in Shape function twice. #412

Closed
vogdb opened this issue Mar 13, 2018 · 3 comments
Closed

Use t in Shape function twice. #412

vogdb opened this issue Mar 13, 2018 · 3 comments

Comments

@vogdb
Copy link
Contributor

vogdb commented Mar 13, 2018

Hi! I'm trying to implement a dual exponential waveform of synaptic conductance that looks like:

some_constant * (exp(-t/tau1) - exp(-t/tau2))

I'm doing this in the equations block.

shape I_shape_in = pA * tau_syn_in * (exp(-1/tau_syn_in_fall*t) - exp(-1/tau_syn_in_rise*t))
function I_syn pA = convolve(I_shape_in, in_spikes) + convolve(I_shape_ex, ex_spikes) + I_e + currents

receive an error:

/home/vogdb/workspace/xxx/neuron-intfire-nestml/build/int_fire4.cpp: In member function ‘virtual void int_fire4::update(const nest::Time&, long int, long int)’:
/home/vogdb/workspace/xxx/neuron-intfire-nestml/build/int_fire4.cpp:272:7: error: ‘__t’ was not declared in this scope
       __t = 0;
       ^

The current solution I use is to split this declaration into two shape functions. Is it correct?

    shape I_shape_in_rise = pA * tau_syn_in * -exp(-1/tau_syn_in_rise*t)
    shape I_shape_in_fall = pA * tau_syn_in * exp(-1/tau_syn_in_fall*t)
    function I_syn pA = convolve(I_shape_in_rise, in_spikes) + convolve(I_shape_in_fall, in_spikes) + convolve(I_shape_ex, ex_spikes) + I_e + currents

Full model description:

neuron int_fire4:

  state:
    r integer # counts number of tick during the refractory period
  end

  initial_values:
    V_m mV = 0mV
  end

  equations:
    shape I_shape_ex = pA * exp(-1/tau_syn_ex*t)
    shape I_shape_in = pA * tau_syn_in * (exp(-1/tau_syn_in_fall*t) - exp(-1/tau_syn_in_rise*t))
    function I_syn pA = convolve(I_shape_in, in_spikes) + convolve(I_shape_ex, ex_spikes) + I_e + currents
    V_m' = -1/tau_m * V_m + 1/1pF * I_syn
  end

  parameters:
    tau_m            ms = 10ms # Membrane time constant.
    tau_syn_in_rise  ms = 2ms  # Time constant of inhibitory synaptic current. Rise phase.
    tau_syn_in_fall  ms = 2ms  # Time constant of inhibitory synaptic current. Fall phase.
    tau_syn_ex       ms = 2ms  # Time constant of excitatory synaptic current.
    t_ref            ms = 2ms  # Duration of refractory period
    V_reset          mV = 0mV  # reset value of the membrane potential
    V_threshold      mV = 1mV  # Threshold value of V_m for spike
    I_e              pA = 0pA  # External current.
  end

  internals:
    RefractoryCounts integer = steps(t_ref) # refractory time in steps
    tau_syn_in real = tau_syn_in_rise * tau_syn_in_fall / (tau_syn_in_fall - tau_syn_in_rise)
  end

  input:
    ex_spikes pA <- excitatory spike
    in_spikes pA <- inhibitory spike
    currents    <- current
  end

  output: spike

  update:
    if r == 0: # neuron not refractory
      integrate_odes()
    else: # neuron is absolute refractory
      r = r - 1
    end

    if V_m >= V_threshold: # threshold crossing
      r = RefractoryCounts
      V_m = V_reset
      emit_spike()
    end

  end

end
@kperun
Copy link
Contributor

kperun commented Apr 5, 2018

@vogdb I think you are using the Java implementation of the toolchain? I have tried to use your model with PyNestML and I get weird errors which seem to be related to Sympy (?). @PTraeder and @DimitriPlotnikov here the log:
kperun@yogapad:~/Dropbox/PyNestMlAtGithub$ python2 PyNestML.py -path /home/kperun/Dropbox/mod.nestml -dev [4,int_fire4, ERROR, [13:28;13:28]]: Variable 'tau_syn_in' used before declaration! Traceback (most recent call last): File "PyNestML.py", line 29, in <module> main(sys.argv[1:]) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/frontend/PyNestMLFrontend.py", line 69, in main nest_generator.analyseAndGenerateNeurons(neurons) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/codegeneration/NestCodeGenerator.py", line 127, in analyseAndGenerateNeurons self.analyseAndGenerateNeuron(neuron) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/codegeneration/NestCodeGenerator.py", line 111, in analyseAndGenerateNeuron workingVersion = self.solveOdesAndShapes(workingVersion) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/codegeneration/NestCodeGenerator.py", line 265, in solveOdesAndShapes workingCopy = EquationsBlockProcessor.solveOdeWithShapes(_neuron) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/solver/EquationsBlockProcessor.py", line 54, in solveOdeWithShapes output = SymPySolver.solveOdeWithShapes(deep_copy.get_equations_blocks()) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/solver/SymPySolver.py", line 42, in solveOdeWithShapes output = OdeAnalyzer.compute_solution(input_json.toJSON()) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/solver/OdeAnalyzer.py", line 194, in compute_solution shape_functions) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/solver/OdeAnalyzer.py", line 207, in compute_exact_solution function_definitions) File "/home/kperun/Dropbox/PyNestMlAtGithub/pynestml/solver/prop_matrix.py", line 90, in ode_to_prop_matrices prop_matrices.append(simplify(exp(A * h))) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/core/cache.py", line 93, in wrapper retval = cfunc(*args, **kwargs) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/core/compatibility.py", line 794, in wrapper return user_function(*args, **kwds) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/core/function.py", line 427, in __new__ result = super(Function, cls).__new__(cls, *args, **options) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/core/cache.py", line 93, in wrapper retval = cfunc(*args, **kwargs) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/core/compatibility.py", line 794, in wrapper return user_function(*args, **kwds) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/core/function.py", line 250, in __new__ evaluated = cls.eval(*args) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/functions/elementary/exponential.py", line 302, in eval return arg.exp() File "/home/kperun/.local/lib/python2.7/site-packages/sympy/matrices/matrices.py", line 2478, in exp ret = P * eJ * P.inv() File "/home/kperun/.local/lib/python2.7/site-packages/sympy/matrices/matrices.py", line 2781, in inv return self._eval_inverse(**kwargs) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/matrices/dense.py", line 260, in _eval_inverse rv = M.inverse_GE(iszerofunc=iszerofunc) File "/home/kperun/.local/lib/python2.7/site-packages/sympy/matrices/matrices.py", line 2696, in inverse_GE raise ValueError("Matrix det == 0; not invertible.") ValueError: Matrix det == 0; not invertible.
Do you have any ideas what could lead to this? Unfortunately I am not even remotely familiar with the ODE toolbox.
Moreover, why does this problem occur in PyNestML and not in Java?

@vogdb
Copy link
Contributor Author

vogdb commented Apr 5, 2018

@vogdb I think you are using the Java implementation of the toolchain?

Yep.

All other questions seem to be related to the contributors. I don't know answers to them :(

@clinssen
Copy link
Contributor

clinssen commented Nov 15, 2018

I cannot reproduce this issue and will assume it has been fixed in the mean time. If you still run into it, please let me know!

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

3 participants