Skip to content

Commit 1898c66

Browse files
authored
Merge pull request #2109 from SciML/myb/alias_fix2
Make sure that the algebraic linear subsystem doesn't have linear dependence
2 parents 01847c4 + 67eb64c commit 1898c66

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/systems/alias_elimination.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ function aag_bareiss!(graph, var_to_diff, mm_orig::SparseMatrixCLIL{T, Ti}) wher
548548
is_linear_variables = is_algebraic.(1:length(var_to_diff))
549549
for i in 𝑠vertices(graph)
550550
# only consider linear algebraic equations
551-
(i in linear_equations_set && all(is_algebraic, 𝑠neighbors(graph, i))) && continue
551+
(i in linear_equations_set && all(is_algebraic, 𝑠neighbors(graph, i))) &&
552+
continue
552553
for j in 𝑠neighbors(graph, i)
553554
is_linear_variables[j] = false
554555
end
@@ -956,11 +957,14 @@ function alias_eliminate_graph!(state::TransformationState, mm_orig::SparseMatri
956957

957958
if needs_update
958959
mm = reduce!(copy(echelon_mm), mm_orig, ag, size(echelon_mm, 1))
959-
for (ei, e) in enumerate(mm.nzrows)
960-
set_neighbors!(graph, e, mm.row_cols[ei])
961-
end
962-
update_graph_neighbors!(graph, ag)
963960
end
961+
# applying new `ag` to `mm` might lead to linear dependence, so we have to
962+
# re-run Bareiss.
963+
mm, = aag_bareiss!(graph, var_to_diff, mm)
964+
for (ei, e) in enumerate(mm.nzrows)
965+
set_neighbors!(graph, e, mm.row_cols[ei])
966+
end
967+
update_graph_neighbors!(graph, ag)
964968

965969
complete_mm = reduce!(copy(echelon_mm), mm_orig, complete_ag, size(echelon_mm, 1))
966970
return ag, mm, complete_ag, complete_mm

0 commit comments

Comments
 (0)