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
Merged

Conversation

utkarsh530
Copy link
Member

Hi,

I have currently added build_solution in solve.jl for NewtonRaphson. I did understand what was the purpose of scalar.jl. Do I need to add build_solution there too? And how to handle bracketing methods for build_solution?
@ChrisRackauckas, please have a look.

src/solve.jl Outdated Show resolved Hide resolved
Copy link
Member

@YingboMa YingboMa left a comment

Choose a reason for hiding this comment

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

Doing one extra function evaluation for the residual seems pretty inefficient. I am fine with merge this as is, but we need to let the nonlinear solver itself forward the last computed residual.

@ChrisRackauckas
Copy link
Member

yeah it's already doing it to exit, so it might as well use the calculation of the exit criterion.

src/solve.jl Outdated
@@ -2,14 +2,8 @@ function SciMLBase.solve(prob::NonlinearProblem,
alg::AbstractNonlinearSolveAlgorithm, args...;
kwargs...)
solver = init(prob, alg, args...; kwargs...)
sol = solve!(solver)
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.

src/solve.jl Outdated
sol = solve!(solver)
return sol
sol, resid = solve!(solver)
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?

src/scalar.jl Outdated
@@ -75,14 +76,14 @@ function SciMLBase.solve(prob::NonlinearProblem, ::Bisection, args...; maxiters
fl, fr = f(left), f(right)

if iszero(fl)
return BracketingSolution(left, right, EXACT_SOLUTION_LEFT)
return BracketingSolution(left, right, EXACT_SOLUTION_LEFT,fl)
Copy link
Member Author

@utkarsh530 utkarsh530 Feb 2, 2021

Choose a reason for hiding this comment

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

Do I need to return SciMLBase.build_solution here too, (scalar.jl)? Because if we need to do, we need to check how u0 as a Tuple will be handled here: https://github.com/SciML/SciMLBase.jl/blob/master/src/solutions/nonlinear_solutions.jl#L26? What should it be in that case? @ChrisRackauckas

Copy link
Member

Choose a reason for hiding this comment

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

Maybe change it to N = length((size(u)...,)) since it should not be able to change over the solution. Yes, it should use build_solution like all others, and treat u as the left.

Copy link
Member

Choose a reason for hiding this comment

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

or well, based on EXACT_SOLUTION_LEFT choose u as left etc.

@utkarsh530
Copy link
Member Author

With SciML/SciMLBase.jl#17, this will complete the PR.

@utkarsh530 utkarsh530 changed the title [WIP] Add SciML.build_solution Add SciML.build_solution Feb 3, 2021
@utkarsh530 utkarsh530 requested a review from YingboMa February 3, 2021 18:25
src/types.jl Outdated
end

# function NewtonImmutableSolver{iip}(iter, f, alg, u, fu, p, force_stop, maxiters, internalnorm, retcode, tol, cache) where iip
# NewtonImmutableSolver{iip, typeof(f), typeof(alg), typeof(u),
# typeof(fu), typeof(p), typeof(internalnorm), typeof(tol), typeof(cache)}(iter, f, alg, u, fu, p, force_stop, maxiters, internalnorm, retcode, tol, cache)
# end

struct BracketingSolution{uType}
struct BracketingSolution{uType,resType}
Copy link
Member

Choose a reason for hiding this comment

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

Are we still using the original solution type?

Copy link
Member Author

@utkarsh530 utkarsh530 Feb 3, 2021

Choose a reason for hiding this comment

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

Nope, we don't need it. Refactored the code. Thanks for the suggestion.

@ChrisRackauckas ChrisRackauckas merged commit b8bed15 into SciML:master Feb 3, 2021
avik-pal pushed a commit that referenced this pull request Nov 1, 2024
TrustRegion -> SimpleTrustRegion and specialize the number types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants