Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NONLINEAR requires sympy --analytic. #1512

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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()
Loading