Skip to content

Commit

Permalink
postsynaptic variable integration fix (#1089)
Browse files Browse the repository at this point in the history
Co-authored-by: C.A.P. Linssen <[email protected]>
  • Loading branch information
clinssen and C.A.P. Linssen authored Aug 15, 2024
1 parent 4a89164 commit 346fcbe
Showing 1 changed file with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,10 @@ void
assert(history_.back().t_ == last_spike_);

{%- for var in purely_numeric_state_variables_moved|sort %}
{{ printer.print(utils.get_state_variable_by_name(astnode, var)) }} = history_.back().{{var}}_;
{{ printer.print(utils.get_state_variable_by_name(astnode, var)) }} = history_.back().{{ var }}_;
{%- endfor %}
{%- for var in analytic_state_variables_moved|sort %}
{{ printer.print(utils.get_state_variable_by_name(astnode, var)) }} = history_.back().{{var}}_;
{{ printer.print(utils.get_state_variable_by_name(astnode, var)) }} = history_.back().{{ var }}_;
{%- endfor %}
}
else
Expand All @@ -1140,6 +1140,7 @@ void
{%- endfor %}
}

{% if paired_synapse is defined and (purely_numeric_state_variables_moved + analytic_state_variables_moved) | length > 0 %}
/**
* update state variables transferred from synapse from `last_spike_` to `t_sp_ms`
*
Expand All @@ -1152,16 +1153,17 @@ void
{
recompute_internal_variables(true);

{%- filter indent(6, True) -%}
{# emulate a call to ``integrate_odes(purely_numeric_state_variables_moved + analytic_state_variables_moved)`` #}
{%- set args = utils.resolve_variables_to_expressions(astnode, purely_numeric_state_variables_moved + analytic_state_variables_moved) %}
{%- set ast = ASTNodeFactory.create_ast_function_call("integrate_odes", args) %}
{%- include "directives_cpp/PredefinedFunction_integrate_odes.jinja2" %}
{%- endfilter %}
{%- filter indent(6, True) -%}
{# emulate a call to ``integrate_odes(purely_numeric_state_variables_moved + analytic_state_variables_moved)`` #}
{%- set args = utils.resolve_variables_to_expressions(astnode, purely_numeric_state_variables_moved + analytic_state_variables_moved) %}
{%- set ast = ASTNodeFactory.create_ast_function_call("integrate_odes", args) %}
{%- include "directives_cpp/PredefinedFunction_integrate_odes.jinja2" %}
{%- endfilter %}

V_.__h = old___h;
recompute_internal_variables(true);
}
{%- endif %}

/**
* print extra on-emit statements transferred from synapse
Expand All @@ -1188,10 +1190,10 @@ void
last_spike_ = t_sp_ms;
history_.push_back( histentry__{{ neuronName }}( last_spike_
{%- for var in purely_numeric_state_variables_moved|sort %}
, get_{{var}}()
, get_{{ var }}()
{%- endfor %}
{%- for var in analytic_state_variables_moved|sort %}
, get_{{var}}()
, get_{{ var }}()
{%- endfor %}
, 0
) );
Expand Down Expand Up @@ -1223,17 +1225,17 @@ void
{%- endif %}

double
{{ neuronName }}::get_{{var}}( double t, const bool before_increment )
{{ neuronName }}::get_{{ var }}( double t, const bool before_increment )
{
#ifdef DEBUG
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{var}}: getting value at t = " << t << std::endl;
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{ var }}: getting value at t = " << t << std::endl;
#endif

// case when the neuron has not yet spiked
if ( history_.empty() )
{
#ifdef DEBUG
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{var}}: \thistory empty, returning initial value = " << {{var}}__iv << std::endl;
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{ var }}: \thistory empty, returning initial value = " << {{ var }}__iv << std::endl;
#endif
// return initial value
return {{ var }}__iv;
Expand All @@ -1251,7 +1253,7 @@ double
if ( t - history_[ i ].t_ >= eps )
{
#ifdef DEBUG
std::cout<<"{{ neuronName }}::get_{{var}}: \tspike occurred at history[i].t_ = " << history_[i].t_ << std::endl;
std::cout << "{{ neuronName }}::get_{{ var }}: \tspike occurred at history[i].t_ = " << history_[i].t_ << std::endl;
#endif

{%- for var_ in purely_numeric_state_variables_moved %}
Expand All @@ -1261,6 +1263,7 @@ double
{{ printer.print(utils.get_variable_by_name(astnode, var_)) }} = history_[ i ].{{var_}}_;
{%- endfor %}

{% if paired_synapse is defined and (purely_numeric_state_variables_moved + analytic_state_variables_moved) | length > 0 %}
/**
* update state variables transferred from synapse from `history[i].t_` to `t`
*
Expand All @@ -1274,17 +1277,18 @@ double
assert(V_.__h > 0);
recompute_internal_variables(true);

{# emulate a call to ``integrate_odes(purely_numeric_state_variables_moved + analytic_state_variables_moved)`` #}
{%- set args = utils.resolve_variables_to_expressions(astnode, purely_numeric_state_variables_moved + analytic_state_variables_moved) %}
{%- set ast = ASTNodeFactory.create_ast_function_call("integrate_odes", args) %}
{%- include "directives_cpp/PredefinedFunction_integrate_odes.jinja2" %}
{# emulate a call to ``integrate_odes(purely_numeric_state_variables_moved + analytic_state_variables_moved)`` #}
{%- set args = utils.resolve_variables_to_expressions(astnode, purely_numeric_state_variables_moved + analytic_state_variables_moved) %}
{%- set ast = ASTNodeFactory.create_ast_function_call("integrate_odes", args) %}
{%- include "directives_cpp/PredefinedFunction_integrate_odes.jinja2" %}

V_.__h = old___h;
recompute_internal_variables(true);
}
{%- endif %}

#ifdef DEBUG
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{var}}: \treturning " << {{ printer.print(utils.get_variable_by_name(astnode, var)) }} << std::endl;
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{ var }}: \treturning " << {{ printer.print(utils.get_variable_by_name(astnode, var)) }} << std::endl;
#endif
return {{ printer.print(utils.get_variable_by_name(astnode, var)) }}; // type: {{declarations.print_variable_type(variable_symbol)}}
}
Expand All @@ -1302,15 +1306,15 @@ double
{%- endfor %}

#ifdef DEBUG
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{var}}: \ttrace requested at exact time of history entry 0, returning " << {{ printer.print(utils.get_variable_by_name(astnode, variable_symbol.get_symbol_name())) }} << std::endl;
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{ var }}: \ttrace requested at exact time of history entry 0, returning " << {{ printer.print(utils.get_variable_by_name(astnode, variable_symbol.get_symbol_name())) }} << std::endl;
#endif
return {{ printer.print(utils.get_variable_by_name(astnode, variable_symbol.get_symbol_name())) }};
}

// this case occurs when the trace was requested at a time before the first spike in the history
// return initial value propagated in time
#ifdef DEBUG
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{var}}: \tfall-through, returning initial value = " << {{var}}__iv << std::endl;
std::cout << "[neuron " << this << "] {{ neuronName }}::get_{{ var }}: \tfall-through, returning initial value = " << {{ var }}__iv << std::endl;
#endif

if (t == 0.)
Expand Down

0 comments on commit 346fcbe

Please sign in to comment.