Skip to content

Commit

Permalink
Merge pull request #3201 from BenChung/additional-passes
Browse files Browse the repository at this point in the history
Add a mechanism to add additional passes to the end of structural simplification before completion.
  • Loading branch information
ChrisRackauckas authored Dec 13, 2024
2 parents 51aea4a + daf93ed commit ba842c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/systems/systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ topological sort of the observed equations in `sys`.
+ `fully_determined=true` controls whether or not an error will be thrown if the number of equations don't match the number of inputs, outputs, and equations.
"""
function structural_simplify(
sys::AbstractSystem, io = nothing; simplify = false, split = true,
sys::AbstractSystem, io = nothing; additional_passes = [], simplify = false, split = true,
allow_symbolic = false, allow_parameter = true, conservative = false, fully_determined = true,
kwargs...)
isscheduled(sys) && throw(RepeatedStructuralSimplificationError())
Expand All @@ -46,6 +46,9 @@ function structural_simplify(
not yet supported.
""")
end
for pass in additional_passes
newsys = pass(newsys)
end
if newsys isa ODESystem || has_parent(newsys)
@set! newsys.parent = complete(sys; split, flatten = false)
end
Expand Down
9 changes: 9 additions & 0 deletions test/structural_transformation/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ end
end
end
end

@testset "additional passes" begin
@variables x(t) y(t)
@named sys = ODESystem([D(x) ~ x, y ~ x + t], t)
value = Ref(0)
pass(sys; kwargs...) = (value[] += 1; return sys)
structural_simplify(sys; additional_passes = [pass])
@test value[] == 1
end

0 comments on commit ba842c2

Please sign in to comment.