Skip to content

Commit

Permalink
Merge pull request #394 from avik-pal/ap/original_no_type
Browse files Browse the repository at this point in the history
Don't specialize on original and stats for polyalg
  • Loading branch information
ChrisRackauckas committed Mar 24, 2024
2 parents 28edcd4 + f4a7871 commit b7ba71d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "3.8.2"
version = "3.8.3"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
9 changes: 5 additions & 4 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ end
$(u_result_syms[i]) = $(sol_syms[i]).u
end
fu = get_fu($(cache_syms[i]))
return SciMLBase.build_solution(
return __build_solution_less_specialize(
$(sol_syms[i]).prob, cache.alg, $(u_result_syms[i]),
fu; retcode = $(sol_syms[i]).retcode, stats,
original = $(sol_syms[i]), trace = $(sol_syms[i]).trace)
Expand Down Expand Up @@ -196,7 +196,8 @@ end
copyto!(cache.u0, u)
u = cache.u0
end
return SciMLBase.build_solution(cache.caches[idx].prob, cache.alg, u, fus[idx];
return __build_solution_less_specialize(
cache.caches[idx].prob, cache.alg, u, fus[idx];
retcode, stats, cache.caches[idx].trace)
end)

Expand Down Expand Up @@ -283,7 +284,7 @@ for (probType, pType) in ((:NonlinearProblem, :NLS), (:NonlinearLeastSquaresProb
else
$(u_result_syms[i]) = $(cur_sol).u
end
return SciMLBase.build_solution(
return __build_solution_less_specialize(
prob, alg, $(u_result_syms[i]), $(cur_sol).resid;
$(cur_sol).retcode, $(cur_sol).stats,
original = $(cur_sol), trace = $(cur_sol).trace)
Expand Down Expand Up @@ -316,7 +317,7 @@ for (probType, pType) in ((:NonlinearProblem, :NLS), (:NonlinearLeastSquaresProb
else
$(u_result_syms[i]) = $(sol_syms[i]).u
end
return SciMLBase.build_solution(
return __build_solution_less_specialize(
prob, alg, $(u_result_syms[i]), $(sol_syms[i]).resid;
$(sol_syms[i]).retcode, $(sol_syms[i]).stats,
$(sol_syms[i]).trace, original = $(sol_syms[i]))
Expand Down
13 changes: 13 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,16 @@ Determine the chunk size for ForwardDiff and PolyesterForwardDiff based on the i
"""
@inline pickchunksize(x) = pickchunksize(length(x))
@inline pickchunksize(x::Int) = ForwardDiff.pickchunksize(x)

# Original is often determined on runtime information especially for PolyAlgorithms so it
# is best to never specialize on that
function __build_solution_less_specialize(prob::AbstractNonlinearProblem, alg, u, resid;
retcode = ReturnCode.Default, original = nothing, left = nothing,
right = nothing, stats = nothing, trace = nothing, kwargs...)
T = eltype(eltype(u))
N = ndims(u)

return SciMLBase.NonlinearSolution{T, N, typeof(u), typeof(resid), typeof(prob),
typeof(alg), Any, typeof(left), Any, typeof(trace)}(
u, resid, prob, alg, retcode, original, left, right, stats, trace)
end
3 changes: 3 additions & 0 deletions test/misc/polyalg_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ end

@test all(!isnan, sol.u)
@test !SciMLBase.successful_retcode(sol.retcode)
@inferred solve(prob)
end

@testitem "[OOP] Infeasible" setup=[InfeasibleFunction] begin
Expand All @@ -235,6 +236,7 @@ end

@test all(!isnan, sol.u)
@test !SciMLBase.successful_retcode(sol.retcode)
@inferred solve(prob)

u0 = @SVector [0.0, 0.0, 0.0]
prob = NonlinearProblem(f1_infeasible, u0)
Expand All @@ -243,6 +245,7 @@ end
sol = solve(prob)
@test all(!isnan, sol.u)
@test !SciMLBase.successful_retcode(sol.retcode)
@inferred solve(prob)
catch err
@test err isa LinearAlgebra.SingularException
end
Expand Down

2 comments on commit b7ba71d

@avik-pal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103514

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.8.3 -m "<description of version>" b7ba71d1bfcf569c7d038575718af5fb2bb15482
git push origin v3.8.3

Please sign in to comment.