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

Add SciML.build_solution #28

Merged
merged 9 commits into from
Feb 3, 2021
8 changes: 5 additions & 3 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ function SciMLBase.solve(prob::NonlinearProblem,
alg::AbstractNonlinearSolveAlgorithm, args...;
kwargs...)
solver = init(prob, alg, args...; kwargs...)
sol = solve!(solver)
return sol
sol, resid = solve!(solver)
Copy link
Member

Choose a reason for hiding this comment

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

solve! has a standard interface that shouldn't be broken. We should just stick the resid in the sol.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I will update the sol struct with resid.

if typeof(sol) <: NewtonSolution
Copy link
Member

Choose a reason for hiding this comment

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

Why is this branching needed? It makes the solution type unstable and break non-Newton solvers. We can just assume that sol.u exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are two types of solver, Newton solver and Bracketing methods, which outputs sol.left and sol.right. That's why I wanted to ask how to pass bracketing methods to build_solution?

return SciMLBase.build_solution(prob, alg, sol.u, resid;retcode=:Success)
end
end

function SciMLBase.init(prob::NonlinearProblem{uType, iip}, alg::AbstractBracketingAlgorithm, args...;
Expand Down Expand Up @@ -68,7 +70,7 @@ function SciMLBase.solve!(solver::AbstractImmutableNonlinearSolver)
@set! solver.retcode = MAXITERS_EXCEED
end
sol = get_solution(solver)
return sol
return sol, solver.fu
end

"""
Expand Down
15 changes: 0 additions & 15 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ function num_types_in_tuple(sig::UnionAll)
length(Base.unwrap_unionall(sig).parameters)
end

function numargs(f)
typ = Tuple{Any, Val{:analytic}, Vararg}
typ2 = Tuple{Any, Type{Val{:analytic}}, Vararg} # This one is required for overloaded types
typ3 = Tuple{Any, Val{:jac}, Vararg}
typ4 = Tuple{Any, Type{Val{:jac}}, Vararg} # This one is required for overloaded types
typ5 = Tuple{Any, Val{:tgrad}, Vararg}
typ6 = Tuple{Any, Type{Val{:tgrad}}, Vararg} # This one is required for overloaded types
numparam = maximum([(m.sig<:typ || m.sig<:typ2 || m.sig<:typ3 || m.sig<:typ4 || m.sig<:typ5 || m.sig<:typ6) ? 0 : num_types_in_tuple(m.sig) for m in methods(f)])
return (numparam-1) #-1 in v0.5 since it adds f as the first parameter
end

function isinplace(f,inplace_param_number)
numargs(f)>=inplace_param_number
end

### Default Linsolve

# Try to be as smart as possible
Expand Down