state_priority ineffective across alias equations of unequal differentiation depth: singleton-SCC demotion that #103's block merge cannot reach (forced by tier mismatch)
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 30/100
調査の方向性
dummy_derivative_graph! と merge_dummy_derivative_blocks から始め、次に fbc/wheel-state-selection ブランチ上で MultibodyComponents.tests.WheelInWorld を使ってその挙動を再現します。アプローチを選ぶ前に、3つの設計オプションと既存の #103 のコンテキストを確認してください。完了条件は、深さが異なるエイリアスのケースについて合意された解決策があり、state_priority が意図どおりに動作することを示す回帰チェックがあることです。
索引モデルが issue の本文から書いたものです。
説明
Summary
state_priority cannot promote a variable whose connection to the rest of the system is an alias equation that Pantelides differentiates less deeply than the alternative variable's chain. The variable's derivative ends up alone in a singleton SCC matched to the differentiated alias equation and is demoted unconditionally — state_priority 30 (or 3000) loses to 15. This is a sibling of #101 that #103's merge_dummy_derivative_blocks cannot reach, and (unlike #101) it is not fixable by priority-aware tie-breaking alone: the demotion is forced by a differentiation-depth mismatch.
Observed on MultibodyComponents.tests.WheelInWorld: the RollingWheel wrapper declares x/z/angles/der_angles (priority 20/30) aliased to RollingWheelJoint's internal coordinates (then 15/15/15/30); the internal low-priority variables were always selected.
Mechanism (debug-traced)
With an env-gated print in dummy_derivative_graph! (per-SCC vars/extended_sp after the priority sort) and in merge_dummy_derivative_blocks (partner analysis for singleton SCCs), on WheelInWorld with the wrapper's angles at priority 3000 for contrast:
SS_DEBUG_MERGE singleton scc 111: var 3 matched diff-eq 103
partner var 6: matched=u is_deriv=true has_deriv=true present=true scc_of_candidate=0
SS_DEBUG_MERGE singleton scc 113: var 2 matched diff-eq 102
partner var 5: matched=u is_deriv=true has_deriv=true present=true scc_of_candidate=0
SS_DEBUG_MERGE singleton scc 115: var 1 matched diff-eq 101
partner var 4: matched=u is_deriv=true has_deriv=true present=true scc_of_candidate=0
...
SS_DEBUG_DD scc: nvars=1 neqs=1
vars (ascending sp): [(3, 3000)]
demote(J): var 3 # and likewise vars 2, 1
vars 1–3 = D(wheel.angles[i]) (priority 3000), vars 4–6 = D(wheel.wheeljoint.angles[i]) (priority 15), eqs 101–103 = the differentiated alias equations D(wheel.angles[i]) ~ D(wheel.wheeljoint.angles[i]).
Chain of causes:
- The joint's internal equations force
wheeljoint.anglesto be differentiated twice (the rolling constraints are velocity-level), while the alias equationwheel.angles ~ wheeljoint.anglesonly needs one differentiation. So at the top tier, the only highest-order derivative incident to the differentiated alias equation isD(wheel.angles[i])—D(wheeljoint.angles[i])is mid-chain (has_deriv=true). - The maximum matching must therefore match the differentiated alias equation to
D(wheel.angles[i])(the invariantvar_to_diff[var] === nothing → else "Invalid SCC"excludes mid-chain variables). The partner stays unmatched (matched=u). find_var_sccsputs the matched variable alone in a singleton SCC;merge_dummy_derivative_blocks(#103) only merges via partners that are matched candidates of another SCC (scc_of_candidate[var2] == 0here), so no merge.- The singleton block demotes its only candidate unconditionally, regardless of priority.
I also tried the naive fix of adding unmatched, present derivative partners as demotion candidates in dummy_derivative_graph! — it cannot fire, because the partner fails the highest-tier requirement (var_to_diff[var2] !== nothing); demoting a mid-chain derivative from a tier-1 block conflicts with the tier-descent bookkeeping of the surrounding while-loop.
Note the contrast with the wrapper's scalar x/z in the same model: their alias chains happen to be differentiated to the same depth as the joint's (through the body's translational dynamics), and priority works exactly as intended there. The failure is specific to unequal differentiation depth across the alias.
Why this is hard / design options
Within the static dummy-derivative scheme, the demotion is structurally forced by minimal differentiation: nothing requires the alias equation's second derivative, so the high-priority side's chain is too short to compete at the tier where the choice is made. Options I can see:
- Over-differentiate alias-like equations connecting chains of unequal depth (equalize depth, then the existing priority sort decides at the top tier and the descent compares the lower tiers). Cost: extra differentiated equations/variables.
- Tier-aware demotion: allow a block to demote a mid-chain alternative and reconcile with the descent bookkeeping (essentially dynamic re-tiering).
- Treat it as a documentation/modeling constraint: priorities only act among chains of equal differentiation depth (this is what we've done in MultibodyComponents for now — the wrapper's duplicated coordinates are documented as unselectable, and the deliberate priorities were moved to the joint's own coordinates: JuliaComputing/MultibodyComponents.jl PR following this issue).
Priority-aware matching (#96) alone does not help here: the matching has no freedom — only one top-tier variable is incident to the differentiated alias equation.
Reproduction
MultibodyComponents.jl branch fbc/wheel-state-selection:
using ModelingToolkit, MultibodyComponents
@named model = MultibodyComponents.tests.WheelInWorld()
ssys = multibody(model)
unknowns(ssys) # wheel.wheeljoint.* selected; wheel.* (wrapper, priority 20/30) never selectable
(Wrapper-variable selection requires the wrapper's der_angles ~ D(angles) relation, included on that branch; without it the wrapper variables have no derivative chain at all and are trivially unselectable.) Versions: StateSelection fix-state-priority-merged-blocks (PR#103 head), ModelingToolkitTearing from lib/, MTK v11.26.8. The debug instrumentation is ~15 lines in dummy_derivative_graph!/merge_dummy_derivative_blocks; happy to push it behind an env gate if useful.
- 主要言語
- Julia
- スター
- 7
- フォーク
- 10
- 平均マージ
- 5日 11時間
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaComputing/StateSelection.jl のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
JuliaComputing/StateSelection.jl#98 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
JuliaComputing/StateSelection.jl#95 · コメント 6 件 ·
JuliaComputing/StateSelection.jl の issue をすべて見る
似ている issue
-
`enzymexla.linalg.lu` lowering fails for a tall matrix: the permutation is built with the pivot typeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
EnzymeAD/Enzyme-JAX#3286 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
SciML/LinearSolve.jl#1359 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
EnzymeAD/ReactantNitro.jl#13 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信