Skip to content

Commit

Permalink
refactor: only display singular warning if warn_initialize_determined
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 25, 2024
1 parent 70843db commit c7453ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/structural_transformation/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,15 @@ function check_consistency(state::TransformationState, orig_inputs; nothrow = fa
unassigned_var = singular_check(state)

if !isempty(unassigned_var) || !is_balanced
if nothrow
return false
end
io = IOBuffer()
Base.print_array(io, unassigned_var)
unassigned_var_str = String(take!(io))
errmsg = "The system is structurally singular! " *
"Here are the problematic variables: \n" *
unassigned_var_str
if nothrow
@warn errmsg
return false
end
throw(InvalidSystemException(errmsg))
end

Expand Down
11 changes: 9 additions & 2 deletions src/systems/diffeqs/abstractodesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,15 @@ function InitializationProblem{iip, specialize}(sys::AbstractODESystem,
sys; u0map, initialization_eqs, check_units, pmap = parammap); fully_determined)
end

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

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

0 comments on commit c7453ad

Please sign in to comment.