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

Can not iterate solver before solving #62

Closed
KronosTheLate opened this issue Apr 28, 2022 · 0 comments · Fixed by #345
Closed

Can not iterate solver before solving #62

KronosTheLate opened this issue Apr 28, 2022 · 0 comments · Fixed by #345
Labels
enhancement New feature or request

Comments

@KronosTheLate
Copy link
Contributor

When attempting to iterate a solver that has not been solved, the user is told that there is no method matching iterate for the solver. Same goes for getindex:

julia> using NonlinearSolve

julia> f(u, p) = u .* u .- 2.0
f (generic function with 1 method)

julia> u0 = (1.0, 2.0) # brackets
(1.0, 2.0)

julia> probB = NonlinearProblem(f, u0)
NonlinearProblem with uType Tuple{Float64, Float64}. In-place: false
u0: (1.0, 2.0)

julia> solver = init(probB, Falsi()) # Can iterate the solver object
NonlinearSolve.BracketingImmutableSolver{NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Falsi, Float64, Float64, SciMLBase.NullParameters, Nothing, NonlinearProblem{Tuple{Float64, Float64}, false, SciMLBase.NullParameters, NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}}(1, NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}(f, LinearAlgebra.UniformScaling{Bool}(true), nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, SciMLBase.DEFAULT_OBSERVED_NO_TIME, nothing), Falsi(), 1.0, 2.0, -1.0, 2.0, SciMLBase.NullParameters(), false, 1000, NonlinearSolve.DEFAULT, nothing, false, NonlinearProblem{Tuple{Float64, Float64}, false, SciMLBase.NullParameters, NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}(NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}(f, LinearAlgebra.UniformScaling{Bool}(true), nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, SciMLBase.DEFAULT_OBSERVED_NO_TIME, nothing), (1.0, 2.0), SciMLBase.NullParameters(), Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}()))

julia> solver[1]
ERROR: MethodError: no method matching getindex(::NonlinearSolve.BracketingImmutableSolver{NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Falsi, Float64, Float64, SciMLBase.NullParameters, Nothing, NonlinearProblem{Tuple{Float64, Float64}, false, SciMLBase.NullParameters, NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}}, ::Int64)
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

julia> for s in solver
           @show s
       end
ERROR: MethodError: no method matching iterate(::NonlinearSolve.BracketingImmutableSolver{NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Falsi, Float64, Float64, SciMLBase.NullParameters, Nothing, NonlinearProblem{Tuple{Float64, Float64}, false, SciMLBase.NullParameters, NonlinearFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}})
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at C:\Users\Dennis Bal\.julia\juliaup\julia-1.7.1+0~x64\share\julia\base\range.jl:826
  iterate(::Union{LinRange, StepRangeLen}, ::Integer) at C:\Users\Dennis Bal\.julia\juliaup\julia-1.7.1+0~x64\share\julia\base\range.jl:826
  iterate(::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}} at C:\Users\Dennis Bal\.julia\juliaup\julia-1.7.1+0~x64\share\julia\base\dict.jl:695
  ...
Stacktrace:
 [1] top-level scope
   @ .\REPL[7]:1

julia> solver = solve!(solver)
u: 1.414213562373095

julia> solver[1]
1.414213562373095

julia> for s in solver
           @show s
       end
s = 1.414213562373095

However, should the unsolved solver not be an empty collection?

This is especially confusing due to the documentation, which says that you can iterate the solver in the line before it is solved. From http://nonlinearsolve.sciml.ai/dev/tutorials/iterator_interface/ :

f(u, p) = u .* u .- 2.0
u0 = (1.0, 2.0) # brackets
probB = NonlinearProblem(f, u0)
solver = init(probB, Falsi()) # Can iterate the solver object
solver = solve!(solver)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants