Skip to content

Commit

Permalink
Merge pull request #2869 from SebastianM-C/smc/subs
Browse files Browse the repository at this point in the history
refactor: avoid substitute warning when not needed
  • Loading branch information
ChrisRackauckas authored Jul 17, 2024
2 parents 421e41e + f45a0fc commit 94cd86b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit 94cd86b

Please sign in to comment.