Skip to content

Commit 4ee1990

Browse files
committed
Handle self-alias in a differentiation chain more carefully
1 parent 9a44828 commit 4ee1990

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/systems/alias_elimination.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
732732
c, dr = reach₌[idx]
733733
@assert c == 1
734734
end
735+
dr in stem_set && break
735736
var_to_diff[prev_r] = dr
736737
push!(updated_diff_vars, prev_r)
737738
prev_r = dr
@@ -901,10 +902,14 @@ function alias_eliminate_graph!(graph, var_to_diff, mm_orig::SparseMatrixCLIL)
901902
# RHS or its derivaitves must still exist in the system to be valid aliases.
902903
needs_update = false
903904
function contains_v_or_dv(var_to_diff, graph, v)
905+
counter = 0
904906
while true
905907
isempty(𝑑neighbors(graph, v)) || return true
906908
v = var_to_diff[v]
907909
v === nothing && return false
910+
counter += 1
911+
counter > 10_000 &&
912+
error("Internal error: there's an infinite loop in the `var_to_diff` graph.")
908913
end
909914
end
910915
for (v, (c, a)) in ag

0 commit comments

Comments
 (0)