From 96bf961d47a64701aaf2dc3eefd5def39dfa3670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Miclu=C8=9Ba-C=C3=A2mpeanu?= Date: Wed, 17 Jul 2024 19:24:18 +0300 Subject: [PATCH 1/2] refactor: avoid substitute warning when not needed --- src/systems/abstractsystem.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 2798349ae6..b701f3c821 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -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 From f45a0fcb2d38f3fc8951bc5f1ab68d326965231d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Miclu=C8=9Ba-C=C3=A2mpeanu?= Date: Wed, 17 Jul 2024 19:31:37 +0300 Subject: [PATCH 2/2] test: add test for warnings in `substitute` --- test/odesystem.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/odesystem.jl b/test/odesystem.jl index d54baa8a93..68c50d4d7f 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -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])