Skip to content

Commit 71c6808

Browse files
Replace internal ITP implementation with SimpleNonlinearSolve.jl's ITP
This PR removes the internal `InternalITP` implementation from DiffEqBase and replaces it with the more robust and feature-complete `ITP` algorithm from SimpleNonlinearSolve.jl. ## Changes: 1. **Removed internal ITP implementation:** - Deleted `src/internal_itp.jl` containing `InternalITP` struct and solver - Removed helper functions like `prevfloat_tdir`, `nextfloat_tdir`, `max_tdir` 2. **Added SimpleNonlinearSolve dependency:** - Added SimpleNonlinearSolve as a dependency in Project.toml - Set minimum version bound to 2.7 to ensure compatibility 3. **Updated usage throughout codebase:** - Modified `src/callbacks.jl` to use `ITP()` instead of `InternalITP()` - Updated `src/DiffEqBase.jl` to import `ITP` from SimpleNonlinearSolve - Updated `ext/DiffEqBaseForwardDiffExt.jl` to handle the new ITP algorithm - Updated `test/internal_rootfinder.jl` to test with the new ITP implementation ## Benefits: - **Better maintenance:** Eliminates duplicate code and reduces maintenance burden - **Improved reliability:** Uses the well-tested and optimized ITP implementation from SimpleNonlinearSolve - **Better performance:** SimpleNonlinearSolve's ITP has additional optimizations and tuning parameters - **Consistency:** Aligns with the broader SciML ecosystem's approach of using specialized packages ## Testing: All existing tests pass, including the specific internal rootfinder tests that verify the ITP algorithm works correctly for various edge cases. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent da6e4c3 commit 71c6808

File tree

6 files changed

+15
-98
lines changed

6 files changed

+15
-98
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2424
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2525
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
2626
SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226"
27+
SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
2728
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2829
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
2930
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
@@ -97,6 +98,7 @@ ReverseDiff = "1"
9798
SciMLBase = "2.115.0"
9899
SciMLOperators = "1"
99100
SciMLStructures = "1.5"
101+
SimpleNonlinearSolve = "2.7"
100102
Setfield = "1"
101103
SparseArrays = "1.9"
102104
Static = "1"

ext/DiffEqBaseForwardDiffExt.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module DiffEqBaseForwardDiffExt
22

33
using DiffEqBase, ForwardDiff
4+
using SimpleNonlinearSolve: ITP
45
using DiffEqBase.ArrayInterface
56
using DiffEqBase: Void, FunctionWrappersWrappers, OrdinaryDiffEqTag,
67
AbstractTimeseriesSolution,
78
RecursiveArrayTools, reduce_tup, _promote_tspan, has_continuous_callback
89
import DiffEqBase: hasdualpromote, wrapfun_oop, wrapfun_iip, prob2dtmin,
9-
promote_tspan, ODE_DEFAULT_NORM,
10-
InternalITP, nextfloat_tdir
10+
promote_tspan, ODE_DEFAULT_NORM
1111
import SciMLBase: isdualtype, DualEltypeChecker, sse, __sum
1212

1313
const dualT = ForwardDiff.Dual{ForwardDiff.Tag{OrdinaryDiffEqTag, Float64}, Float64, 1}
@@ -153,7 +153,7 @@ end
153153

154154
# Differentiation of internal solver
155155

156-
function scalar_nlsolve_ad(prob, alg::InternalITP, args...; kwargs...)
156+
function scalar_nlsolve_ad(prob, alg::ITP, args...; kwargs...)
157157
f = prob.f
158158
p = value(prob.p)
159159

@@ -186,7 +186,7 @@ end
186186
function SciMLBase.solve(
187187
prob::IntervalNonlinearProblem{uType, iip,
188188
<:ForwardDiff.Dual{T, V, P}},
189-
alg::InternalITP, args...;
189+
alg::ITP, args...;
190190
kwargs...) where {uType, iip, T, V, P}
191191
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
192192
return SciMLBase.build_solution(prob, alg, ForwardDiff.Dual{T, V, P}(sol.u, partials),
@@ -202,7 +202,7 @@ function SciMLBase.solve(
202202
V,
203203
P},
204204
}},
205-
alg::InternalITP, args...;
205+
alg::ITP, args...;
206206
kwargs...) where {uType, iip, T, V, P}
207207
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
208208

src/DiffEqBase.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ using SciMLBase
4444

4545
using SciMLOperators: AbstractSciMLOperator, AbstractSciMLScalarOperator
4646

47+
using SimpleNonlinearSolve: ITP
48+
4749
using SciMLBase: @def, DEIntegrator, AbstractDEProblem,
4850
AbstractDiffEqInterpolation,
4951
DECallback, AbstractDEOptions, DECache, AbstractContinuousCallback,
@@ -140,7 +142,6 @@ include("utils.jl")
140142
include("stats.jl")
141143
include("calculate_residuals.jl")
142144
include("tableaus.jl")
143-
include("internal_itp.jl")
144145

145146
include("callbacks.jl")
146147
include("common_defaults.jl")

src/callbacks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,17 @@ end
358358
# rough implementation, needs multiple type handling
359359
# always ensures that if r = bisection(f, (x0, x1))
360360
# then either f(nextfloat(r)) == 0 or f(nextfloat(r)) * f(r) < 0
361-
# note: not really using bisection - uses the ITP method
361+
# note: not really using bisection - uses the ITP method
362362
function bisection(
363363
f, tup, t_forward::Bool, rootfind::SciMLBase.RootfindOpt, abstol, reltol;
364364
maxiters = 1000)
365365
if rootfind == SciMLBase.LeftRootFind
366366
solve(IntervalNonlinearProblem{false}(f, tup),
367-
InternalITP(), abstol = abstol,
367+
ITP(), abstol = abstol,
368368
reltol = reltol).left
369369
else
370370
solve(IntervalNonlinearProblem{false}(f, tup),
371-
InternalITP(), abstol = abstol,
371+
ITP(), abstol = abstol,
372372
reltol = reltol).right
373373
end
374374
end

src/internal_itp.jl

Lines changed: 0 additions & 87 deletions
This file was deleted.

test/internal_rootfinder.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using DiffEqBase
2-
using DiffEqBase: InternalITP, IntervalNonlinearProblem
2+
using DiffEqBase: IntervalNonlinearProblem
3+
using SimpleNonlinearSolve: ITP
34
using ForwardDiff
45

5-
for Rootfinder in (InternalITP,)
6+
for Rootfinder in (ITP,)
67
rf = Rootfinder()
78
# From SimpleNonlinearSolve
89
f = (u, p) -> u * u - p

0 commit comments

Comments
 (0)