Skip to content

Commit 94cd86b

Browse files
Merge pull request #2869 from SebastianM-C/smc/subs
refactor: avoid substitute warning when not needed
2 parents 421e41e + f45a0fc commit 94cd86b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/systems/abstractsystem.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,8 +2600,10 @@ end
26002600

26012601
keytype(::Type{<:Pair{T, V}}) where {T, V} = T
26022602
function Symbolics.substitute(sys::AbstractSystem, rules::Union{Vector{<:Pair}, Dict})
2603-
if has_continuous_domain(sys) && get_continuous_events(sys) !== nothing ||
2604-
has_discrete_events(sys) && get_discrete_events(sys) !== nothing
2603+
if has_continuous_domain(sys) && get_continuous_events(sys) !== nothing &&
2604+
!isempty(get_continuous_events(sys)) ||
2605+
has_discrete_events(sys) && get_discrete_events(sys) !== nothing &&
2606+
!isempty(get_discrete_events(sys))
26052607
@warn "`substitute` only supports performing substitutions in equations. This system has events, which will not be updated."
26062608
end
26072609
if keytype(eltype(rules)) <: Symbol

test/odesystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ vars_sub2 = @variables s2(t)
972972
@named partial_sub = ODESystem(Equation[], t, vars_sub2, [])
973973
@named sub = extend(partial_sub, sub)
974974

975-
new_sys2 = complete(substitute(sys2, Dict(:sub => sub)))
975+
# no warnings for systems without events
976+
new_sys2 = @test_nowarn complete(substitute(sys2, Dict(:sub => sub)))
976977
Set(unknowns(new_sys2)) == Set([new_sys2.x1, new_sys2.sys1.x1,
977978
new_sys2.sys1.sub.s1, new_sys2.sys1.sub.s2,
978979
new_sys2.sub.s1, new_sys2.sub.s2])

0 commit comments

Comments
 (0)