Skip to content

Commit 2b7a6b6

Browse files
refactor: only display singular warning if warn_initialize_determined
1 parent 1892f0a commit 2b7a6b6

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,17 @@ 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 &&
1318+
(unassigned_vars = StructuralTransformations.singular_check(ts); !isempty(unassigned_vars))
1319+
errmsg = """
1320+
The initialization system is structurally singular. Guess values may \
1321+
significantly affect the initial values of the ODE. The problematic variables \
1322+
are $unassigned_vars.
1323+
1324+
Note that the identification of problematic variables is a best-effort heuristic.
1325+
"""
1326+
@warn errmsg
13181327
end
13191328

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

test/initializationsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,6 @@ end
955955
D(D(y)) ~ λ * y - g
956956
x^2 + y^2 ~ 1]
957957
@mtkbuild pend = ODESystem(eqs, t)
958-
@test_warn ["structurally singular", "initialization", "guess"] ODEProblem(
958+
@test_warn ["structurally singular", "initialization", "Guess", "heuristic"] ODEProblem(
959959
pend, [x => 1, y => 0], (0.0, 1.5), [g => 1], guesses ==> 1])
960960
end

0 commit comments

Comments
 (0)