Skip to content

Commit c7453ad

Browse files
refactor: only display singular warning if warn_initialize_determined
1 parent 70843db commit c7453ad

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/structural_transformation/utils.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,15 @@ function check_consistency(state::TransformationState, orig_inputs; nothrow = fa
123123
unassigned_var = singular_check(state)
124124

125125
if !isempty(unassigned_var) || !is_balanced
126+
if nothrow
127+
return false
128+
end
126129
io = IOBuffer()
127130
Base.print_array(io, unassigned_var)
128131
unassigned_var_str = String(take!(io))
129132
errmsg = "The system is structurally singular! " *
130133
"Here are the problematic variables: \n" *
131134
unassigned_var_str
132-
if nothrow
133-
@warn errmsg
134-
return false
135-
end
136135
throw(InvalidSystemException(errmsg))
137136
end
138137

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,15 @@ function InitializationProblem{iip, specialize}(sys::AbstractODESystem,
13131313
sys; u0map, initialization_eqs, check_units, pmap = parammap); fully_determined)
13141314
end
13151315

1316-
if !isempty(StructuralTransformations.singular_check(get_tearing_state(isys)))
1317-
@warn "Since the initialization system is singular, the guess values may significantly affect the initial values of the ODE"
1316+
ts = get_tearing_state(isys)
1317+
if warn_initialize_determined && (unassigned_vars = StructuralTransformations.singular_check(ts); !isempty(unassigned_vars))
1318+
errmsg = """
1319+
The initialization system is singular. Guess values may significantly affect \
1320+
the initial values of the ODE. The problematic variables are $unassigned_vars.
1321+
1322+
Note that the identification of problematic variables is a best-effort heuristic.
1323+
"""
1324+
@warn errmsg
13181325
end
13191326

13201327
uninit = setdiff(unknowns(sys), [unknowns(isys); getfield.(observed(isys), :lhs)])

0 commit comments

Comments
 (0)