Skip to content

Commit d5f3a26

Browse files
committed
Fix isvariable
1 parent 1c091d4 commit d5f3a26

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import Symbolics: rename, get_variables!, _solve, hessian_sparsity,
5252
ParallelForm, SerialForm, MultithreadedForm, build_function,
5353
unflatten_long_ops, rhss, lhss, prettify_expr, gradient,
5454
jacobian, hessian, derivative, sparsejacobian, sparsehessian,
55-
substituter, scalarize
55+
substituter, scalarize, getparent
5656

5757
import DiffEqBase: @add_kwonly
5858

src/utils.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ isdiffeq(eq) = isdifferential(eq.lhs)
210210
isdifference(expr) = istree(expr) && operation(expr) isa Difference
211211
isdifferenceeq(eq) = isdifference(eq.lhs)
212212

213-
isvariable(x) = x isa Symbolic && hasmetadata(x, VariableSource)
213+
function isvariable(x)
214+
x isa Symbolic || return false
215+
p = getparent(x, nothing)
216+
p === nothing || (x = p)
217+
hasmetadata(x, VariableSource)
218+
end
214219

215220
vars(x::Sym; op=Differential) = Set([x])
216221
vars(exprs::Symbolic; op=Differential) = vars([exprs]; op=op)

src/variables.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Symbolics.option_to_metadata_type(::Val{:input}) = VariableInput
1212
Symbolics.option_to_metadata_type(::Val{:output}) = VariableOutput
1313

1414
function isvarkind(m, x)
15-
p = Symbolics.getparent(x, nothing)
15+
p = getparent(x, nothing)
1616
p === nothing || (x = p)
1717
getmetadata(x, m, false)
1818
end

test/odesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ eqs = [
399399
@test isequal(@nonamespace(sys.y), unwrap(y))
400400
@test isequal(@nonamespace(sys.p), unwrap(p))
401401
@test_nowarn sys.x, sys.y, sys.p
402+
@test ModelingToolkit.isvariable(Symbolics.unwrap(x[1]))
402403

403404
# Mixed Difference Differential equations
404405
@parameters t a b c d

0 commit comments

Comments
 (0)