Skip to content

Commit 2308aeb

Browse files
committed
Clean up and fix edge case return ordering
1 parent 621a5ac commit 2308aeb

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/structural_transformation/pantelides.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ function pantelides!(state::TransformationState, ag::Union{AliasGraph, Nothing}
9696
var′ === nothing && break
9797
var = var′
9898
end
99-
if !isempty(𝑑neighbors(graph, var)) || (ag !== nothing && haskey(ag, var))
100-
if haskey(ag, var)
99+
if !isempty(𝑑neighbors(graph, var))
100+
if ag !== nothing && haskey(ag, var)
101101
# TODO: remove lower diff vars from whitelist
102102
c, a = ag[var]
103103
iszero(c) || (varwhitelist[a] = true)
@@ -107,7 +107,6 @@ function pantelides!(state::TransformationState, ag::Union{AliasGraph, Nothing}
107107
end
108108
end
109109
end
110-
@show varwhitelist
111110

112111
if nnonemptyeqs > count(varwhitelist)
113112
throw(InvalidSystemException("System is structurally singular"))

src/structural_transformation/partial_state_selection.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,13 @@ function partial_state_selection_graph!(structure::SystemStructure, var_eq_match
157157
var_eq_matching
158158
end
159159

160-
function dummy_derivative_graph!(state::TransformationState, jac = nothing, ag = nothing;
160+
function dummy_derivative_graph!(state::TransformationState, jac = nothing,
161+
(ag, diff_va) = (nothing, nothing);
161162
kwargs...)
162163
state.structure.solvable_graph === nothing && find_solvables!(state; kwargs...)
163-
var_eq_matching = complete(pantelides!(state, ag === nothing ? nothing : first(ag)))
164+
var_eq_matching = complete(pantelides!(state, ag))
164165
complete!(state.structure)
165-
dummy_derivative_graph!(state.structure, var_eq_matching, jac, ag)
166+
dummy_derivative_graph!(state.structure, var_eq_matching, jac, (ag, diff_va))
166167
end
167168

168169
function compute_diff_level(diff_to_x)
@@ -185,7 +186,6 @@ end
185186
function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, jac,
186187
(ag, diff_va))
187188
@unpack eq_to_diff, var_to_diff, graph = structure
188-
display(structure)
189189
diff_to_eq = invview(eq_to_diff)
190190
diff_to_var = invview(var_to_diff)
191191
invgraph = invview(graph)
@@ -197,7 +197,6 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
197197
dummy_derivatives = Int[]
198198
col_order = Int[]
199199
nvars = ndsts(graph)
200-
@info "" var_eq_matching
201200
for vars in var_sccs
202201
eqs = [var_eq_matching[var] for var in vars if var_eq_matching[var] !== unassigned]
203202
isempty(eqs) && continue
@@ -249,15 +248,17 @@ function dummy_derivative_graph!(structure::SystemStructure, var_eq_matching, ja
249248
vars = [diff_to_var[var] for var in vars if diff_to_var[var] !== nothing]
250249
end
251250
end
252-
n_dummys = length(dummy_derivatives)
253-
needed = count(x -> x isa Int, diff_to_eq) - n_dummys
254-
n = 0
255-
for v in diff_va
256-
c, a = ag[v]
257-
n += 1
258-
push!(dummy_derivatives, iszero(c) ? v : a)
259-
needed == n && break
260-
continue
251+
if diff_va !== nothing
252+
n_dummys = length(dummy_derivatives)
253+
needed = count(x -> x isa Int, diff_to_eq) - n_dummys
254+
n = 0
255+
for v in diff_va
256+
c, a = ag[v]
257+
n += 1
258+
push!(dummy_derivatives, iszero(c) ? v : a)
259+
needed == n && break
260+
continue
261+
end
261262
end
262263

263264
dummy_derivatives_set = BitSet(dummy_derivatives)

src/systems/alias_elimination.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function alias_eliminate_graph!(state::TransformationState)
88
mm = linear_subsys_adjmat(state)
99
if size(mm, 1) == 0
1010
ag = AliasGraph(ndsts(state.structure.graph))
11-
return ag, ag, mm, mm, BitSet() # No linear subsystems
11+
return ag, mm, ag, mm, BitSet() # No linear subsystems
1212
end
1313

1414
@unpack graph, var_to_diff = state.structure

0 commit comments

Comments
 (0)