From 27cfbbb6c7d5a5173a42e22c6e63020bbf3c0b3e Mon Sep 17 00:00:00 2001 From: DimitriPlotnikov Date: Sun, 23 Oct 2016 17:19:25 +0200 Subject: [PATCH 1/2] Improve frontend's output. Add more tutorial models. MC. --- .../frontend/CliConfigurationExecutor.java | 4 +- src/main/java/org/nest/frontend/Reporter.java | 13 +- .../nest/spl/_cocos/IllegalExpression.java | 6 +- .../codegeneration/NestCodeGeneratorTest.java | 10 + .../NestmlFrontendIntegrationTest.java | 4 +- .../codegeneration/aeif_cond_alpha.nestml | 187 +++++++-------- .../codegeneration/neuron_with_setter.nestml | 137 +++++++++++ .../codegeneration/terub_neuron_stn.nestml | 217 +++++++----------- src/test/resources/tutorial/41_iaf.nestml | 37 +++ .../resources/tutorial/42_quadratic.nestml | 37 +++ 10 files changed, 414 insertions(+), 238 deletions(-) create mode 100644 src/test/resources/codegeneration/neuron_with_setter.nestml create mode 100644 src/test/resources/tutorial/41_iaf.nestml create mode 100644 src/test/resources/tutorial/42_quadratic.nestml diff --git a/src/main/java/org/nest/frontend/CliConfigurationExecutor.java b/src/main/java/org/nest/frontend/CliConfigurationExecutor.java index 369d128dd..4619942c2 100644 --- a/src/main/java/org/nest/frontend/CliConfigurationExecutor.java +++ b/src/main/java/org/nest/frontend/CliConfigurationExecutor.java @@ -126,7 +126,9 @@ private void processNestmlModels( generateModuleCode(modelRoots, config, generator); } else { - Log.error(LOG_NAME + ": Models contain semantic errors, therefore, no codegeneration is possible"); + final String msg = " Models contain semantic error(s), therefore, no codegeneration is possible"; + Log.error(LOG_NAME + ":" + msg); + reporter.addSystemInfo(msg, Reporter.Level.ERROR); } } diff --git a/src/main/java/org/nest/frontend/Reporter.java b/src/main/java/org/nest/frontend/Reporter.java index ac9d9b359..e40c1bfe4 100644 --- a/src/main/java/org/nest/frontend/Reporter.java +++ b/src/main/java/org/nest/frontend/Reporter.java @@ -28,6 +28,7 @@ import java.io.PrintStream; import java.util.List; import java.util.Map; +import java.util.Optional; /** * Collects all finding and statuses for artifacts and containing neurons. @@ -67,14 +68,24 @@ void addArtifactInfo(final String artifactName, final String message, final Leve } void printReports(final PrintStream info, final PrintStream err) { + Optional> error = artifactReports. + entries() + .stream() + .filter(message -> message.getValue().startsWith(Level.ERROR.toString())) + .findAny(); info.println("----------------------------------------------------------"); - info.println("-----------------Environment summary----------------------"); + info.println("-----------------Execution summary------------------------"); systemReports.forEach(report -> printEntry(report, info, err)); + error.ifPresent(errorMessage -> err.println( + errorMessage.getKey() + " contains some errors: " + errorMessage.getValue() + ". Code generation was canceled.")); info.println("-----------------Artifact summary-------------------------"); artifactReports.entries().forEach(entry -> printEntry(entry, info, err)); info.println("-----------------Statistics ------------------------------"); info.println("Overall " + artifactReports.keySet().size() + " NESTML artifact(s) found and processed"); + info.println("----------------------------------------------------------"); + error.ifPresent(errorMessage -> err.println( + errorMessage.getKey() + " contains some errors: " + errorMessage.getValue() + ". Code generation was canceled.")); } private void printEntry(final String message, final PrintStream info, final PrintStream err) { diff --git a/src/main/java/org/nest/spl/_cocos/IllegalExpression.java b/src/main/java/org/nest/spl/_cocos/IllegalExpression.java index 86c43e493..03d6c407c 100644 --- a/src/main/java/org/nest/spl/_cocos/IllegalExpression.java +++ b/src/main/java/org/nest/spl/_cocos/IllegalExpression.java @@ -79,7 +79,7 @@ public void check(final ASTDeclaration node) { } else { final String errorDescription = initializerExpressionType.getError() + - "Problem with the expression: " + AstUtils.toString(node.getExpr().get()); + ": Problem with the expression: " + AstUtils.toString(node.getExpr().get()); undefinedTypeError(node, errorDescription); } @@ -98,7 +98,7 @@ public void check(final ASTELIF_Clause node) { if (exprType.isError()) { final String errorDescription = exprType.getError() + - "Problem with the expression: " + AstUtils.toString(node.getExpr()); + ". Problem with the expression: " + AstUtils.toString(node.getExpr()); undefinedTypeError(node, errorDescription); } @@ -120,7 +120,7 @@ public void check(final ASTIF_Clause node) { if (exprType.isError()) { final String errorDescription = exprType.getError() + - "Problem with the expression: " + AstUtils.toString(node.getExpr()); + ". Problem with the expression: " + AstUtils.toString(node.getExpr()); undefinedTypeError(node, errorDescription); } diff --git a/src/test/java/org/nest/codegeneration/NestCodeGeneratorTest.java b/src/test/java/org/nest/codegeneration/NestCodeGeneratorTest.java index 5a3af1274..13ce7f0ff 100644 --- a/src/test/java/org/nest/codegeneration/NestCodeGeneratorTest.java +++ b/src/test/java/org/nest/codegeneration/NestCodeGeneratorTest.java @@ -27,6 +27,7 @@ public class NestCodeGeneratorTest extends GenerationBasedTest { private static final String PSC_MODEL_WITH_ODE = "models/iaf_psc_alpha.nestml"; private static final String PSC_MODEL_IMPERATIVE = "src/test/resources/codegeneration/imperative/iaf_psc_alpha_imperative.nestml"; private static final String PSC_MODEL_THREE_BUFFERS = "src/test/resources/codegeneration/iaf_psc_alpha_three_buffers.nestml"; + private static final String NEURON_WITH_SETTER = "src/test/resources/codegeneration/neuron_with_setter.nestml"; private static final String COND_MODEL_IMPLICIT = "models/iaf_cond_alpha_implicit.nestml"; private static final String COND_MODEL_WITH_ODE = "models/iaf_cond_alpha.nestml"; private static final String MODEL_PATH = "src/test/resources"; @@ -86,4 +87,13 @@ public void testPSCModelWithThreeBuffers() { generator.generateNESTModuleCode(newArrayList(root), MODULE_NAME, CODE_GEN_OUTPUT); } + @Test + public void testNeuronWithSetter() { + final ASTNESTMLCompilationUnit root = parseNESTMLModel(NEURON_WITH_SETTER, MODEL_PATH); + scopeCreator.runSymbolTableCreator(root); + final NestCodeGenerator generator = new NestCodeGenerator(scopeCreator, pscMock); + + generator.analyseAndGenerate(root, CODE_GEN_OUTPUT); + generator.generateNESTModuleCode(newArrayList(root), MODULE_NAME, CODE_GEN_OUTPUT); + } } diff --git a/src/test/java/org/nest/integration/NestmlFrontendIntegrationTest.java b/src/test/java/org/nest/integration/NestmlFrontendIntegrationTest.java index 15a15a9b9..f1abf3e1b 100644 --- a/src/test/java/org/nest/integration/NestmlFrontendIntegrationTest.java +++ b/src/test/java/org/nest/integration/NestmlFrontendIntegrationTest.java @@ -47,7 +47,7 @@ public void testInfrastructure() { } @Test - public void testModelsFolder() { + public void testModelsgFolder() { final String[] args = new String[] { "models", "--target", outputPath.toString()}; @@ -67,7 +67,7 @@ public void testTutorialModels() { @Test public void manually() { final String[] args = new String[] { - "models/terub_neuron_gpe.nestml", + "STNGPeGPi", "--target", outputPath.toString()}; new NestmlFrontend().start(args); diff --git a/src/test/resources/codegeneration/aeif_cond_alpha.nestml b/src/test/resources/codegeneration/aeif_cond_alpha.nestml index 7c710acee..39f2d5ebb 100644 --- a/src/test/resources/codegeneration/aeif_cond_alpha.nestml +++ b/src/test/resources/codegeneration/aeif_cond_alpha.nestml @@ -1,132 +1,135 @@ /* -Name: aeif_cond_alpha - Conductance based exponential integrate-and-fire neuron - model according to Brette and Gerstner (2005). +Name: iaf_psc_alpha - Leaky integrate-and-fire neuron model. Description: -aeif_cond_alpha is the adaptive exponential integrate and fire neuron according -to Brette and Gerstner (2005). -Synaptic conductances are modelled as alpha-functions. -This implementation uses the embedded 4th order Runge-Kutta-Fehlberg solver with -adaptive step size to integrate the differential equation. - -The membrane potential is given by the following differential equation: -C dV/dt= -g_L(V-E_L)+g_L*Delta_T*exp((V-V_T)/Delta_T)-g_e(t)(V-E_e) - -g_i(t)(V-E_i)-w +I_e - -and - -tau_w * dw/dt= a(V-E_L) -W - -Integration parameters - gsl_error_tol double - This parameter controls the admissible error of the - GSL integrator. Reduce it if NEST complains about - numerical instabilities. - -Author: Marc-Oliver Gewaltig + iaf_psc_alpha is an implementation of a leaky integrate-and-fire model + with alpha-function shaped synaptic currents. Thus, synaptic currents + and the resulting post-synaptic potentials have a finite rise time. + + The threshold crossing is followed by an absolute refractory period + during which the membrane potential is clamped to the resting potential. + + The linear subthresold dynamics is integrated by the Exact + Integration scheme [1]. The neuron dynamics is solved on the time + grid given by the computation step size. Incoming as well as emitted + spikes are forced to that grid. + + An additional state variable and the corresponding differential + equation represents a piecewise constant external current. + + The general framework for the consistent formulation of systems with + neuron like dynamics interacting by point events is described in + [1]. A flow chart can be found in [2]. + + Critical tests for the formulation of the neuron model are the + comparisons of simulation results for different computation step + sizes. sli/testsuite/nest contains a number of such tests. + + The iaf_psc_alpha is the standard model used to check the consistency + of the nest simulation kernel because it is at the same time complex + enough to exhibit non-trivial dynamics and simple enough compute + relevant measures analytically. + +Remarks: + + The present implementation uses individual variables for the + components of the state vector and the non-zero matrix elements of + the propagator. Because the propagator is a lower triangular matrix + no full matrix multiplication needs to be carried out and the + computation can be done "in place" i.e. no temporary state vector + object is required. + + The template support of recent C++ compilers enables a more succinct + formulation without loss of runtime performance already at minimal + optimization levels. A future version of iaf_psc_alpha will probably + address the problem of efficient usage of appropriate vector and + matrix objects. + +Remarks: + + If tau_m is very close to tau_syn_ex or tau_syn_in, the model + will numerically behave as if tau_m is equal to tau_syn_ex or + tau_syn_in, respectively, to avoid numerical instabilities. + For details, please see IAF_Neruons_Singularity.ipynb in + the NEST source code (docs/model_details). + +References: + [1] Rotter S & Diesmann M (1999) Exact simulation of time-invariant linear + systems with applications to neuronal modeling. Biologial Cybernetics + 81:381-402. + [2] Diesmann M, Gewaltig M-O, Rotter S, & Aertsen A (2001) State space + analysis of synchronous spiking in cortical neural networks. + Neurocomputing 38-40:565-571. + [3] Morrison A, Straube S, Plesser H E, & Diesmann M (2006) Exact subthreshold + integration with continuous spike times in discrete time neural network + simulations. Neural Computation, in press Sends: SpikeEvent Receives: SpikeEvent, CurrentEvent, DataLoggingRequest - -References: Brette R and Gerstner W (2005) Adaptive Exponential - Integrate-and-Fire Model as an Effective Description of Neuronal - Activity. J Neurophysiol 94:3637-3642 - -SeeAlso: iaf_cond_alpha, aeif_cond_exp +FirstVersion: September 1999 +Author: Diesmann, Gewaltig +SeeAlso: iaf_psc_delta, iaf_psc_exp, iaf_cond_exp */ -neuron aeif_cond_alpha_neuron: +neuron iaf_psc_alpha_neuron: state: - V_m mV = E_L # Membrane potential - w pA = 0 # Spike-adaptation current + V_abs mV + alias V_m mV = V_abs + E_L # Membrane potential. end - equations: - shape g_in = (e/tau_syn_in) * t * exp(-1/tau_syn_in*t) # Excitatory synaptic conductance in nS - shape g_ex = (e/tau_syn_ex) * t * exp(-1/tau_syn_ex*t) # Inhibitory synaptic conductance in nS - # Add aliases to simplify the equation definition of V_m - exp_arg real = (V_m-V_th)/delta_T - I_spike pA = delta_T*exp(exp_arg) - I_syn_exc pA = Cond_sum(g_ex, spikesExc) * ( V_m - E_ex ) - I_syn_inh pA = Cond_sum(g_in, spikesInh) * ( V_m - E_in ) - V_m' = ( -g_L * ( ( V_m - E_L ) - I_spike ) - I_syn_exc - I_syn_inh - w + I_e + I_stim ) / C_m + equations: + shape I_shape_in = (e/tau_syn_in) * t * exp(-1/tau_syn_in*t) + shape I_shape_ex = (e/tau_syn_ex) * t * exp(-1/tau_syn_ex*t) - w' = (a*(V_m - E_L) - w)/tau_w + V_abs' = -1/Tau * V_abs + 1/C_m * (I_sum(I_shape_in, in_spikes) + I_sum(I_shape_ex, ex_spikes) + I_e + currents) end parameter: - # membrane parameters - C_m pF = 281.0pF # Membrane Capacitance in pF - t_ref ms = 0.0ms # Refractory period in ms - V_reset mV = -60.0mV # Reset Potential in mV - g_L nS = 30.0nS # Leak Conductance in nS - E_L mV = -70.6mV # Leak reversal Potential (aka resting potential) in mV - I_e pA = 0pA # Constant Current in pA - - # spike adaptation parameters - a nS = 4nS # Subthreshold adaptation - b pA = 80.5pA # pike-triggered adaptation - delta_T mV = 2.0mV # Slope factor - tau_w ms = 144.0ms # Adaptation time constant - V_th mV = -50.4mV # Threshold Potential in mV - V_peak mV = 0mV # Spike detection threshold - - # synaptic parameters - E_ex mV = 0mV # Excitatory reversal Potential in mV - tau_syn_ex ms = 0.2ms # Synaptic Time Constant Excitatory Synapse in ms - E_in mV = -85.0mV # Inhibitory reversal Potential in mV - tau_syn_in ms = 2.0ms # Synaptic Time Constant for Inhibitory Synapse in ms - - # Input current injected by CurrentEvent. - # This variable is used to transport the current applied into the - # _dynamics function computing the derivative of the state vector. - I_stim pA = 0pA + C_m pF = 250pF # Capacity of the membrane + Tau ms = 10ms # Membrane time constant. + tau_syn_in ms = 2ms # Time constant of synaptic current. + tau_syn_ex ms = 2ms # Time constant of synaptic current. + t_ref ms = 2ms # Duration of refractory period in ms. + E_L mV = -70mV # Resting potential. + alias V_reset mV = -70mV - E_L # Reset potential of the membrane in mV. + alias Theta mV = -55mV - E_L # Spike threshold in mV. + I_e pA = 0pA # Constant external input current in pA. end internal: - # Impulse to add to DG_EXC on spike arrival to evoke unit-amplitude - # conductance excursion. - PSConInit_E real = 1.0 * e / tau_syn_ex - - # Impulse to add to DG_INH on spike arrival to evoke unit-amplitude - # conductance excursion. - PSConInit_I real = 1.0 * e / tau_syn_in - - # refractory time in steps - RefractoryCounts integer = steps(t_ref) - # counts number of tick during the refractory period - r integer + RefractoryCounts integer = steps(t_ref) # refractory time in steps + r integer # counts number of tick during the refractory period end input: - spikesInh <- inhibitory spike - spikesExc <- excitatory spike - currents <- current + ex_spikes <- excitatory spike + in_spikes <- inhibitory spike + currents <- current end output: spike update: - integrate(V_m) - - if r > 0: # refractory + if r == 0: # neuron not refractory + integrate(V_abs) + else: # neuron is absolute refractory r = r - 1 end - if r > 0: # not refractory - V_m = V_reset # clamp potential - elif V_m >= V_peak: + if V_abs >= Theta: # threshold crossing + # A supra-threshold membrane potential should never be observable. + # The reset at the time of threshold crossing enables accurate + # integration independent of the computation step size, see [2,3] for + # details. r = RefractoryCounts - V_m = V_reset # clamp potential - w += b + V_abs = V_reset emit_spike() end - # Update with initial values must be added after the model analysis - I_stim = currents.get_sum() end end diff --git a/src/test/resources/codegeneration/neuron_with_setter.nestml b/src/test/resources/codegeneration/neuron_with_setter.nestml new file mode 100644 index 000000000..b1bb88e36 --- /dev/null +++ b/src/test/resources/codegeneration/neuron_with_setter.nestml @@ -0,0 +1,137 @@ +/* +Name: iaf_psc_alpha - Leaky integrate-and-fire neuron model. + +Description: + + iaf_psc_alpha is an implementation of a leaky integrate-and-fire model + with alpha-function shaped synaptic currents. Thus, synaptic currents + and the resulting post-synaptic potentials have a finite rise time. + + The threshold crossing is followed by an absolute refractory period + during which the membrane potential is clamped to the resting potential. + + The linear subthresold dynamics is integrated by the Exact + Integration scheme [1]. The neuron dynamics is solved on the time + grid given by the computation step size. Incoming as well as emitted + spikes are forced to that grid. + + An additional state variable and the corresponding differential + equation represents a piecewise constant external current. + + The general framework for the consistent formulation of systems with + neuron like dynamics interacting by point events is described in + [1]. A flow chart can be found in [2]. + + Critical tests for the formulation of the neuron model are the + comparisons of simulation results for different computation step + sizes. sli/testsuite/nest contains a number of such tests. + + The iaf_psc_alpha is the standard model used to check the consistency + of the nest simulation kernel because it is at the same time complex + enough to exhibit non-trivial dynamics and simple enough compute + relevant measures analytically. + +Remarks: + + The present implementation uses individual variables for the + components of the state vector and the non-zero matrix elements of + the propagator. Because the propagator is a lower triangular matrix + no full matrix multiplication needs to be carried out and the + computation can be done "in place" i.e. no temporary state vector + object is required. + + The template support of recent C++ compilers enables a more succinct + formulation without loss of runtime performance already at minimal + optimization levels. A future version of iaf_psc_alpha will probably + address the problem of efficient usage of appropriate vector and + matrix objects. + +Remarks: + + If tau_m is very close to tau_syn_ex or tau_syn_in, the model + will numerically behave as if tau_m is equal to tau_syn_ex or + tau_syn_in, respectively, to avoid numerical instabilities. + For details, please see IAF_Neruons_Singularity.ipynb in + the NEST source code (docs/model_details). + +References: + [1] Rotter S & Diesmann M (1999) Exact simulation of time-invariant linear + systems with applications to neuronal modeling. Biologial Cybernetics + 81:381-402. + [2] Diesmann M, Gewaltig M-O, Rotter S, & Aertsen A (2001) State space + analysis of synchronous spiking in cortical neural networks. + Neurocomputing 38-40:565-571. + [3] Morrison A, Straube S, Plesser H E, & Diesmann M (2006) Exact subthreshold + integration with continuous spike times in discrete time neural network + simulations. Neural Computation, in press + +Sends: SpikeEvent + +Receives: SpikeEvent, CurrentEvent, DataLoggingRequest +FirstVersion: September 1999 +Author: Diesmann, Gewaltig +SeeAlso: iaf_psc_delta, iaf_psc_exp, iaf_cond_exp +*/ +neuron iaf_psc_alpha_neuron: + + state: + V_abs mV + alias V_m mV = V_abs + E_L # Membrane potential. + end + + function set_V_m(V_m mV): + V_abs = V_m + V_abs + end + + equations: + shape I_shape_in = (e/tau_syn_in) * t * exp(-1/tau_syn_in*t) + shape I_shape_ex = (e/tau_syn_ex) * t * exp(-1/tau_syn_ex*t) + + V_abs' = -1/Tau * V_abs + 1/C_m * (I_sum(I_shape_in, in_spikes) + I_sum(I_shape_ex, ex_spikes) + I_e + currents) + end + + parameter: + C_m pF = 250pF # Capacity of the membrane + Tau ms = 10ms # Membrane time constant. + tau_syn_in ms = 2ms # Time constant of synaptic current. + tau_syn_ex ms = 2ms # Time constant of synaptic current. + t_ref ms = 2ms # Duration of refractory period in ms. + E_L mV = -70mV # Resting potential. + alias V_reset mV = -70mV - E_L # Reset potential of the membrane in mV. + alias Theta mV = -55mV - E_L # Spike threshold in mV. + I_e pA = 0pA # Constant external input current in pA. + end + + internal: + RefractoryCounts integer = steps(t_ref) # refractory time in steps + r integer # counts number of tick during the refractory period + end + + input: + ex_spikes <- excitatory spike + in_spikes <- inhibitory spike + currents <- current + end + + output: spike + + update: + if r == 0: # neuron not refractory + integrate(V_abs) + else: # neuron is absolute refractory + r = r - 1 + end + + if V_abs >= Theta: # threshold crossing + # A supra-threshold membrane potential should never be observable. + # The reset at the time of threshold crossing enables accurate + # integration independent of the computation step size, see [2,3] for + # details. + r = RefractoryCounts + V_abs = V_reset + emit_spike() + end + + end + +end diff --git a/src/test/resources/codegeneration/terub_neuron_stn.nestml b/src/test/resources/codegeneration/terub_neuron_stn.nestml index 9a6a42843..b5054f6e4 100644 --- a/src/test/resources/codegeneration/terub_neuron_stn.nestml +++ b/src/test/resources/codegeneration/terub_neuron_stn.nestml @@ -1,168 +1,105 @@ /* -Name: terub_neuron_stn - Terman Rubin neuron model. +Name: hh_cond_exp_traub - Hodgin Huxley based model, Traub modified. Description: - terub_neuron_stn is an implementation of a spiking neuron using the Terman Rubin model - based on the Hodgkin-Huxley formalism. + hh_cond_exp_traub is an implementation of a modified Hodkin-Huxley model - (1) Post-syaptic currents - Incoming spike events induce a post-synaptic change of current modelled - by an alpha function. The alpha function is normalised such that an event of - weight 1.0 results in a peak current of 1 pA. + (1) Post-synaptic currents + Incoming spike events induce a post-synaptic change of conductance modeled + by an exponential function. The exponential function is normalized such that an + event of weight 1.0 results in a peak current of 1 nS. - - (2) Spike Detection - Spike detection is done by a combined threshold-and-local-maximum search: if there - is a local maximum above a certain threshold of the membrane potential, it is considered a spike. + (2) Spike Detection + Spike detection is done by a combined threshold-and-local-maximum search: if + there is a local maximum above a certain threshold of the membrane potential, + it is considered a spike. Problems/Todo: - - better spike detection - +Only the channel variables m,h,n are implemented. The original +contains variables called y,s,r,q and \chi. References: - Terman, D. and Rubin, J.E. and Yew, A.C. and Wilson, C.J. - Activity Patterns in a Model for the Subthalamopallidal Network - of the Basal Ganglia - The Journal of Neuroscience, 22(7), 2963-2976 (2002) - - Rubin, J.E. and Terman, D. - High Frequency Stimulation of the Subthalamic Nucleus Eliminates - Pathological Thalamic Rhythmicity in a Computational Model - Journal of Computational Neuroscience, 16, 211-235 (2004) +Traub, R.D. and Miles, R. (1991) Neuronal Networks of the Hippocampus. +Cambridge University Press, Cambridge UK. Sends: SpikeEvent Receives: SpikeEvent, CurrentEvent, DataLoggingRequest -Author: Martin Ebert +Author: Schrader + +SeeAlso: hh_psc_alpha */ -neuron terub_neuron_stn: +neuron hh_cond_exp_traub_implicit: state: V_m mV = E_L # Membrane potential - g_in pA = 0pA # Inhibitory synaptic conductance - g_ex pA = 0pA # Excitatory synaptic conductance + g_in nS = 0nS # Inhibitory synaptic conductance + g_ex nS = 0nS # Excitatory synaptic conductance + + # TODO: it should be possible, to define these variables in the internal block + alias alpha_n_init real = 0.032 * ( 15. - V_m ) / ( exp( ( 15. - V_m ) / 5. ) - 1. ) + alias beta_n_init real = 0.5 * exp( ( 10. - V_m ) / 40. ) + alias alpha_m_init real = 0.32 * ( 13. - V_m ) / ( exp( ( 13. - V_m ) / 4. ) - 1. ) + alias beta_m_init real = 0.28 * ( V_m - 40. ) / ( exp( ( V_m - 40. ) / 5. ) - 1. ) + alias alpha_h_init real = 0.128 * exp( ( 17. - V_m ) / 18. ) + alias beta_h_init real = 4. / ( 1. + exp( ( 40. - V_m ) / 5. ) ) - gate_h real # gating variable h - gate_n real # gating variable n - gate_r real # gating variable r - Ca_con real # gating variable r + Act_m real = alpha_m_init / ( alpha_m_init + beta_m_init ) + Act_h real = alpha_h_init / ( alpha_h_init + beta_h_init ) + Inact_n real = alpha_n_init / ( alpha_n_init + beta_n_init ) end equations: - #Parameters for Terman Rubin STN Neuron - - #time constants for slow gating variables - tau_n_0 ms = 1.0ms - tau_n_1 ms = 100.0ms - theta_n_tau mV = -80.0mV - sigma_n_tau mV = -26.0mV - - tau_h_0 ms = 1.0ms - tau_h_1 ms = 500.0ms - theta_h_tau mV = -57.0mV - sigma_h_tau mV = -3.0mV - - tau_r_0 ms = 7.1ms # Guo 7.1 Terman02 40.0 - tau_r_1 ms = 17.5ms - theta_r_tau mV = 68.0mV - sigma_r_tau mV = -2.2mV - - #steady state values for gating variables - theta_a mV = -63.0mV - sigma_a mV = 7.8mV - theta_h mV = -39.0mV - sigma_h mV = -3.1mV - theta_m mV = -30.0mV - sigma_m mV = 15.0mV - theta_n mV = -32.0mV - sigma_n mV = 8.0mV - theta_r mV = -67.0mV - sigma_r mV = -2.0mV - theta_s mV = -39.0mV - sigma_s mV = 8.0mV - - theta_b real = 0.25 # Guo 0.25 Terman02 0.4 - sigma_b real = 0.07 # Guo 0.07 Terman02 -0.1 - - #time evolvement of gating variables - phi_h real = 0.75 - phi_n real = 0.75 - phi_r real = 0.5 # Guo 0.5 Terman02 0.2 - - # Calcium concentration and afterhyperpolarization current - epsilon ms**-1 = 0.00005[ms**-1] # 1/ms Guo 0.00005 Terman02 0.0000375 - k_Ca real = 22.5 - k1 real = 15.0 - - I_ex_mod pA = -I_sum(g_ex,spikeExc)*V_m - I_in_mod pA = I_sum(g_in, spikeInh) * (V_m-E_gs) - - tau_n mV = tau_n_0 + tau_n_1 / (1. + exp(-(V_m-theta_n_tau +"BUG")/sigma_n_tau)) - tau_h mV = tau_h_0 + tau_h_1 / (1. + exp(-(V_m-theta_h_tau)/sigma_h_tau)) - tau_r mV = tau_r_0 + tau_r_1 / (1. + exp(-(V_m-theta_r_tau)/sigma_r_tau)) - - a_inf real = 1. / (1. +exp(-(V_m-theta_a)/sigma_a)) - h_inf real = 1. / (1. + exp(-(V_m-theta_h)/sigma_h)); - m_inf real = 1. / (1. + exp(-(V_m-theta_m)/sigma_m)) - n_inf real = 1. / (1. + exp(-(V_m-theta_n)/sigma_n)) - r_inf real = 1. / (1. + exp(-(V_m-theta_r)/sigma_r)) - s_inf real = 1. / (1. + exp(-(V_m-theta_s)/sigma_s)) - b_inf real = 1. / (1. + exp((gate_r-theta_b)/sigma_b)) - 1. / (1. + exp(-theta_b/sigma_b)) - - I_Na pA = g_Na * m_inf * m_inf * m_inf * gate_h * (V_m - E_Na) - I_K pA = g_K * gate_n * gate_n * gate_n * gate_n * (V_m - E_K ) - I_L pA = g_L * (V_m - E_L ) - I_T pA = g_T *a_inf*a_inf*a_inf*b_inf*b_inf* (V_m - E_Ca) - I_Ca pA = g_Ca * s_inf * s_inf * (V_m - E_Ca) - I_ahp pA = g_ahp * (Ca_con / (Ca_con + k1)) * (V_m - E_K ) - - # V dot -- synaptic input are currents, inhib current is negative - V_m' = ( -(I_Na + I_K + I_L + I_T + I_Ca + I_ahp) + I_stim + I_e + I_ex_mod + I_in_mod) / C_m - - #channel dynamics - gate_h' = phi_h *((h_inf-gate_h) / tau_h) # h-variable - gate_n' = phi_n *((n_inf-gate_n) / tau_n) # n-variable - gate_r' = phi_r *((r_inf-gate_r) / tau_r) # r-variable - - #Calcium concentration - Ca_con' = epsilon*(-I_Ca - I_T - k_Ca * Ca_con); - - # synapses: alpha functions - g_ex'' = -g_ex' / tau_syn_ex - g_ex' = g_ex' - ( g_ex / tau_syn_ex ) - - g_in'' = -g_in' / tau_syn_in - g_in' = g_in' - ( g_in / tau_syn_in ) + # Add aliases to simplify the equation definition of V_m + I_Na pA = g_Na * Act_m * Act_m * Act_m * Act_h * ( V_m - E_Na ) + I_K pA = g_K * Inact_n * Inact_n * Inact_n * Inact_n * ( V_m - E_K ) + I_L pA = g_L * ( V_m - E_L ) + I_syn_exc pA = Cond_sum(g_ex, spikeExc) * ( V_m - E_ex ) + I_syn_inh pA = Cond_sum(g_in, spikeInh) * ( V_m - E_in ) + + V_m' =( -I_Na - I_K - I_L - I_syn_exc - I_syn_inh + I_stim + I_e ) / C_m + + # equilibrium values for (in)activation variables + V_rel mV = V_m - V_T + alpha_n real = 0.032 * ( 15. - V_rel ) / ( exp( ( 15. - V_rel ) / 5. ) - 1. ) + beta_n real = 0.5 * exp( ( 10. - V_rel ) / 40. ) + alpha_m real = 0.32 * ( 13. - V_rel ) / ( exp( ( 13. - V_rel ) / 4. ) - 1. ) + beta_m real = 0.28 * ( V_rel - 40. ) / ( exp( ( V_rel - 40. ) / 5. ) - 1. ) + alpha_h real = 0.128 * exp( ( 17. - V_rel ) / 18. ) + beta_h real = 4. / ( 1. + exp( ( 40. - V_rel ) / 5. ) ) + + Act_m' = alpha_m - ( alpha_m + beta_m ) * Act_m + Act_h' = alpha_h - ( alpha_h + beta_h ) * Act_h + Inact_n' = alpha_n - ( alpha_n + beta_n ) * Inact_n + + # synapses: exponential conductance + g_ex' = -g_ex / tau_syn_ex + g_in' = -g_in / tau_syn_in end parameter: - E_L mV = -60mV # Resting membrane potential in mV. - g_L nS = 2.25nS # Leak conductance in nS. - C_m pF = 1.0 pF # Capacity of the membrane in pF. - E_Na mV = 55mV # Sodium reversal potential in mV. - g_Na nS = 37.5nS # Sodium peak conductance in nS. - E_K mV = -80.0mV# Potassium reversal potential in mV. - g_K nS = 45.0nS # Potassium peak conductance in nS. - E_Ca mV = 120mV # Calcium reversal potential in mV. - g_Ca nS = 140nS # Calcium peak conductance in nS. - g_T nS = 0.5nS # T-type Calcium channel peak conductance in nS. - g_ahp nS = 9nS # afterpolarization current peak conductance in nS. - tau_syn_ex ms = 1.0ms # Rise time of the excitatory synaptic alpha function in ms. - tau_syn_in ms = 0.08ms # Rise time of the inhibitory synaptic alpha function in ms. - I_e pA = 0pA # Constant external input current in pA. - E_gs mV = -85.0mV# reversal potential for inhibitory input (from GPe) - t_ref ms = 2ms # refractory time in ms - I_stim pA = 0pA + g_Na nS = 20000.0nS # Threshold Potential in mV + g_K nS = 6000.0nS # K Conductance + g_L nS = 10nS # Leak Conductance + C_m pF = 200.0pF # Membrane Capacitance in pF + E_Na mV = 50mV # Reversal potentials + E_K mV = -90.mV # Potassium reversal potential + E_L mV = -60.mV # Leak reversal Potential (aka resting potential) in mV + V_T mV = -63.0mV # Voltage offset that controls dynamics. For default + # parameters, V_T = -63mV results in a threshold around -50mV. + tau_syn_ex ms = 5.0ms # Synaptic Time Constant Excitatory Synapse in ms + tau_syn_in ms = 10.0ms # Synaptic Time Constant for Inhibitory Synapse in ms + I_e pA = 0pA # Constant Current in pA + E_ex mV = 0.0 mV # Excitatory synaptic reversal potential + E_in mV = -80.0mV # Inhibitory synaptic reversal potential + I_stim pA = 0pA # External input current end internal: - PSCurrInit_E real = 1.0 * e / tau_syn_ex - PSCurrInit_I real = 1.0 * e / tau_syn_in - refractory_counts integer = steps(t_ref) + RefractoryCounts integer = 20 r integer # counts number of tick during the refractory period end @@ -181,16 +118,18 @@ neuron terub_neuron_stn: # sending spikes: crossing 0 mV, pseudo-refractoriness and local maximum... if r > 0: r -= 1 - elif V_m > 0mV and U_old > V_m: - r = refractory_counts + elif V_m > V_T + 30mV and U_old > V_m: + r = RefractoryCounts emit_spike() end # set new input current I_stim = currents.get_sum() - g_ex' += spikeExc.get_sum() * PSCurrInit_E - g_in' += spikeInh.get_sum() * PSCurrInit_I + g_ex += spikeExc.get_sum() + g_in += spikeInh.get_sum() + + alpha_n_init = 12 end end diff --git a/src/test/resources/tutorial/41_iaf.nestml b/src/test/resources/tutorial/41_iaf.nestml new file mode 100644 index 000000000..22e625f4f --- /dev/null +++ b/src/test/resources/tutorial/41_iaf.nestml @@ -0,0 +1,37 @@ +/* + TODO +*/ +neuron IaF: + + state: + V_m mV = 0mV + end + + equations: + V_m' = I_syn + a - b*V_m + end + + parameter: + I_syn pA = 10pA + a real = -7.0 + b real = 0.1 + c mV = 0mV + V_th mV = 10mV + end + + input: + spikes <- spike + end + + output: spike + + update: + integrate(V_m) + if V_m > V_th: + V_m = c + emit_spike() + end + end + + +end \ No newline at end of file diff --git a/src/test/resources/tutorial/42_quadratic.nestml b/src/test/resources/tutorial/42_quadratic.nestml new file mode 100644 index 000000000..c6cc0b36c --- /dev/null +++ b/src/test/resources/tutorial/42_quadratic.nestml @@ -0,0 +1,37 @@ +/* + TODO +*/ +neuron quadratic_IaF: + + state: + V_m mV = 0mV + end + + equations: + V_m' = I_syn + a * (V_m - V_reset)*(V_m - V_th) + end + + parameter: + I_syn pA = 10pA + a real = 7.0 + V_reset mV = 10mV + V_peak mV = 20mV + V_th mV = 15mV + end + + input: + spikes <- spike + end + + output: spike + + update: + integrate(V_m) + if V_m > V_peak: + V_m = V_reset + emit_spike() + end + end + + +end \ No newline at end of file From 33863b3a59d8c91b91eb0bb76037bda1fa8b5a95 Mon Sep 17 00:00:00 2001 From: DimitriPlotnikov Date: Sun, 23 Oct 2016 17:47:38 +0200 Subject: [PATCH 2/2] Create release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8c80780c1..78607825b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ nestml nestml-core - 1.2.2-SNAPSHOT + 1.2.3