From d4f7e8a1392b4aa8b6c3507c706d91ac968eb9d6 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 19 Nov 2024 13:30:37 +0530 Subject: [PATCH 1/2] fix: handle observeds in `get_all_timeseries_indexes` for `split = false` systems --- src/systems/abstractsystem.jl | 18 +++++++++++++----- test/symbolic_indexing_interface.jl | 11 +++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index db2fcb4f10..6d59c5b8ea 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -770,11 +770,19 @@ for traitT in [ is_variable(sys, operation(s)(get_iv(sys))) # DDEs case, to detect x(t - k) push!(ts_idxs, ContinuousTimeseries()) - elseif has_index_cache(sys) && (ic = get_index_cache(sys)) !== nothing - if (ts = get(ic.observed_syms_to_timeseries, s, nothing)) !== nothing - union!(ts_idxs, ts) - elseif (ts = get(ic.dependent_pars_to_timeseries, s, nothing)) !== nothing - union!(ts_idxs, ts) + else + if has_index_cache(sys) && (ic = get_index_cache(sys)) !== nothing + if (ts = get(ic.observed_syms_to_timeseries, s, nothing)) !== nothing + union!(ts_idxs, ts) + elseif (ts = get(ic.dependent_pars_to_timeseries, s, nothing)) !== + nothing + union!(ts_idxs, ts) + end + else + # for split=false systems + if has_observed_with_lhs(sys, sym) + push!(ts_idxs, ContinuousTimeseries()) + end end end end diff --git a/test/symbolic_indexing_interface.jl b/test/symbolic_indexing_interface.jl index 161d926cb2..e46c197dde 100644 --- a/test/symbolic_indexing_interface.jl +++ b/test/symbolic_indexing_interface.jl @@ -213,3 +213,14 @@ end prob = ODEProblem(sys, [], (0.0, 1.0)) @test prob.ps[b] == prob.ps[:b] end + +@testset "`get_all_timeseries_indexes` with non-split systems" begin + @variables x(t) y(t) z(t) + @parameters a + @named sys = ODESystem([D(x) ~ a * x, y ~ 2x, z ~ 0.0], t) + sys = structural_simplify(sys, split = false) + for sym in [x, y, z, x + y, x + a, y / x] + @test only(get_all_timeseries_indexes(sys, sym)) == ContinuousTimeseries() + end + @test isempty(get_all_timeseries_indexes(sys, a)) +end From 0b9d51dbac41d7bf3138fa3f6c5710a79043330a Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 19 Nov 2024 14:39:40 +0530 Subject: [PATCH 2/2] refactor: format --- test/odesystem.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/odesystem.jl b/test/odesystem.jl index 90d1c4c578..02eb80ef85 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -1521,6 +1521,6 @@ end @parameters p[1:2] = [1.0, 2.0] @mtkbuild sys = ODESystem([D(x) ~ x, y^2 ~ x + sum(p)], t) prob = DAEProblem(sys, [D(x) => x, D(y) => D(x) / 2y], [], (0.0, 1.0)) - sol = solve(prob, DFBDF(), abstol=1e-8, reltol=1e-8) + sol = solve(prob, DFBDF(), abstol = 1e-8, reltol = 1e-8) @test sol[x]≈sol[y^2 - sum(p)] atol=1e-5 end