Skip to content

Commit 835eb6f

Browse files
committed
state_selection: Correct is_not_present condition
The is_present condition is supposed to be equivalent to the variable not appearing in the system at all (for example, it could appear as `a*D(v)`, where `a` ends up aliased to `0`, meaning that we don't notice that it does not appear in the system until we've performed alias analysis. In these kinds of situations, a variable is present in the system if, either: 1. It appears in the graph (i.e. it's used in the equations), or 2. It is irreducible (and was in the alias graph). The condition was trying to check this, but didn't quite get the negations correct, resulting in sub-optimal state selection.
1 parent 9a44828 commit 835eb6f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/structural_transformation/partial_state_selection.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,22 +277,25 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
277277
end
278278
x = diff_to_var[x]
279279
x === nothing && break
280+
isempty(𝑑neighbors(graph, x)) && continue
280281
if !haskey(ag, x)
281282
isred = false
282283
end
283284
end
284285
isred
285286
end
286287
irreducible_set = BitSet()
287-
for (k, (_, v)) in ag
288+
for (k, (c, v)) in ag
288289
isreducible(k) || push!(irreducible_set, k)
289290
isreducible(k) || push!(irreducible_set, k)
291+
iszero(c) && continue
290292
push!(irreducible_set, v)
291293
end
292294
end
293295

294296
is_not_present = v -> isempty(𝑑neighbors(graph, v)) &&
295-
(ag === nothing || (haskey(ag, v) && !(v in irreducible_set)))
297+
(ag === nothing || !haskey(ag, v) || !(v in irreducible_set))
298+
296299
# Derivatives that are either in the dummy derivatives set or ended up not
297300
# participating in the system at all are not considered differential
298301
is_some_diff = let dummy_derivatives_set = dummy_derivatives_set

0 commit comments

Comments
 (0)