Skip to content

Commit

Permalink
NONLINEAR requires sympy --analytic. (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc authored Oct 14, 2024
1 parent 43dca3d commit 9c543ef
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/language/nmodl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1140,15 +1140,15 @@
type: Expression

- NonLinEquation:
brief: "TODO"
brief: "One equation in a system of equations that collectively make a NONLINEAR block."
nmodl: "~ "
members:
- lhs:
brief: "TODO"
brief: "Left-hand-side of the equation."
type: Expression
suffix: {value: " = "}
- rhs:
brief: "TODO"
brief: "Right-hand-side of the equation."
type: Expression

- LinEquation:
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ int run_nmodl(int argc, const char* argv[]) {

enable_sympy(solver_exists(*ast, "derivimplicit"), "'SOLVE ... METHOD derivimplicit'");
enable_sympy(node_exists(*ast, ast::AstNodeType::LINEAR_BLOCK), "'LINEAR' block");
enable_sympy(node_exists(*ast, ast::AstNodeType::NON_LINEAR_BLOCK),
"'NONLINEAR' block");
enable_sympy(solver_exists(*ast, "sparse"), "'SOLVE ... METHOD sparse'");
}

Expand Down
1 change: 1 addition & 0 deletions test/usecases/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(NMODL_USECASE_DIRS
net_receive
net_send
neuron_variables
nonlinear
nonspecific_current
parameter
point_process
Expand Down
21 changes: 21 additions & 0 deletions test/usecases/nonlinear/nonlin.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
NEURON {
SUFFIX nonlin
}

STATE { x }

FUNCTION solve() {
: Iterative solvers need a starting guess.
x = 1.0
SOLVE eq

solve = x
}

NONLINEAR eq {
~ x*x = 4.0
}

FUNCTION residual(x) {
residual = x - 2.0
}
15 changes: 15 additions & 0 deletions test/usecases/nonlinear/test_nonlin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from neuron import h, gui


def test_nonlin():
s = h.Section()
s.insert("nonlin")
inst = s(0.5).nonlin

x = inst.solve()
error = inst.residual(x)
assert abs(error) < 1e-9, f"{x = }, {error = }"


if __name__ == "__main__":
test_nonlin()

0 comments on commit 9c543ef

Please sign in to comment.