Skip to content

Commit b991a62

Browse files
Merge pull request #3221 from AayushSabharwal/as/nosplit-timeseries
fix: handle observeds in `get_all_timeseries_indexes` for `split = false` systems
2 parents 21dff0c + 0b9d51d commit b991a62

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/systems/abstractsystem.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,19 @@ for traitT in [
770770
is_variable(sys, operation(s)(get_iv(sys)))
771771
# DDEs case, to detect x(t - k)
772772
push!(ts_idxs, ContinuousTimeseries())
773-
elseif has_index_cache(sys) && (ic = get_index_cache(sys)) !== nothing
774-
if (ts = get(ic.observed_syms_to_timeseries, s, nothing)) !== nothing
775-
union!(ts_idxs, ts)
776-
elseif (ts = get(ic.dependent_pars_to_timeseries, s, nothing)) !== nothing
777-
union!(ts_idxs, ts)
773+
else
774+
if has_index_cache(sys) && (ic = get_index_cache(sys)) !== nothing
775+
if (ts = get(ic.observed_syms_to_timeseries, s, nothing)) !== nothing
776+
union!(ts_idxs, ts)
777+
elseif (ts = get(ic.dependent_pars_to_timeseries, s, nothing)) !==
778+
nothing
779+
union!(ts_idxs, ts)
780+
end
781+
else
782+
# for split=false systems
783+
if has_observed_with_lhs(sys, sym)
784+
push!(ts_idxs, ContinuousTimeseries())
785+
end
778786
end
779787
end
780788
end

test/odesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ end
15211521
@parameters p[1:2] = [1.0, 2.0]
15221522
@mtkbuild sys = ODESystem([D(x) ~ x, y^2 ~ x + sum(p)], t)
15231523
prob = DAEProblem(sys, [D(x) => x, D(y) => D(x) / 2y], [], (0.0, 1.0))
1524-
sol = solve(prob, DFBDF(), abstol=1e-8, reltol=1e-8)
1524+
sol = solve(prob, DFBDF(), abstol = 1e-8, reltol = 1e-8)
15251525
@test sol[x]sol[y^2 - sum(p)] atol=1e-5
15261526
end
15271527

test/symbolic_indexing_interface.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,14 @@ end
213213
prob = ODEProblem(sys, [], (0.0, 1.0))
214214
@test prob.ps[b] == prob.ps[:b]
215215
end
216+
217+
@testset "`get_all_timeseries_indexes` with non-split systems" begin
218+
@variables x(t) y(t) z(t)
219+
@parameters a
220+
@named sys = ODESystem([D(x) ~ a * x, y ~ 2x, z ~ 0.0], t)
221+
sys = structural_simplify(sys, split = false)
222+
for sym in [x, y, z, x + y, x + a, y / x]
223+
@test only(get_all_timeseries_indexes(sys, sym)) == ContinuousTimeseries()
224+
end
225+
@test isempty(get_all_timeseries_indexes(sys, a))
226+
end

0 commit comments

Comments
 (0)