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

Long output from `init(NonlinearProblem(...))` #362

Closed jamblejoe closed 4 months ago

jamblejoe commented 5 months ago

Describe the bug 🐞

The output from init(NonlinearProblem(...)) in the REPL seems a bit excessive. I cannot copy the complete out here, as it reaches the github limitation of 65536 characters. The full output is here https://pastebin.com/RBsB8C7f.

Expected behavior

Shorter output.

Minimal Reproducible Example 👇

f(u, p) = u .* u .- 2
u0 = @SVector[1.0, 1.0]
prob = NonlinearProblem(f, u0)
init(prob)

outputs the following. This seems a bit too long for a REPL output.

julia> init(prob)
NonlinearSolve.NonlinearSolvePolyAlgorithmCache{false, 7, Tuple{NonlinearSolve.ApproximateJacobianSolveCache{true, :LineSearch, false, false, SVector{2, Float64}, SVector{2, Float64}, SVector{2, Float64}, SciMLBase.NullParameters, SVector{2, Float64}, SMatrix{2, 2, Float64, 4}, ApproximateJacobianSolveAlgorithm{false, :Broyden, NoLineSearch, Missing, NewtonDescent{Nothing, typeof(NonlinearSolve.DEFAULT_PRECS)}, NonlinearSolve.GoodBroydenUpdateRule, NonlinearSolve.NoChangeInStateReset{Nothing}, NonlinearSolve.IdentityInitialization{Nothing, NonlinearSolve.FullStructure}}, NonlinearProblem{SVector{2, Float64}, false, SciMLBase.NullParameters, NonlinearFunction{false, SciMLBase.FullSpecialize, 
.... 
!!!!TRUNCATED!!!!
....
Tracing Disabled, SciMLBase.ReturnCode.Default, false)), NonlinearSolvePolyAlgorithm for NonlinearProblem with 7 algorithms
  [1]: Broyden(
           descent = NewtonDescent(),
           update_rule = GoodBroydenUpdateRule(),
           reinit_rule = NoChangeInStateReset(),
           max_resets = 100,
           initialization = IdentityInitialization(structure = FullStructure()),
           inverse_jacobian = true
       )
  [2]: Broyden(
           descent = NewtonDescent(),
           update_rule = GoodBroydenUpdateRule(),
           reinit_rule = NoChangeInStateReset(),
           max_resets = 100,
           initialization = TrueJacobianInitialization(structure = FullStructure()),
           inverse_jacobian = true
       )
  [3]: Klement(
           descent = NewtonDescent(),
           update_rule = KlementUpdateRule(),
           reinit_rule = IllConditionedJacobianReset(),
           max_resets = 100,
           initialization = IdentityInitialization(structure = DiagonalStructure())
       )
  [4]: NewtonRaphson(
          descent = NewtonDescent()
       )
  [5]: NewtonRaphson(
          linesearch = LineSearchesJL(method = BackTracking()),
          descent = NewtonDescent()
       )
  [6]: TrustRegion(
          trustregion = GenericTrustRegionScheme(method = RadiusUpdateSchemes.Simple),
          descent = Dogleg(newton_descent = NewtonDescent(), steepest_descent = SteepestDescent())
       )
  [7]: TrustRegion(
          trustregion = GenericTrustRegionScheme(method = RadiusUpdateSchemes.Bastin),
          descent = Dogleg(newton_descent = NewtonDescent(), steepest_descent = SteepestDescent())
       ), 1)

Environment (please complete the following information):

NonlinearSolve v3.5.3 `https://github.com/SciML/NonlinearSolve.jl.git#master`
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
  Threads: 1 on 4 virtual cores

julia> 
avik-pal commented 5 months ago

Not really a bug :sweat_smile:. But if anyone wants to create a PR for pretty printing the caches, I will gladly accept them.

avik-pal commented 5 months ago

We can potentially use https://github.com/curtd/AutoPrettyPrinting.jl for this

jamblejoe commented 5 months ago

Agree, it's not really a bug. But it is annoying in interactive sessions and, at least for me, does not provide any useful information. If there is any in the above output, it vanishes in the vast majority of stuff, which is printed. For comparison: imagine, whenever you define an array in Julia, it prints the whole content. Sure, you can append ; but it would be annoying. It just doesn't make sense.

So while it is probably not top priority, it should be addressed eventually.

EDIT: I forgot: The work put into this package and the whole SciML ecosystem has been awesome. Great job!

oscardssmith commented 5 months ago

Specifically, for me at least, the important things to see the method and the autodiff settings, but pretty much everything else is fairly useless.