Skip to content

Commit

Permalink
fix: handle observeds in get_all_timeseries_indexes for `split = fa…
Browse files Browse the repository at this point in the history
…lse` systems
  • Loading branch information
AayushSabharwal committed Nov 19, 2024
1 parent 57e1a43 commit e96b33f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,18 @@ 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
Expand Down
11 changes: 11 additions & 0 deletions test/symbolic_indexing_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e96b33f

Please sign in to comment.