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

`solve(nlcache)` errors for complex types #364

Closed jamblejoe closed 5 months ago

jamblejoe commented 5 months ago

Describe the bug šŸž

solve(prob) does not error for complex valued problems, but solve(nlcache) does.

Minimal Reproducible Example šŸ‘‡

f(u, p) = u .* u .- p
u0 = [1.0im]
prob = NonlinearProblem(f, u0, [1])

Now

solve(prob)

returns successfully. But

nlcache = init(prob)
solve(nlcache)

errors.

Error & Stacktrace āš ļø

ERROR: MethodError: no method matching init(::NonlinearSolve.NonlinearSolvePolyAlgorithmCache{false, 4, Tuple{ā€¦}, NonlinearSolvePolyAlgorithm{ā€¦}})

Closest candidates are:
  init(::SciMLBase.AbstractJumpProblem, Any...; kwargs...)
   @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:545
  init(::NonlinearProblem{<:Union{Number, var"#s157"} where var"#s157"<:AbstractArray, iip, <:Union{var"#s156", var"#s155"} where {var"#s156"<:ForwardDiff.Dual{T, V, P}, var"#s155"<:(AbstractArray{<:ForwardDiff.Dual{T, V, P}})}}, ::Union{Nothing, SciMLBase.AbstractNonlinearAlgorithm}, ::Any...; kwargs...) where {T, V, P, iip}
   @ NonlinearSolve ~/.julia/packages/NonlinearSolve/UPIol/src/internal/forward_diff.jl:37
  init(::PDEProblem, ::SciMLBase.AbstractDEAlgorithm, ::Any...; kwargs...)
   @ DiffEqBase ~/.julia/packages/DiffEqBase/eLhx9/src/solve.jl:1140
  ...

Stacktrace:
 [1] solve(args::NonlinearSolve.NonlinearSolvePolyAlgorithmCache{ā€¦}; kwargs::@Kwargs{})
   @ CommonSolve ~/.julia/packages/CommonSolve/JfpfI/src/CommonSolve.jl:23
 [2] top-level scope
   @ REPL[97]:1
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  NonlinearSolve v3.5.3
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
ChrisRackauckas commented 5 months ago

You meant solve!?

avik-pal commented 5 months ago

Just changing to solve! works.

jamblejoe commented 5 months ago

Sorry, I get confused with solve and solve!