Skip to content

Commit 0190957

Browse files
Throw a more concrete error on unsupported modelingtoolkitize parameters
This is at least an intermediate solution to help give more interpretable error messages for #1678 . It's not a full solution since the real problem there is that while tuples are supported, it assumes `::NTuple{<:Number}` The "real" answer of course is to make this handling recursive, but I'll leave that as a separate PR.
1 parent f055ee3 commit 0190957

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/systems/diffeqs/modelingtoolkitize.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,41 @@ function define_vars(u::Union{SLArray, LArray}, t)
9191
[_defvar(x)(t) for x in LabelledArrays.symnames(typeof(u))]
9292
end
9393

94-
function define_vars(u::Tuple, t)
94+
function define_vars(u::NTuple{<:Number}, t)
9595
tuple((_defvaridx(:x, i)(ModelingToolkit.value(t)) for i in eachindex(u))...)
9696
end
9797

9898
function define_vars(u::NamedTuple, t)
9999
NamedTuple(x => _defvar(x)(ModelingToolkit.value(t)) for x in keys(u))
100100
end
101101

102+
const PARAMETERS_NOT_SUPPORTED_MESSAGE =
103+
"""
104+
The chosen parameter type is currently not supported by `modelingtoolkitize`. The
105+
current supported types are:
106+
107+
- AbstractArrays
108+
- AbstractDicts
109+
- LabelledArrays (SLArray, LArray)
110+
- Flat tuples (tuples of numbers)
111+
- Flat named tuples (namedtuples of numbers)
112+
"""
113+
114+
struct ModelingtoolkitizeParametersNotSupportedError <: Exception
115+
type::Any
116+
end
117+
118+
function Base.showerror(io::IO, e::ModelingtoolkitizeParametersNotSupportedError)
119+
println(io, PARAMETERS_NOT_SUPPORTED_MESSAGE)
120+
print(io, "Parameter type: ")
121+
println(io,e.type)
122+
end
123+
102124
function define_params(p)
125+
throw(ModelingtoolkitizeParametersNotSupportedError(typeof(p)))
126+
end
127+
128+
function define_params(p::AbstractArray)
103129
[toparam(variable(, i)) for i in eachindex(p)]
104130
end
105131

0 commit comments

Comments
 (0)