Skip to content

Commit ba842c2

Browse files
Merge pull request #3201 from BenChung/additional-passes
Add a mechanism to add additional passes to the end of structural simplification before completion.
2 parents 51aea4a + daf93ed commit ba842c2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/systems/systems.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ topological sort of the observed equations in `sys`.
2626
+ `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.
2727
"""
2828
function structural_simplify(
29-
sys::AbstractSystem, io = nothing; simplify = false, split = true,
29+
sys::AbstractSystem, io = nothing; additional_passes = [], simplify = false, split = true,
3030
allow_symbolic = false, allow_parameter = true, conservative = false, fully_determined = true,
3131
kwargs...)
3232
isscheduled(sys) && throw(RepeatedStructuralSimplificationError())
@@ -46,6 +46,9 @@ function structural_simplify(
4646
not yet supported.
4747
""")
4848
end
49+
for pass in additional_passes
50+
newsys = pass(newsys)
51+
end
4952
if newsys isa ODESystem || has_parent(newsys)
5053
@set! newsys.parent = complete(sys; split, flatten = false)
5154
end

test/structural_transformation/utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ end
152152
end
153153
end
154154
end
155+
156+
@testset "additional passes" begin
157+
@variables x(t) y(t)
158+
@named sys = ODESystem([D(x) ~ x, y ~ x + t], t)
159+
value = Ref(0)
160+
pass(sys; kwargs...) = (value[] += 1; return sys)
161+
structural_simplify(sys; additional_passes = [pass])
162+
@test value[] == 1
163+
end

0 commit comments

Comments
 (0)