fix: [AI] fix bug caused by duplicate alias equations from eliminate_perfect_aliases!#4523
Merged
Merged
Conversation
3f53de6 to
34b1cf8
Compare
When all variables in an alias group have equal state_priority (common for rotation matrix elements), findmax on equal values returned the first element in insertion order rather than the physics variable. For R[i,j] alias groups of ~18 variables, the physics variable (body₊frame_a₊R[i,j]) has vtd=Int and appears in ~9 equations, while visualization shape variables appear in only 1. Picking a shape variable as target and then eliminating the physics variable causes structural singularity in Pantelides. Fix: when priorities are tied, prefer the variable with the most equation appearances. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ect_aliases! When a sticky (high state_priority) non-target variable is directly aliased to a zero-priority variable in the same group, the c1/c2 removal check correctly keeps the equation (c1 ≠ c2). After the substitution loop rewrites that zero-priority variable to the group target, the surviving equation becomes structurally identical to the direct alias between the sticky variable and the target — a redundant duplicate. Multiple such duplicates over-constrain the bipartite graph and cause Pantelides to fail on downstream acceleration variables. Fix: after the substitution loop, scan surviving candidate equations for pairs with the same (v_a, v_b) variable endpoints and remove all but the first. This is O(n) in the number of candidate alias equations. The equation-count tiebreaker in pick_alias_target is retained as a secondary heuristic to prefer targets that already have derivative chains in var_to_diff, reducing unnecessary var_derivative! calls. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34b1cf8 to
dbfd91b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The commit messages describe this pretty well. I'm trying to get Claude to write a test.