Skip to content

Commit

Permalink
add support for forward Euler integrator
Browse files Browse the repository at this point in the history
  • Loading branch information
C.A.P. Linssen committed Aug 9, 2023
1 parent cd1dc90 commit fe04249
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pynestml/codegeneration/python_standalone_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class PythonStandaloneCodeGenerator(NESTCodeGenerator):
},
"module_templates": ["simulator.py.jinja2", "test_python_standalone_module.py.jinja2", "neuron.py.jinja2", "spike_generator.py.jinja2", "utils.py.jinja2"]
},
"solver": "analytic"
"solver": "analytic",
"numeric_solver": "rk45"
}

def __init__(self, options: Optional[Mapping[str, Any]] = None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ for (size_t i = 0; i < State_::STATE_VEC_SIZE; ++i)
}
{%- else %}
{{ raise('Unknown numeric ODE solver requested.') }}
{%- endif %}
{%- endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Generates a series of statements which perform one integration step of all ODEs defined the neuron.
#}
{%- if tracing %}# generated by {{self._TemplateReference__context.name}}{% endif %}
{%- if numeric_solver == "rk45" %}
res = scipy.integrate.solve_ivp(Neuron_{{neuronName}}.dynamics, t_span=(origin, origin + timestep), y0=self.S_.ode_state, method="RK45", args=(self, ))
np.testing.assert_almost_equal(res.t[-1], origin + timestep) # sanity check on the final timestep reached by the solver
self.S_.ode_state = res.y[:, -1]
{%- else %}
{{ raise('Unsupported numerical solver') }}
{%- endif %}
3 changes: 2 additions & 1 deletion pynestml/utils/ast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,8 @@ def replace_var(_expr, replace_var_name: str, replace_with_var_name: str):
for decl in equation_block.get_declarations():
if isinstance(decl, ASTInlineExpression) \
and isinstance(decl.get_expression(), ASTSimpleExpression) \
and '__X__' in str(decl.get_expression()):
and '__X__' in str(decl.get_expression()) \
and decl.get_expression().get_variable():
replace_with_var_name = decl.get_expression().get_variable().get_name()
neuron.accept(ASTHigherOrderVisitor(lambda x: replace_var(
x, decl.get_variable_name(), replace_with_var_name)))
Expand Down

0 comments on commit fe04249

Please sign in to comment.