Skip to content

Commit f828027

Browse files
Merge pull request #4674 from SciML/as/fewer-warnings
refactor: eliminate unnecessary maxiters warnings if `missing_guess_value` is not `Error`
2 parents 85ce215 + 72c5625 commit f828027

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

lib/ModelingToolkitBase/src/systems/parameter_buffer.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ function MTKParameters(
107107
# Substitute through `AADSubWrapper` so that `COMMON_NOTHING` holes in partially
108108
# specified array values are never substituted into expressions (issue #4607).
109109
wrapped_op = AADSubWrapper(op)
110-
evaluate_varmap!(wrapped_op, all_ps; limit = substitution_limit)
110+
ir = get_irstructure(sys)
111+
evaluate_varmap!(ir, wrapped_op, all_ps; limit = substitution_limit)
111112

112113
tunable_buffer = Vector{ic.tunable_buffer_size.type}(
113114
undef, ic.tunable_buffer_size.length

lib/ModelingToolkitBase/src/systems/problem_utils.jl

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Keyword arguments:
332332
itself to get a numeric value for each variable in `vars`.
333333
"""
334334
function varmap_to_vars(
335-
varmap::AbstractDict, vars::Vector;
335+
varmap::AbstractDict, vars::Vector; ir = nothing,
336336
tofloat = true, use_union = false, container_type = Array, buffer_eltype = Nothing,
337337
toterm = default_toterm, check = true, allow_symbolic = false,
338338
is_initializeprob = false, substitution_limit = 100, missing_values = MissingGuessValue.Error()
@@ -345,7 +345,21 @@ function varmap_to_vars(
345345
if toterm !== nothing
346346
add_toterms!(varmap; toterm)
347347
end
348-
evaluate_varmap!(AtomicArrayDictSubstitutionWrapper(varmap), vars; limit = substitution_limit, allow_symbolic)
348+
if ir !== nothing
349+
evaluate_varmap!(
350+
ir, AtomicArrayDictSubstitutionWrapper(varmap), vars;
351+
limit = substitution_limit,
352+
allow_symbolic = allow_symbolic ||
353+
!Moshi.Data.isa_variant(missing_values, MissingGuessValue.Error)
354+
)
355+
else
356+
evaluate_varmap!(
357+
AtomicArrayDictSubstitutionWrapper(varmap), vars;
358+
limit = substitution_limit,
359+
allow_symbolic = allow_symbolic ||
360+
!Moshi.Data.isa_variant(missing_values, MissingGuessValue.Error)
361+
)
362+
end
349363
if check && !allow_symbolic
350364
missing_vars = missingvars(varmap, vars; toterm)
351365
for var in vars
@@ -519,6 +533,20 @@ function evaluate_varmap!(varmap::AbstractDict{SymbolicT, SymbolicT}, vars; limi
519533
return
520534
end
521535

536+
function evaluate_varmap!(
537+
ir::IRStructure{SymReal}, varmap::AtomicArrayDictSubstitutionWrapper, vars;
538+
limit = 100, allow_symbolic = false
539+
)
540+
subber = Symbolics.FixpointSubstituter(SU.IRSubstituter{true}(ir, varmap); maxiters = limit, warn_maxiters = !allow_symbolic)
541+
for k in vars
542+
v = get(varmap, k, COMMON_NOTHING)
543+
v === COMMON_NOTHING && continue
544+
SU.isconst(v) && continue
545+
varmap[k] = subber(v)
546+
end
547+
return
548+
end
549+
522550
"""
523551
$(TYPEDSIGNATURES)
524552
@@ -1932,15 +1960,16 @@ function __process_SciMLProblem(
19321960
end
19331961
end
19341962

1963+
ir = get_irstructure(sys)
19351964
if is_initializeprob
19361965
u0 = varmap_to_vars(
1937-
op, dvs; buffer_eltype = u0_eltype, container_type = u0Type,
1966+
op, dvs; ir, buffer_eltype = u0_eltype, container_type = u0Type,
19381967
allow_symbolic = symbolic_u0, is_initializeprob, substitution_limit,
19391968
missing_values = missing_guess_value
19401969
)
19411970
else
19421971
u0 = varmap_to_vars(
1943-
op, dvs; buffer_eltype = u0_eltype, container_type = u0Type,
1972+
op, dvs; ir, buffer_eltype = u0_eltype, container_type = u0Type,
19441973
allow_symbolic = symbolic_u0, is_initializeprob, substitution_limit
19451974
)
19461975
end

0 commit comments

Comments
 (0)