Skip to content

Commit a312925

Browse files
committed
add more imports
1 parent f5f92cc commit a312925

File tree

2 files changed

+156
-154
lines changed

2 files changed

+156
-154
lines changed

lib/NonlinearSolveBase/src/NonlinearSolveBase.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ using SciMLBase: SciMLBase, ReturnCode, AbstractODEIntegrator, AbstractNonlinear
2020
AbstractNonlinearAlgorithm,
2121
NonlinearProblem, NonlinearLeastSquaresProblem,
2222
NonlinearFunction, NLStats, LinearProblem,
23-
LinearAliasSpecifier, ImmutableNonlinearProblem, NonlinearAliasSpecifier
23+
LinearAliasSpecifier, ImmutableNonlinearProblem, NonlinearAliasSpecifier,
24+
promote_u0, anyeltypedual, eval_u0, get_concrete_u0, get_concrete_p,
25+
has_kwargs, extract_alg, get_concrete_problem
2426
import SciMLBase: solve, init, solve!, __init, __solve, wrap_sol, get_root_indp, isinplace, remake
2527
using SciMLJacobianOperators: JacobianOperator, StatefulJacobianOperator
2628
using SciMLOperators: AbstractSciMLOperator, IdentityOperator

lib/NonlinearSolveBase/src/solve.jl

Lines changed: 153 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ end
393393
function init_up(prob::AbstractNonlinearProblem, sensealg, u0, p, args...; kwargs...)
394394
alg = extract_alg(args, kwargs, has_kwargs(prob) ? prob.kwargs : kwargs)
395395
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,
397397
p = p, kwargs...)
398398
init_call(_prob, args...; kwargs...)
399399
else
@@ -755,9 +755,9 @@ SII.state_values(cache::NonlinearSolveNoInitCache) = SII.state_values(cache.prob
755755

756756
get_u(cache::NonlinearSolveNoInitCache) = SII.state_values(cache.prob)
757757

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)
761761

762762
function SciMLBase.reinit!(
763763
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
854854
end
855855

856856

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
880880

881881
"""
882882
Given the index provider `indp` used to construct the problem `prob` being solved, return
@@ -931,129 +931,129 @@ function build_null_solution(
931931
SciMLBase.build_solution(prob, nothing, Float64[], resid; retcode)
932932
end
933933

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

Comments
 (0)