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 forward mode to line search #446

Merged
merged 1 commit into from
Jun 14, 2024
Merged

Conversation

tansongchen
Copy link
Collaborator

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Added forward mode support to line searches. We prefer forward AD for better performance, however, reverse AD is also supported if user explicitly requests it.

  1. If jvp is available, we use forward AD;
  2. If reverse type is requested, we use reverse AD;
  3. Otherwise, we use forward AD.

@tansongchen
Copy link
Collaborator Author

Getting significant perf improvement for in-place functions like

quadratic_f!(du, u, p) = (du .= u .* u .- p)
u0 = fill(1.0, 1000)
p = 2.0
prob = NonlinearProblem(quadratic_f!, u0, p)
algfwd = NewtonRaphson(; linesearch=LineSearchesJL(; method=LineSearches.HagerZhang()))
algrev = NewtonRaphson(; linesearch=LineSearchesJL(; method=LineSearches.HagerZhang(), autodiff=AutoZygote())) # fallback to finitediff
julia> @btime sol = solve(prob, algfwd)
  27.795 ms (265 allocations: 15.62 MiB)
Julia> @btime sol = solve(prob, algrev)
  50.685 ms (15732 allocations: 133.12 MiB)

Copy link

codecov bot commented Jun 7, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.54%. Comparing base (a74c321) to head (82944d0).

Files Patch % Lines
src/globalization/line_search.jl 77.77% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #446      +/-   ##
==========================================
- Coverage   86.45%   85.54%   -0.91%     
==========================================
  Files          47       47              
  Lines        2872     2878       +6     
==========================================
- Hits         2483     2462      -21     
- Misses        389      416      +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tansongchen
Copy link
Collaborator Author

tansongchen commented Jun 14, 2024

Updated strategy:

  1. If FiniteDiff is requested, we use finite diff on $\phi$;
  2. If jvp is available, we use jvp;
  3. If vjp is available, we use vjp;
  4. If reverse type is requested, we use reverse AD;
  5. Finally, we use forward AD.

@avik-pal avik-pal merged commit 6740074 into SciML:master Jun 14, 2024
18 of 22 checks passed
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