File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -717,6 +717,9 @@ function complete(
717717 @set! sys. parameter_bindings_graph = nothing
718718 end
719719 if split && has_index_cache (sys)
720+ # The `IndexCache` constructor uses `is_parameter` and family. If the system already
721+ # contains an index cache, it'll get wrong results.
722+ @set! sys. index_cache = nothing
720723 @set! sys. index_cache = IndexCache (sys)
721724 # Ideally we'd do `get_ps` but if `flatten = false`
722725 # we don't get all of them. So we call `parameters`.
Original file line number Diff line number Diff line change 11using ModelingToolkitBase, SymbolicIndexingInterface, SciMLStructures
2- using ModelingToolkitBase: t_nounits as t
2+ using ModelingToolkitBase: t_nounits as t, D_nounits as D, SymbolicDiscreteCallback
3+ using Symbolics: unwrap
4+ using Setfield: @set!
35using Test
46
57# Ensure indexes of array symbolics are cached appropriately
123125 @test length (parameters (ss)) == 1
124126 @test ! is_timeseries_parameter (ss, p_1)
125127end
128+
129+ @testset " Old index cache doesn't influence new index cache construction" begin
130+ @variables x (t)
131+ @discretes d (t)
132+ @named sys = System ([D (x) ~ t + 2 ], t)
133+ sys = complete (sys)
134+ @set! sys. discrete_events = [SymbolicDiscreteCallback (x > 1 , [d ~ Pre (d) + 1 ]; discrete_parameters = [d])]
135+ @set! sys. ps = [unwrap (d)]
136+ # This used to throw, since `d` wasn't a parameter before and thus not present in
137+ # the `IndexCache`. This failed the construction of the subsequent `IndexCache`, since
138+ # it uses `is_parameter` to check if `discrete_parameters` are in the parameters of
139+ # the system.
140+ @test_nowarn complete (sys)
141+ end
You can’t perform that action at this time.
0 commit comments