Skip to content

Commit e2df0e8

Browse files
committed
Add maxiter and error msg
1 parent 080c40e commit e2df0e8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/systems/diffeqs/index_reduction.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ function matching(edges, nvars, active=trues(nvars))
102102
return assign
103103
end
104104

105-
function pantelides(sys::ODESystem)
105+
function pantelides(sys::ODESystem; kwargs...)
106106
edges, fullvars, vars_asso = sys2bigraph(sys)
107-
return pantelides!(edges, fullvars, vars_asso)
107+
return pantelides!(edges, fullvars, vars_asso; kwargs...)
108108
end
109109

110-
function pantelides!(edges, vars, vars_asso; maxiter = 100_000_000)
110+
function pantelides!(edges, vars, vars_asso; maxiter = 8000)
111111
neqs = length(edges)
112112
nvars = length(vars)
113113
assign = zeros(Int, nvars)
@@ -116,13 +116,15 @@ function pantelides!(edges, vars, vars_asso; maxiter = 100_000_000)
116116
for k in 1:neqs′
117117
i = k
118118
pathfound = false
119+
# In practice, `maxiter=8000` should never be reached, otherwise, the
120+
# index would be on the order of thousands.
119121
for _ in 1:maxiter
120122
# run matching on (dx, y) variables
121123
active = vars_asso .== 0
122124
vcolor = falses(nvars)
123125
ecolor = falses(neqs)
124126
pathfound = match_equation!(edges, i, assign, active, vcolor, ecolor)
125-
pathfound && break
127+
pathfound && break # terminating condition
126128
# for every colored V-node j
127129
for j in eachindex(vcolor); vcolor[j] || continue
128130
# introduce a new variable
@@ -154,6 +156,7 @@ function pantelides!(edges, vars, vars_asso; maxiter = 100_000_000)
154156
end
155157
i = eqs_asso[i]
156158
end # for _ in 1:maxiter
159+
pathfound || error("maxiter=$maxiter reached! File a bug report if your system has a reasonable index (<100), and you are using the default `maxiter`. Try to increase the maxiter by `pantelides(sys::ODESystem; maxiter=1_000_000)` if your system has an incredibly high index and it is truly extremely large.")
157160
end # for k in 1:neqs′
158161
return edges, assign, vars_asso, eqs_asso
159162
end

0 commit comments

Comments
 (0)