From be29b20697d200d0f6026bddf760d19ab3fef98b Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 7 Jan 2026 11:15:47 +0530 Subject: [PATCH 1/2] fix: remove bindings, initial conditions for unused variables --- lib/ModelingToolkitTearing/src/tearingstate.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/ModelingToolkitTearing/src/tearingstate.jl b/lib/ModelingToolkitTearing/src/tearingstate.jl index b9066f1..e1bd180 100644 --- a/lib/ModelingToolkitTearing/src/tearingstate.jl +++ b/lib/ModelingToolkitTearing/src/tearingstate.jl @@ -287,7 +287,24 @@ function TearingState(sys::System, source_info::Union{Nothing, MTKBase.EquationS # build incidence graph graph = build_incidence_graph(length(fullvars), symbolic_incidence, var2idx) + # Identify unknowns that do not appear in any equations and are thus not present in + # `fullvars`. The bindings and initial conditions for these variables should be removed. + for v in fullvars + delete!(dvs, v) + arr, _ = MTKBase.split_indexed_var(v) + delete!(dvs, arr) + end + new_binds = copy(parent(bindings(sys))) + new_ics = copy(initial_conditions(sys)) + for var in dvs + arr, _ = MTKBase.split_indexed_var(var) + delete!(new_binds, arr) + delete!(new_ics, arr) + end + @set! sys.eqs = eqs + @set! sys.bindings = new_binds + @set! sys.initial_conditions = new_ics eq_to_diff = StateSelection.DiffGraph(nsrcs(graph)) From a80c86a241c49b862d4bf6aab4db68065512d095 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 7 Jan 2026 11:44:51 +0530 Subject: [PATCH 2/2] refactor: remove unnecessary `@assert` --- lib/ModelingToolkitTearing/src/reassemble.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ModelingToolkitTearing/src/reassemble.jl b/lib/ModelingToolkitTearing/src/reassemble.jl index b3c40f3..b3b1a01 100644 --- a/lib/ModelingToolkitTearing/src/reassemble.jl +++ b/lib/ModelingToolkitTearing/src/reassemble.jl @@ -551,7 +551,6 @@ function get_linear_scc_linsol(state::TearingState, alg_eqs::Vector{Int}, for (varidx, var) in enumerate(vars) a, resid, islinear = Symbolics.linear_expansion(resid, var) islinear || return nothing - @assert islinear A[eqidx, varidx] = a end # `-` is important! `b` is on the other side of the equality.