feat: add pass which removes equations incident on a single variable#4454
feat: add pass which removes equations incident on a single variable#4454AayushSabharwal wants to merge 1 commit intomasterfrom
Conversation
| union!(eqs_to_substitute, 𝑑neighbors(graph, ivar)) | ||
|
|
||
| v = var_to_diff[ivar] | ||
| while v isa Int |
There was a problem hiding this comment.
would this be more readable if it was while !isnothing(v)?
There was a problem hiding this comment.
I was hoping isa Int would help type inference better. And iirc since v::Union{Int, Nothing}, codegen will union-split the call to isnothing whereas isa is a builtin, so there's only ever one thing to call.
There was a problem hiding this comment.
Also this is just personal preference but I like reading var === nothing over isnothing(var).
There was a problem hiding this comment.
I'd also be fine with !(isa Nothing). isa Int just feels kind of fragile (e.g. it would break if we changed incidence to Int32)
There was a problem hiding this comment.
Ah, I see your point.
| for ieq in 𝑠vertices(graph) | ||
| empty!(snbors) | ||
| append!(snbors, 𝑠neighbors(graph, ieq)) | ||
| setdiff!(snbors, vars_to_rm_set) |
There was a problem hiding this comment.
is this needed to prevent needing to recompute the neighbors after each variable removal? IMO it could use a comment if so.
There was a problem hiding this comment.
Will add a comment (and just spam some more in general)
|
I also just realized that this pass doesn't need to substitute, since if the eliminated variable is removed from |
|
That's a very nice simplification! |
b3183de to
cca4564
Compare
|
Addressed the comments |
|
A multibody model is now simplifying to 25 variables instead of 17 because of the latest changes on this PR. |
|
any idea what the difference is? |
|
A bunch of algebraic equations that should have been torn but weren't. |
|
We also need to make sure to deal with #4458 for this (and add a test) |
|
Okay, we do need to substitute. If we eliminate a variable |
|
The problematic multibody system is handled by changing the tearing algorithm to the old |
|
Weirdly either |
|
I'm certain though, there was a point where this pass + |
This avoids cases where pantelides ends up choosing a bad matching and unnecessarily differentiates the kind of equations removed by this pass.