393
393
function init_up (prob:: AbstractNonlinearProblem , sensealg, u0, p, args... ; kwargs... )
394
394
alg = extract_alg (args, kwargs, has_kwargs (prob) ? prob. kwargs : kwargs)
395
395
if isnothing (alg) || ! (alg isa AbstractNonlinearAlgorithm) # Default algorithm handling
396
- _prob = get_concrete_problem (prob, ! (prob isa DiscreteProblem) ; u0 = u0,
396
+ _prob = get_concrete_problem (prob, true ; u0 = u0,
397
397
p = p, kwargs... )
398
398
init_call (_prob, args... ; kwargs... )
399
399
else
@@ -755,9 +755,9 @@ SII.state_values(cache::NonlinearSolveNoInitCache) = SII.state_values(cache.prob
755
755
756
756
get_u (cache:: NonlinearSolveNoInitCache ) = SII. state_values (cache. prob)
757
757
758
- has_kwargs (_prob:: AbstractNonlinearProblem ) = has_kwargs (typeof (_prob))
759
- Base. @pure __has_kwargs (:: Type{T} ) where {T} = :kwargs ∈ fieldnames (T)
760
- has_kwargs (:: Type{T} ) where {T} = __has_kwargs (T)
758
+ # has_kwargs(_prob::AbstractNonlinearProblem) = has_kwargs(typeof(_prob))
759
+ # Base.@pure __has_kwargs(::Type{T}) where {T} = :kwargs ∈ fieldnames(T)
760
+ # has_kwargs(::Type{T}) where {T} = __has_kwargs(T)
761
761
762
762
function SciMLBase. reinit! (
763
763
cache:: NonlinearSolveNoInitCache , u0 = cache. prob. u0; p = cache. prob. p, kwargs...
@@ -854,29 +854,29 @@ function _solve_forward(prob, sensealg, u0, p, originator, args...; merge_callba
854
854
end
855
855
856
856
857
- function get_concrete_problem (prob:: NonlinearProblem , isadapt; kwargs... )
858
- oldprob = prob
859
- prob = get_updated_symbolic_problem (get_root_indp (prob), prob; kwargs... )
860
- if prob != = oldprob
861
- kwargs = (; kwargs... , u0 = SII. state_values (prob), p = SII. parameter_values (prob))
862
- end
863
- p = get_concrete_p (prob, kwargs)
864
- u0 = get_concrete_u0 (prob, isadapt, nothing , kwargs)
865
- u0 = promote_u0 (u0, p, nothing )
866
- remake (prob; u0 = u0, p = p)
867
- end
868
-
869
- function get_concrete_problem (prob:: NonlinearLeastSquaresProblem , isadapt; kwargs... )
870
- oldprob = prob
871
- prob = get_updated_symbolic_problem (get_root_indp (prob), prob; kwargs... )
872
- if prob != = oldprob
873
- kwargs = (; kwargs... , u0 = SII. state_values (prob), p = SII. parameter_values (prob))
874
- end
875
- p = get_concrete_p (prob, kwargs)
876
- u0 = get_concrete_u0 (prob, isadapt, nothing , kwargs)
877
- u0 = promote_u0 (u0, p, nothing )
878
- remake (prob; u0 = u0, p = p)
879
- end
857
+ # function get_concrete_problem(prob::NonlinearProblem, isadapt; kwargs...)
858
+ # oldprob = prob
859
+ # prob = get_updated_symbolic_problem(get_root_indp(prob), prob; kwargs...)
860
+ # if prob !== oldprob
861
+ # kwargs = (; kwargs..., u0 = SII.state_values(prob), p = SII.parameter_values(prob))
862
+ # end
863
+ # p = get_concrete_p(prob, kwargs)
864
+ # u0 = get_concrete_u0(prob, isadapt, nothing, kwargs)
865
+ # u0 = promote_u0(u0, p, nothing)
866
+ # remake(prob; u0 = u0, p = p)
867
+ # end
868
+
869
+ # function get_concrete_problem(prob::NonlinearLeastSquaresProblem, isadapt; kwargs...)
870
+ # oldprob = prob
871
+ # prob = get_updated_symbolic_problem(get_root_indp(prob), prob; kwargs...)
872
+ # if prob !== oldprob
873
+ # kwargs = (; kwargs..., u0 = SII.state_values(prob), p = SII.parameter_values(prob))
874
+ # end
875
+ # p = get_concrete_p(prob, kwargs)
876
+ # u0 = get_concrete_u0(prob, isadapt, nothing, kwargs)
877
+ # u0 = promote_u0(u0, p, nothing)
878
+ # remake(prob; u0 = u0, p = p)
879
+ # end
880
880
881
881
"""
882
882
Given the index provider `indp` used to construct the problem `prob` being solved, return
@@ -931,129 +931,129 @@ function build_null_solution(
931
931
SciMLBase. build_solution (prob, nothing , Float64[], resid; retcode)
932
932
end
933
933
934
- @inline function extract_alg (solve_args, solve_kwargs, prob_kwargs)
935
- if isempty (solve_args) || isnothing (first (solve_args))
936
- if haskey (solve_kwargs, :alg )
937
- solve_kwargs[:alg ]
938
- elseif haskey (prob_kwargs, :alg )
939
- prob_kwargs[:alg ]
940
- else
941
- nothing
942
- end
943
- elseif first (solve_args) isa SciMLBase. AbstractSciMLAlgorithm &&
944
- ! (first (solve_args) isa SciMLBase. EnsembleAlgorithm)
945
- first (solve_args)
946
- else
947
- nothing
948
- end
949
- end
950
-
951
- function get_concrete_u0 (prob, isadapt, t0, kwargs)
952
- if eval_u0 (prob. u0)
953
- u0 = prob. u0 (prob. p, t0)
954
- elseif haskey (kwargs, :u0 )
955
- u0 = kwargs[:u0 ]
956
- else
957
- u0 = prob. u0
958
- end
959
-
960
- isadapt && eltype (u0) <: Integer && (u0 = float .(u0))
961
-
962
- _u0 = handle_distribution_u0 (u0)
963
-
964
- if isinplace (prob) && (_u0 isa Number || _u0 isa SArray)
965
- throw (IncompatibleInitialConditionError ())
966
- end
967
-
968
- if _u0 isa Tuple
969
- throw (TupleStateError ())
970
- end
971
-
972
- _u0
973
- end
974
-
975
- function get_concrete_p (prob, kwargs)
976
- if haskey (kwargs, :p )
977
- p = kwargs[:p ]
978
- else
979
- p = prob. p
980
- end
981
- end
982
-
983
- eval_u0 (u0:: Function ) = true
984
- eval_u0 (u0) = false
985
-
986
- handle_distribution_u0 (_u0) = _u0
987
-
988
- anyeltypedual (x) = anyeltypedual (x, Val{0 })
989
- anyeltypedual (x, counter) = Any
990
-
991
- function promote_u0 (u0, p, t0)
992
- if SciMLStructures. isscimlstructure (p)
993
- _p = SciMLStructures. canonicalize (SciMLStructures. Tunable (), p)[1 ]
994
- if ! isequal (_p, p)
995
- return promote_u0 (u0, _p, t0)
996
- end
997
- end
998
- Tu = eltype (u0)
999
- if isdualtype (Tu)
1000
- return u0
1001
- end
1002
- Tp = anyeltypedual (p, Val{0 })
1003
- if Tp == Any
1004
- Tp = Tu
1005
- end
1006
- Tt = anyeltypedual (t0, Val{0 })
1007
- if Tt == Any
1008
- Tt = Tu
1009
- end
1010
- Tcommon = promote_type (Tu, Tp, Tt)
1011
- return if isdualtype (Tcommon)
1012
- Tcommon .(u0)
1013
- else
1014
- u0
1015
- end
1016
- end
1017
-
1018
- function promote_u0 (u0:: AbstractArray{<:Complex} , p, t0)
1019
- if SciMLStructures. isscimlstructure (p)
1020
- _p = SciMLStructures. canonicalize (SciMLStructures. Tunable (), p)[1 ]
1021
- if ! isequal (_p, p)
1022
- return promote_u0 (u0, _p, t0)
1023
- end
1024
- end
1025
- Tu = real (eltype (u0))
1026
- if isdualtype (Tu)
1027
- return u0
1028
- end
1029
- Tp = anyeltypedual (p, Val{0 })
1030
- if Tp == Any
1031
- Tp = Tu
1032
- end
1033
- Tt = anyeltypedual (t0, Val{0 })
1034
- if Tt == Any
1035
- Tt = Tu
1036
- end
1037
- Tcommon = promote_type (eltype (u0), Tp, Tt)
1038
- return if isdualtype (real (Tcommon))
1039
- Tcommon .(u0)
1040
- else
1041
- u0
1042
- end
1043
- end
1044
-
1045
- function checkkwargs (kwargshandle; kwargs... )
1046
- if any (x -> x ∉ allowedkeywords, keys (kwargs))
1047
- if kwargshandle == KeywordArgError
1048
- throw (CommonKwargError (kwargs))
1049
- elseif kwargshandle == KeywordArgWarn
1050
- @warn KWARGWARN_MESSAGE
1051
- unrecognized = setdiff (keys (kwargs), allowedkeywords)
1052
- print (" Unrecognized keyword arguments: " )
1053
- printstyled (unrecognized; bold = true , color = :red )
1054
- print (" \n\n " )
1055
- else
1056
- @assert kwargshandle == KeywordArgSilent
1057
- end
1058
- end
1059
- end
934
+ # @inline function extract_alg(solve_args, solve_kwargs, prob_kwargs)
935
+ # if isempty(solve_args) || isnothing(first(solve_args))
936
+ # if haskey(solve_kwargs, :alg)
937
+ # solve_kwargs[:alg]
938
+ # elseif haskey(prob_kwargs, :alg)
939
+ # prob_kwargs[:alg]
940
+ # else
941
+ # nothing
942
+ # end
943
+ # elseif first(solve_args) isa SciMLBase.AbstractSciMLAlgorithm &&
944
+ # !(first(solve_args) isa SciMLBase.EnsembleAlgorithm)
945
+ # first(solve_args)
946
+ # else
947
+ # nothing
948
+ # end
949
+ # end
950
+
951
+ # function get_concrete_u0(prob, isadapt, t0, kwargs)
952
+ # if eval_u0(prob.u0)
953
+ # u0 = prob.u0(prob.p, t0)
954
+ # elseif haskey(kwargs, :u0)
955
+ # u0 = kwargs[:u0]
956
+ # else
957
+ # u0 = prob.u0
958
+ # end
959
+
960
+ # isadapt && eltype(u0) <: Integer && (u0 = float.(u0))
961
+
962
+ # _u0 = handle_distribution_u0(u0)
963
+
964
+ # if isinplace(prob) && (_u0 isa Number || _u0 isa SArray)
965
+ # throw(IncompatibleInitialConditionError())
966
+ # end
967
+
968
+ # if _u0 isa Tuple
969
+ # throw(TupleStateError())
970
+ # end
971
+
972
+ # _u0
973
+ # end
974
+
975
+ # function get_concrete_p(prob, kwargs)
976
+ # if haskey(kwargs, :p)
977
+ # p = kwargs[:p]
978
+ # else
979
+ # p = prob.p
980
+ # end
981
+ # end
982
+
983
+ # eval_u0(u0::Function) = true
984
+ # eval_u0(u0) = false
985
+
986
+ # handle_distribution_u0(_u0) = _u0
987
+
988
+ # anyeltypedual(x) = anyeltypedual(x, Val{0})
989
+ # anyeltypedual(x, counter) = Any
990
+
991
+ # function promote_u0(u0, p, t0)
992
+ # if SciMLStructures.isscimlstructure(p)
993
+ # _p = SciMLStructures.canonicalize(SciMLStructures.Tunable(), p)[1]
994
+ # if !isequal(_p, p)
995
+ # return promote_u0(u0, _p, t0)
996
+ # end
997
+ # end
998
+ # Tu = eltype(u0)
999
+ # if isdualtype(Tu)
1000
+ # return u0
1001
+ # end
1002
+ # Tp = anyeltypedual(p, Val{0})
1003
+ # if Tp == Any
1004
+ # Tp = Tu
1005
+ # end
1006
+ # Tt = anyeltypedual(t0, Val{0})
1007
+ # if Tt == Any
1008
+ # Tt = Tu
1009
+ # end
1010
+ # Tcommon = promote_type(Tu, Tp, Tt)
1011
+ # return if isdualtype(Tcommon)
1012
+ # Tcommon.(u0)
1013
+ # else
1014
+ # u0
1015
+ # end
1016
+ # end
1017
+
1018
+ # function promote_u0(u0::AbstractArray{<:Complex}, p, t0)
1019
+ # if SciMLStructures.isscimlstructure(p)
1020
+ # _p = SciMLStructures.canonicalize(SciMLStructures.Tunable(), p)[1]
1021
+ # if !isequal(_p, p)
1022
+ # return promote_u0(u0, _p, t0)
1023
+ # end
1024
+ # end
1025
+ # Tu = real(eltype(u0))
1026
+ # if isdualtype(Tu)
1027
+ # return u0
1028
+ # end
1029
+ # Tp = anyeltypedual(p, Val{0})
1030
+ # if Tp == Any
1031
+ # Tp = Tu
1032
+ # end
1033
+ # Tt = anyeltypedual(t0, Val{0})
1034
+ # if Tt == Any
1035
+ # Tt = Tu
1036
+ # end
1037
+ # Tcommon = promote_type(eltype(u0), Tp, Tt)
1038
+ # return if isdualtype(real(Tcommon))
1039
+ # Tcommon.(u0)
1040
+ # else
1041
+ # u0
1042
+ # end
1043
+ # end
1044
+
1045
+ # function checkkwargs(kwargshandle; kwargs...)
1046
+ # if any(x -> x ∉ allowedkeywords, keys(kwargs))
1047
+ # if kwargshandle == KeywordArgError
1048
+ # throw(CommonKwargError(kwargs))
1049
+ # elseif kwargshandle == KeywordArgWarn
1050
+ # @warn KWARGWARN_MESSAGE
1051
+ # unrecognized = setdiff(keys(kwargs), allowedkeywords)
1052
+ # print("Unrecognized keyword arguments: ")
1053
+ # printstyled(unrecognized; bold = true, color = :red)
1054
+ # print("\n\n")
1055
+ # else
1056
+ # @assert kwargshandle == KeywordArgSilent
1057
+ # end
1058
+ # end
1059
+ # end
0 commit comments