SciML / NonlinearSolve.jl

High-performance and differentiation-enabled nonlinear solvers (Newton methods), bracketed rootfinding (bisection, Falsi), with sparsity and Newton-Krylov support.
https://docs.sciml.ai/NonlinearSolve/stable/
MIT License
216 stars 39 forks source link

Allow linsolve to be \ #358

Closed avik-pal closed 5 months ago

avik-pal commented 5 months ago

For very simple problems with a diagonal Jacobian this is much faster.

Testing on the quadratic problem

julia> @benchmark solve(prob, NLsolveJL())
BenchmarkTools.Trial: 10000 samples with 5 evaluations.
 Range (min … max):  6.047 μs …  2.675 ms  ┊ GC (min … max):  0.00% … 98.90%
 Time  (median):     7.052 μs              ┊ GC (median):     0.00%
 Time  (mean ± σ):   9.251 μs ± 50.774 μs  ┊ GC (mean ± σ):  10.88% ±  1.98%

    ▁█▂                                                       
  ▁▂███▆▃▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▂▂▂▃▃▃▄▄▄▃▄▃▃▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁ ▂
  6.05 μs        Histogram: frequency by time        12.6 μs <

 Memory estimate: 8.20 KiB, allocs estimate: 107.

julia> @benchmark solve(prob, NewtonRaphson(; linsolve = \, autodiff = AutoForwardDiff(; chunksize = 2)))
BenchmarkTools.Trial: 10000 samples with 9 evaluations.
 Range (min … max):  2.446 μs …  1.465 ms  ┊ GC (min … max):  0.00% … 98.65%
 Time  (median):     2.976 μs              ┊ GC (median):     0.00%
 Time  (mean ± σ):   4.062 μs ± 27.179 μs  ┊ GC (mean ± σ):  13.24% ±  1.98%

     ▄█▇▅▁                                                    
  ▁▂▅██████▆▃▃▃▂▂▂▂▃▂▃▃▃▃▂▂▂▂▂▁▂▂▂▂▃▃▃▃▃▃▃▄▄▃▃▂▂▂▂▂▂▂▂▂▁▁▁▁▁ ▂
  2.45 μs        Histogram: frequency by time        5.89 μs <

 Memory estimate: 5.09 KiB, allocs estimate: 54.

julia> @benchmark solve(prob, NewtonRaphson(; linsolve = LUFactorization(), autodiff = AutoForwardDiff(; chunksize = 2)))
BenchmarkTools.Trial: 10000 samples with 8 evaluations.
 Range (min … max):  3.409 μs …  1.503 ms  ┊ GC (min … max): 0.00% … 98.89%
 Time  (median):     3.759 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   4.631 μs ± 25.575 μs  ┊ GC (mean ± σ):  9.47% ±  1.71%

   ▄▆██▇▇▇▆▅▄▃▃▂▁ ▁             ▁▁▁▁▂▁▂▂▂▂▃▂▃▃▂▃▂▁▂▁▁▁       ▂
  █████████████████▇▅▆▆▆▅▆▆▇▇▇███████████████████████████▇▇▇ █
  3.41 μs      Histogram: log(frequency) by time     6.77 μs <

 Memory estimate: 5.22 KiB, allocs estimate: 55.

julia> @benchmark solve(prob, NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 2)))
BenchmarkTools.Trial: 10000 samples with 7 evaluations.
 Range (min … max):  4.846 μs …  1.846 ms  ┊ GC (min … max):  0.00% … 98.97%
 Time  (median):     5.304 μs              ┊ GC (median):     0.00%
 Time  (mean ± σ):   6.414 μs ± 40.806 μs  ┊ GC (mean ± σ):  14.11% ±  2.21%

   ▃▅▇███▇▆▅▄▃▂▂▂                                            ▂
  █████████████████▇▆▇▇▆▆▆▇▆▇▆▅▆▄▅▆▅▄▄▅▅▄▆▅▇▆▆▇▇▇▆███▇█▇▇▇▇▇ █
  4.85 μs      Histogram: log(frequency) by time     9.25 μs <

 Memory estimate: 8.25 KiB, allocs estimate: 100.
codecov[bot] commented 5 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (e989b72) 86.23% compared to head (d840c17) 86.19%.

Files Patch % Lines
src/internal/linear_solve.jl 75.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #358 +/- ## ========================================== - Coverage 86.23% 86.19% -0.05% ========================================== Files 44 44 Lines 2609 2608 -1 ========================================== - Hits 2250 2248 -2 - Misses 359 360 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

avik-pal commented 5 months ago

Failure is due to https://github.com/SciML/SciMLBase.jl/pull/605.