From eda30b9c5e165798bf64f6170cce148ebce9526e Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 5 Nov 2024 14:20:47 +0530 Subject: [PATCH 1/2] fix: `complete` with `split = false` removes the index cache --- src/systems/abstractsystem.jl | 2 ++ test/odesystem.jl | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 10401d91c5..9a2b2369bd 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -985,6 +985,8 @@ function complete(sys::AbstractSystem; split = true, flatten = true) end @set! sys.ps = ordered_ps end + elseif has_index_cache(sys) + @set! sys.index_cache = nothing end if isdefined(sys, :initializesystem) && get_initializesystem(sys) !== nothing @set! sys.initializesystem = complete(get_initializesystem(sys); split) diff --git a/test/odesystem.jl b/test/odesystem.jl index dfc755da98..d7a2658f63 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -1495,3 +1495,12 @@ end sys2 = complete(sys) @test length(equations(sys2)) == total_eqs end + +@testset "`complete` with `split = false` removes the index cache" begin + @variables x(t) + @parameters p + @mtkbuild sys = ODESystem(D(x) ~ p * t, t) + @test ModelingToolkit.get_index_cache(sys) !== nothing + sys2 = complete(sys; split = false) + @test ModelingToolkit.get_index_cache(sys2) === nothing +end From eaf5edc646b41d41f30878cb0b368756ba0c017c Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 5 Nov 2024 14:20:51 +0530 Subject: [PATCH 2/2] refactor: format --- src/systems/abstractsystem.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 9a2b2369bd..80bc3d44d4 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -3003,8 +3003,8 @@ By default, the resulting system inherits `sys`'s name and description. See also [`compose`](@ref). """ function extend(sys::AbstractSystem, basesys::AbstractSystem; - name::Symbol = nameof(sys), description = description(sys), - gui_metadata = get_gui_metadata(sys)) + name::Symbol = nameof(sys), description = description(sys), + gui_metadata = get_gui_metadata(sys)) T = SciMLBase.parameterless_type(basesys) ivs = independent_variables(basesys) if !(sys isa T)