Skip to content

Commit 4d5f3af

Browse files
Fix SpeedMapping 0.4 compatibility
SpeedMapping 0.4 introduced breaking API changes: - `converged::Bool` -> `status::Symbol` in return type - `tol` -> `abstol` - `Lp` -> `pnorm` - `store_info` -> `store_trace` - `σ_min` -> `initial_learning_rate` - `orders::Vector{Int}` -> `orders::Tuple` This commit adds version detection to support both 0.3 and 0.4+ APIs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7946442 commit 4d5f3af

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

ext/NonlinearSolveSpeedMappingExt.jl

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
module NonlinearSolveSpeedMappingExt
22

3-
using SpeedMapping: speedmapping
3+
using SpeedMapping: SpeedMapping, speedmapping
44

55
using NonlinearSolveBase: NonlinearSolveBase
66
using NonlinearSolve: NonlinearSolve, SpeedMappingJL
77
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode
88

9+
# Check SpeedMapping version to determine API
10+
const SPEEDMAPPING_VERSION = pkgversion(SpeedMapping)
11+
const SPEEDMAPPING_NEW_API = SPEEDMAPPING_VERSION >= v"0.4"
12+
913
function SciMLBase.__solve(
1014
prob::NonlinearProblem, alg::SpeedMappingJL, args...;
1115
abstol = nothing, maxiters = 1000, alias = SciMLBase.NonlinearAliasSpecifier(alias_u0 = false),
@@ -28,18 +32,37 @@ function SciMLBase.__solve(
2832

2933
time_limit = ifelse(maxtime === nothing, 1000, maxtime)
3034

31-
sol = speedmapping(
32-
u; m!, tol, Lp = Inf, maps_limit = maxiters, alg.orders,
33-
alg.check_obj, store_info = store_trace isa Val{true}, alg.σ_min, alg.stabilize,
34-
time_limit
35-
)
35+
sol = if SPEEDMAPPING_NEW_API
36+
# SpeedMapping 0.4+ API
37+
speedmapping(
38+
u; m!, abstol = tol, pnorm = Inf, maps_limit = maxiters,
39+
orders = Tuple(alg.orders),
40+
initial_learning_rate = alg.σ_min == 0.0 ? 1.0 : alg.σ_min,
41+
store_trace = store_trace isa Val{true},
42+
time_limit
43+
)
44+
else
45+
# SpeedMapping 0.3 API
46+
speedmapping(
47+
u; m!, tol, Lp = Inf, maps_limit = maxiters, alg.orders,
48+
alg.check_obj, store_info = store_trace isa Val{true}, alg.σ_min, alg.stabilize,
49+
time_limit
50+
)
51+
end
3652
res = prob.u0 isa Number ? first(sol.minimizer) : sol.minimizer
3753
resid = NonlinearSolveBase.Utils.evaluate_f(prob, res)
3854

55+
# SpeedMapping 0.3 returns `converged::Bool`, 0.4+ returns `status::Symbol`
56+
converged = if hasproperty(sol, :converged)
57+
sol.converged
58+
else
59+
sol.status == :first_order
60+
end
61+
3962
return SciMLBase.build_solution(
4063
prob, alg, res, resid;
4164
original = sol, stats = SciMLBase.NLStats(sol.maps, 0, 0, 0, sol.maps),
42-
retcode = ifelse(sol.converged, ReturnCode.Success, ReturnCode.Failure)
65+
retcode = ifelse(converged, ReturnCode.Success, ReturnCode.Failure)
4366
)
4467
end
4568

0 commit comments

Comments
 (0)