Skip to content

Commit

Permalink
Merge pull request #3105 from AayushSabharwal/as/callable-params-topsort
Browse files Browse the repository at this point in the history
fix: handle unknowns inside callable parameters when topsorting equations
  • Loading branch information
ChrisRackauckas authored Oct 12, 2024
2 parents 535d1f4 + c3deaf9 commit 7b451b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
StaticArrays = "0.10, 0.11, 0.12, 1.0"
SymbolicIndexingInterface = "0.3.31"
SymbolicUtils = "3.7"
Symbolics = "6.12"
Symbolics = "6.14"
URIs = "1"
UnPack = "0.1, 1.0"
Unitful = "1.1"
Expand Down
8 changes: 8 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ function vars!(vars, eq::Equation; op = Differential)
end
function vars!(vars, O; op = Differential)
if isvariable(O)
if iscalledparameter(O)
f = getcalledparameter(O)
push!(vars, f)
for arg in arguments(O)
vars!(vars, arg; op)
end
return vars
end
return push!(vars, O)
end
if symbolic_type(O) == NotSymbolic() && O isa AbstractArray
Expand Down
8 changes: 8 additions & 0 deletions test/structural_transformation/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ se = collect(StructuralTransformations.edges(graph))
@test se == mapreduce(vcat, enumerate(graph.fadjlist)) do (s, d)
StructuralTransformations.BipartiteEdge.(s, d)
end

@testset "observed2graph handles unknowns inside callable parameters" begin
@variables x(t) y(t)
@parameters p(..)
g, _ = ModelingToolkit.observed2graph([y ~ p(x), x ~ 0], [y, x])
@test ModelingToolkit.𝑠neighbors(g, 1) == [2]
@test ModelingToolkit.𝑑neighbors(g, 2) == [1]
end

0 comments on commit 7b451b4

Please sign in to comment.