Skip to content

Commit 4048ae8

Browse files
authored
Merge pull request #1682 from SciML/parameters_mtkitize
Throw a more concrete error on unsupported modelingtoolkitize parameters
2 parents f055ee3 + 11af9c6 commit 4048ae8

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/systems/diffeqs/modelingtoolkitize.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,47 @@ 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+
The chosen parameter type is currently not supported by `modelingtoolkitize`. The
104+
current supported types are:
105+
106+
- AbstractArrays
107+
- AbstractDicts
108+
- LabelledArrays (SLArray, LArray)
109+
- Flat tuples (tuples of numbers)
110+
- Flat named tuples (namedtuples of numbers)
111+
"""
112+
113+
struct ModelingtoolkitizeParametersNotSupportedError <: Exception
114+
type::Any
115+
end
116+
117+
function Base.showerror(io::IO, e::ModelingtoolkitizeParametersNotSupportedError)
118+
println(io, PARAMETERS_NOT_SUPPORTED_MESSAGE)
119+
print(io, "Parameter type: ")
120+
println(io, e.type)
121+
end
122+
102123
function define_params(p)
124+
throw(ModelingtoolkitizeParametersNotSupportedError(typeof(p)))
125+
end
126+
127+
function define_params(p::AbstractArray)
103128
[toparam(variable(, i)) for i in eachindex(p)]
104129
end
105130

131+
function define_params(p::Number)
132+
[toparam(variable())]
133+
end
134+
106135
function define_params(p::AbstractDict)
107136
OrderedDict(k => toparam(variable(, i)) for (i, k) in zip(1:length(p), keys(p)))
108137
end

0 commit comments

Comments
 (0)