Skip to content

Consider refactoring SymPy solver code in NMODL #3414

@JCGoran

Description

@JCGoran

Overview of the feature

We use SymPy in NMODL to solve ODEs, as well as linear and nonlinear systems analytically, or, if the system is not analytically solvable, using Newton iteration. Since NMODL may use some keywords from SymPy or Python, the procedure basically looks like this:

  • rename all variables and function calls which collide with Python/SymPy to something like _sympy_[name]_var
  • use SymPy to parse the fixed expression and derive a result
  • put back the original variable names and function calls
  • generate C code from the resulting expression

This is currently done by calling functions like search_and_replace_protected_identifiers_from_sympy, search_and_replace_protected_identifiers_to_sympy, but it would be easier to use a class or a context manager since for any new functionality we would not need to worry about whether or not the identifiers have been correctly replaced (or replaced twice).

Foreseeable Impact

  • Area(s) of change: NMODL Python module ode, NMODL C++ module wrapper.cpp
  • Possible issues: none

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions