Skip to content

Commit

Permalink
Merge pull request #281 from DimitriPlotnikov/master
Browse files Browse the repository at this point in the history
Prepare new release
  • Loading branch information
Plotnikov authored Oct 23, 2016
2 parents b7594f4 + 33863b3 commit 6161f65
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 239 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>nestml</groupId>
<artifactId>nestml-core</artifactId>
<version>1.2.2-SNAPSHOT</version>
<version>1.2.3</version>

<properties>
<!-- .. Libraries ..................................................... -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/nest/frontend/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -67,14 +68,24 @@ void addArtifactInfo(final String artifactName, final String message, final Leve
}

void printReports(final PrintStream info, final PrintStream err) {
Optional<Map.Entry<String, String>> 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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/nest/spl/_cocos/IllegalExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/nest/codegeneration/NestCodeGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testInfrastructure() {
}

@Test
public void testModelsFolder() {
public void testModelsgFolder() {
final String[] args = new String[] {
"models",
"--target", outputPath.toString()};
Expand All @@ -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);
Expand Down
187 changes: 95 additions & 92 deletions src/test/resources/codegeneration/aeif_cond_alpha.nestml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 6161f65

Please sign in to comment.