Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mechanism to add additional passes to the end of structural simplification before completion. #3201

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading