Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/problems/initializationproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ All other keyword arguments are forwarded to the wrapped nonlinear problem const
# TODO: throw on uninitialized arrays
filter!(x -> !(x isa Symbolics.Arr), uninit)
if time_dependent_init && !isempty(uninit)
allow_incomplete || throw(IncompleteInitializationError(uninit))
allow_incomplete || throw(IncompleteInitializationError(uninit, sys))
# for incomplete initialization, we will add the missing variables as parameters.
# they will be updated by `update_initializeprob!` and `initializeprobmap` will
# use them to construct the new `u0`.
Expand Down Expand Up @@ -146,9 +146,10 @@ const INCOMPLETE_INITIALIZATION_MESSAGE = """

struct IncompleteInitializationError <: Exception
uninit::Any
sys::Any
end

function Base.showerror(io::IO, e::IncompleteInitializationError)
println(io, INCOMPLETE_INITIALIZATION_MESSAGE)
println(io, e.uninit)
println(io, underscore_to_D(e.uninit, e.sys))
end
20 changes: 20 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,3 +1079,23 @@ function Base.showerror(io::IO, ::NotPossibleError)
This should not be possible. Please open an issue in ModelingToolkit.jl with an MWE.
""")
end

"""
$(TYPEDSIGNATURES)
Given a vector of variables in the system, return the corresponding `Differential` form of variable if possible.
Else returns the variable as-is.
"""
function underscore_to_D(v::AbstractVector, sys)
maps = get_schedule(sys).dummy_sub
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be gated behind isscheduled(sys) so that printing the error doesn't error if the system isn't mtkcompiled? It could also use the string manipulation "hack" discussed earlier in that case (or if the inverse map doesn't have the appropriate entry, as is the case for algebraic variables)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that error check happen earlier (ie before we get this far in the problem construction). Also note that any variables not in the schedule get passed through as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problems do not require the system to be mtkcompiled.

Also note that any variables not in the schedule get passed through as is.

Yeah, but we can still print them better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is added back in f137b1a

inv_maps = Dict{valtype(maps), Vector{Base.keytype(maps)}}()

for (k, v) in maps
push!(get!(() -> valtype(inv_maps)[], inv_maps, v), k)
end
map(Base.Fix2(underscore_to_D, inv_maps), v)
end

function underscore_to_D(v, inv_map)
only(get(inv_map, v, [v]))
end
Loading