@@ -185,75 +185,81 @@ end
185185# Treat the result as a vector of symbols always
186186function SymbolicIndexingInterface. is_variable (sys:: AbstractSystem , sym)
187187 if unwrap (sym) isa Int # [x, 1] coerces 1 to a Num
188- return unwrap (sym) in 1 : length (unknown_states (sys))
188+ return unwrap (sym) in 1 : length (variable_symbols (sys))
189189 end
190- return any (isequal (sym), unknown_states (sys)) ||
190+ return any (isequal (sym), variable_symbols (sys)) ||
191191 hasname (sym) && is_variable (sys, getname (sym))
192192end
193193
194194function SymbolicIndexingInterface. is_variable (sys:: AbstractSystem , sym:: Symbol )
195- return any (isequal (sym), getname .(unknown_states (sys))) ||
195+ return any (isequal (sym), getname .(variable_symbols (sys))) ||
196196 count (' ₊' , string (sym)) == 1 &&
197- count (isequal (sym), Symbol .(sys. name, :₊ , getname .(unknown_states (sys)))) == 1
197+ count (isequal (sym), Symbol .(nameof (sys), :₊ , getname .(variable_symbols (sys)))) ==
198+ 1
198199end
199200
200201function SymbolicIndexingInterface. variable_index (sys:: AbstractSystem , sym)
201202 if unwrap (sym) isa Int
202203 return unwrap (sym)
203204 end
204- idx = findfirst (isequal (sym), unknown_states (sys))
205+ idx = findfirst (isequal (sym), variable_symbols (sys))
205206 if idx === nothing && hasname (sym)
206207 idx = variable_index (sys, getname (sym))
207208 end
208209 return idx
209210end
210211
211212function SymbolicIndexingInterface. variable_index (sys:: AbstractSystem , sym:: Symbol )
212- idx = findfirst (isequal (sym), getname .(unknown_states (sys)))
213+ idx = findfirst (isequal (sym), getname .(variable_symbols (sys)))
213214 if idx != = nothing
214215 return idx
215216 elseif count (' ₊' , string (sym)) == 1
216- return findfirst (isequal (sym), Symbol .(sys. name, :₊ , getname .(unknown_states (sys))))
217+ return findfirst (isequal (sym),
218+ Symbol .(nameof (sys), :₊ , getname .(variable_symbols (sys))))
217219 end
218220 return nothing
219221end
220222
223+ SymbolicIndexingInterface. variable_symbols (sys:: AbstractMultivariateSystem ) = sys. dvs
224+
221225function SymbolicIndexingInterface. variable_symbols (sys:: AbstractSystem )
222226 return unknown_states (sys)
223227end
224228
225229function SymbolicIndexingInterface. is_parameter (sys:: AbstractSystem , sym)
226230 if unwrap (sym) isa Int
227- return unwrap (sym) in 1 : length (parameters (sys))
231+ return unwrap (sym) in 1 : length (parameter_symbols (sys))
228232 end
229233
230- return any (isequal (sym), parameters (sys)) ||
234+ return any (isequal (sym), parameter_symbols (sys)) ||
231235 hasname (sym) && is_parameter (sys, getname (sym))
232236end
233237
234238function SymbolicIndexingInterface. is_parameter (sys:: AbstractSystem , sym:: Symbol )
235- return any (isequal (sym), getname .(parameters (sys))) ||
239+ return any (isequal (sym), getname .(parameter_symbols (sys))) ||
236240 count (' ₊' , string (sym)) == 1 &&
237- count (isequal (sym), Symbol .(sys. name, :₊ , getname .(parameters (sys)))) == 1
241+ count (isequal (sym),
242+ Symbol .(nameof (sys), :₊ , getname .(parameter_symbols (sys)))) == 1
238243end
239244
240245function SymbolicIndexingInterface. parameter_index (sys:: AbstractSystem , sym)
241246 if unwrap (sym) isa Int
242247 return unwrap (sym)
243248 end
244- idx = findfirst (isequal (sym), parameters (sys))
249+ idx = findfirst (isequal (sym), parameter_symbols (sys))
245250 if idx === nothing && hasname (sym)
246251 idx = parameter_index (sys, getname (sym))
247252 end
248253 return idx
249254end
250255
251256function SymbolicIndexingInterface. parameter_index (sys:: AbstractSystem , sym:: Symbol )
252- idx = findfirst (isequal (sym), getname .(parameters (sys)))
257+ idx = findfirst (isequal (sym), getname .(parameter_symbols (sys)))
253258 if idx != = nothing
254259 return idx
255260 elseif count (' ₊' , string (sym)) == 1
256- return findfirst (isequal (sym), Symbol .(sys. name, :₊ , getname .(parameters (sys))))
261+ return findfirst (isequal (sym),
262+ Symbol .(nameof (sys), :₊ , getname .(parameter_symbols (sys))))
257263 end
258264 return nothing
259265end
@@ -263,7 +269,7 @@ function SymbolicIndexingInterface.parameter_symbols(sys::AbstractSystem)
263269end
264270
265271function SymbolicIndexingInterface. is_independent_variable (sys:: AbstractSystem , sym)
266- return any (isequal (sym), independent_variables (sys))
272+ return any (isequal (sym), independent_variable_symbols (sys))
267273end
268274
269275function SymbolicIndexingInterface. is_independent_variable (sys:: AbstractSystem , sym:: Symbol )
@@ -284,6 +290,20 @@ SymbolicIndexingInterface.is_time_dependent(::AbstractTimeIndependentSystem) = f
284290
285291SymbolicIndexingInterface. constant_structure (:: AbstractSystem ) = true
286292
293+ function SymbolicIndexingInterface. all_variable_symbols (sys:: AbstractSystem )
294+ syms = variable_symbols (sys)
295+ obs = getproperty .(observed (sys), :lhs )
296+ return isempty (obs) ? syms : vcat (syms, obs)
297+ end
298+
299+ function SymbolicIndexingInterface. all_symbols (sys:: AbstractSystem )
300+ syms = all_variable_symbols (sys)
301+ for other in (parameter_symbols (sys), independent_variable_symbols (sys))
302+ isempty (other) || (syms = vcat (syms, other))
303+ end
304+ return syms
305+ end
306+
287307iscomplete (sys:: AbstractSystem ) = isdefined (sys, :complete ) && getfield (sys, :complete )
288308
289309"""
@@ -303,6 +323,7 @@ for prop in [:eqs
303323 :states
304324 :ps
305325 :tspan
326+ :name
306327 :var_to_name
307328 :ctrls
308329 :defaults
@@ -639,7 +660,7 @@ function states(sys::AbstractSystem)
639660 end
640661 isempty (nonunique_states) && return nonunique_states
641662 # `Vector{Any}` is incompatible with the `SymbolicIndexingInterface`, which uses
642- # `elsymtype = symbolic_type(eltype(_arg))`
663+ # `elsymtype = symbolic_type(eltype(_arg))`
643664 # which inappropriately returns `NotSymbolic()`
644665 if nonunique_states isa Vector{Any}
645666 nonunique_states = _nonum .(nonunique_states)
650671
651672function parameters (sys:: AbstractSystem )
652673 ps = get_ps (sys)
674+ if ps == SciMLBase. NullParameters ()
675+ return []
676+ end
677+ if eltype (ps) <: Pair
678+ ps = first .(ps)
679+ end
653680 systems = get_systems (sys)
654681 unique (isempty (systems) ? ps : [ps; reduce (vcat, namespace_parameters .(systems))])
655682end
0 commit comments