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

refactor: avoid substitute warning when not needed #2869

Merged
merged 2 commits into from
Jul 17, 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
6 changes: 4 additions & 2 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2600,8 +2600,10 @@ end

keytype(::Type{<:Pair{T, V}}) where {T, V} = T
function Symbolics.substitute(sys::AbstractSystem, rules::Union{Vector{<:Pair}, Dict})
if has_continuous_domain(sys) && get_continuous_events(sys) !== nothing ||
has_discrete_events(sys) && get_discrete_events(sys) !== nothing
if has_continuous_domain(sys) && get_continuous_events(sys) !== nothing &&
!isempty(get_continuous_events(sys)) ||
has_discrete_events(sys) && get_discrete_events(sys) !== nothing &&
!isempty(get_discrete_events(sys))
@warn "`substitute` only supports performing substitutions in equations. This system has events, which will not be updated."
end
if keytype(eltype(rules)) <: Symbol
Expand Down
3 changes: 2 additions & 1 deletion test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ vars_sub2 = @variables s2(t)
@named partial_sub = ODESystem(Equation[], t, vars_sub2, [])
@named sub = extend(partial_sub, sub)

new_sys2 = complete(substitute(sys2, Dict(:sub => sub)))
# no warnings for systems without events
new_sys2 = @test_nowarn complete(substitute(sys2, Dict(:sub => sub)))
Set(unknowns(new_sys2)) == Set([new_sys2.x1, new_sys2.sys1.x1,
new_sys2.sys1.sub.s1, new_sys2.sys1.sub.s2,
new_sys2.sub.s1, new_sys2.sub.s2])
Expand Down
Loading