patrick-kidger / patrick-kidger/diffrax
NewtonNonlinearSolver returns nan when initialized with root value
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.1k
- Forks
- 189
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 1
Description
It seems like the Newton solver fails when initialized with the root value at which also $f'(x) = 0$. A minimal working example:
from diffrax import NewtonNonlinearSolver
def fun(x, args): return x**3
solver = NewtonNonlinearSolver(rtol=1e-3, atol=1e-6)
sol = solver(fun, 0., None)
print(sol.root, fun(sol.root, None)) # nan nan
It looks like the conditions here would catch it, where it not for at_least_two iterations. Of course, Newtons method can't do much in case of $f'(x) = 0$, but I would expect the solver to stop when it figures out it is already at the root.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with diffrax/nonlinear_solver/newton.py at the linked condition around line 128, then reproduce the provided x**3 example with an initial value of 0. Check how the solver handles an initial point that is already a root when the derivative is zero. Done means the example returns root 0.0 and a non-NaN function value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100