Skip to content

Commit

Permalink
fix: fix timeseries_parameter_index for array symbolics
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 24, 2024
1 parent 8781223 commit 994b2db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/systems/index_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,16 @@ function SymbolicIndexingInterface.timeseries_parameter_index(ic::IndexCache, sy
sym = get(ic.symbol_to_variable, sym, nothing)
sym === nothing && return nothing
end
sym = unwrap(sym)
idx = check_index_map(ic.discrete_idx, sym)
idx === nothing ||
return ParameterTimeseriesIndex(idx.clock_idx, (idx.buffer_idx, idx.idx_in_clock))
iscall(sym) && operation(sym) == getindex || return nothing
args = arguments(sym)
idx = timeseries_parameter_index(ic, args[1])
idx === nothing && return nothing
ParameterIndex(idx.portion, (idx.idx..., args[2:end]...), idx.validate_size)
return ParameterTimeseriesIndex(
idx.timeseries_idx, (idx.parameter_idx..., args[2:end]...))
end

function check_index_map(idxmap, sym)
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 @@ -224,3 +224,14 @@ end
end
@test isempty(get_all_timeseries_indexes(sys, a))
end

@testset "`timeseries_parameter_index` on unwrapped scalarized timeseries parameter" begin
@variables x(t)[1:2]
@parameters p(t)[1:2, 1:2]
ev = [x[1] ~ 2.0] => [p ~ -ones(2, 2)]
@mtkbuild sys = ODESystem(D(x) ~ p * x, t; continuous_events = [ev])
p = ModelingToolkit.unwrap(p)
@test timeseries_parameter_index(sys, p) === ParameterTimeseriesIndex(1, (1, 1))
@test timeseries_parameter_index(sys, p[1, 1]) ===
ParameterTimeseriesIndex(1, (1, 1, 1, 1))
end

0 comments on commit 994b2db

Please sign in to comment.