Skip to content

Alias aware state priority - #3093

Open
YingboMa wants to merge 8 commits into
masterfrom
myb/dd
Open

YingboMa wants to merge 8 commits into
masterfrom
myb/dd

Conversation

@YingboMa

@YingboMa YingboMa commented Oct 4, 2024

Copy link
Copy Markdown
Member

No description provided.

else
ag = AliasGraph(mm, ndsts(state.structure.graph))
end
dummy_derivative_graph!(state.structure, var_eq_matching, jac, state_priority, ag, mm, log)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
dummy_derivative_graph!(state.structure, var_eq_matching, jac, state_priority, ag, mm, log)
dummy_derivative_graph!(
state.structure, var_eq_matching, jac, state_priority, ag, mm, log)

Comment thread src/systems/alias_elimination.jl Outdated
Comment on lines +404 to +405
:inneighbors, :is_directed, :ne, :nv, :outneighbors,
:src, :vertices]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
:inneighbors, :is_directed, :ne, :nv, :outneighbors,
:src, :vertices]
:inneighbors, :is_directed, :ne, :nv, :outneighbors,
:src, :vertices]

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #3093

Reviewed head: babf18f
Raw SHA-256: 01cc22060f546e013bc27f9951fff5d754c1caaba57988bca30bbf9908adb089
Source SHA-256: 657b2ab248e14364c66af6f2bddb6bcdae63d21cb95ed93d4476955d294eee9e
Source: standard-review-v1 (harness-log)
Reviewer session: 01a2195b-0e71-78e0-8873-460947187580
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium-high (MH1)
  • Verdict: CHANGES
  • Reviewed head: babf18f

Review report

VERDICT: CHANGES
Round: 1
Head: babf18f
Slot: 1
CI: CI unreadable; review only; merge gates unchanged
Session: 01a2195b-0e71-78e0-8873-460947187580
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

medium-high (MH1: the default structural_simplify path now evaluates priorities eagerly, including when an ODE has no state candidates to rank)

Blocking findings

  • Blocking priorities: P1, P2, P2

  • [P1] Alias priorities never reach state selection (src/structural_transformation/symbolics_tearing.jl:829). Both fully determined branches in src/systems/systemstructure.jl:691 pass the alias matrix to dummy_derivative. That function consumes mm as a named keyword and omits it from the call to dummy_derivative_graph!. The new graph branch therefore receives its default nothing. I ran a DAE with one differential degree of freedom, constraint x^2 + y^2 = 1, and alias a = x. With competing priority 5 on y, priority 10 on x gave the sole differential equation D(x). Moving priority 10 to a gave D(y). Both revisions produced those results.

    Implementation fix: Forward mm from dummy_derivative to the transformation-state overload of dummy_derivative_graph! and retain it for tearing_reassemble. Drop the unused positional mm from the structure overload in src/structural_transformation/partial_state_selection.jl. Feed the graph per-variable metadata before any derivative-chain aggregation, so the callback cannot propagate backwards against the graph's directed derivative edges. Preserve the no-graph priority policy. In test/state_selection.jl, add the DAE above as a regression with priority on the coordinate and on its positive and negative aliases. Assert that the sole differential state belongs to the prioritized coordinate's alias class in every case. Describe the alias behavior alongside the existing priority example in docs/src/tutorials/initialization.md.

  • [P2] Priority propagation misses cycles and competing paths (src/structural_transformation/partial_state_selection.jl:227). The traversal only starts at zero-indegree vertices. A component with bidirectional alias edges can have none. The per-root visited set also blocks a stronger priority arriving later at a vertex. Running the graph code from the checked-out source, an equality chain with seed priorities [10, 0, 0] returned [10, 0, 0] instead of [10, 10, 10]. A diamond with edges 1→2, 1→3, 2→4, 3→4 and seed priorities [0, 1, 10, 0] assigned vertex 4 priority 1 instead of 10.

    Implementation fix: Seed a worklist with every vertex in prop_state_priority!. Relax each outgoing edge with the priority comparator and requeue the destination whenever its priority changes. This handles cyclic aliases and propagates improvements through previously visited vertices. In test/structural_transformation/utils.jl, add both graphs and assert the final vectors [10, 10, 10] and [0, 1, 10, 10]. Repeat the diamond with the two middle vertex indices exchanged to check independence from traversal order.

  • [P2] Omitting the priority callback now throws (src/structural_transformation/partial_state_selection.jl:292). On the scalar ODE D(x) = -x, dummy_derivative_graph!(TearingState(sys)) returned a two-entry matching at the comparison base and threw MethodError: objects of type Nothing are not callable at the head. A second probe passed a counting callback and observed zero calls at the base and four at the head. This ODE has no differentiated constraints and needs no priority sort.

    Implementation fix: Initialize the expanded priorities on first use inside the guarded SCC ranking block in the structure overload of dummy_derivative_graph!. Cache them for subsequent SCCs and keep the branch inactive when state_priority === nothing. In test/structural_transformation/index_reduction.jl, exercise the transformation-state overload on the scalar ODE and assert that an omitted callback gives the same matching as an explicit zero-priority callback. Also assert that the callback is invoked zero times for that model.

Non-blocking findings

  • The unused signed alias lookup records incorrect signs (src/systems/alias_elimination.jl:398). For rows [1, -1, 0] and [0, 1, 1], the head returned (true, false, true, false) for (1,2), (2,1), (2,3), (3,2). The first pair represents equality and the second negation, so a signed undirected lookup should return (false, false, true, true).

    Implementation fix: Remove neg_edge and isneg from AliasGraph while the priority graph only consumes adjacency. This is the smaller option. Read the sparse row with findnz(r.vec) and trim the phase-two sketch at src/structural_transformation/partial_state_selection.jl:245 to the invariant the code implements. In test/structural_transformation/utils.jl, assert that equality and negation rows each create the expected undirected edge and transfer priority in both directions. If signed lookup is retained, store an edge only when v1 == v2, canonicalize the endpoints on write and lookup, and assert the four signed results above.

What I ran

  • git diff --check origin/master...HEAD exited 0. The rename-aware path scan found three modified source files and no renames. All three paths were checked for H6. None governs privileges, security, hooks, merges, deployment, publishing, or registration.
  • With Julia 1.10.12, GROUP=InterfaceI julia +1.10 --startup-file=no --project=. -e 'using Pkg; Pkg.test()' exited 1 after 20m37s of tests. The summary was 1,816 passed, 4 failed, 2 errored, and 9 broken. StructuralTransformations reported 72 passed and 3 broken. State Selection reported 8 passed and 1 broken.
  • I reran the unmodified StructuralTransformations and State Selection test files using their SafeTestsets entries and the resolved test environment. The focused run exited 0 with 79 passed and 4 broken.
  • I reran the four failing InterfaceI test files at comparison base 024e66ce1760fe4e470b903da70da85ae07b128d with the same resolved versions. All six outcomes reproduced. test/initializationsystem.jl:475 evaluated 4 == 3. test/model_parsing.jl:821, :825, and :829 evaluated BasicSymbolic{Real} == Num. test/symbolic_events.jl:637 and test/parameter_dependencies.jl:284 hit _reset_aggregator! with “Error, encountered a symbol. This should not happen.”
  • I ran priority_graph_probe.jl against the checked-out source and observed three failed assertions. I ran priority_integration_probe.jl, no_priority_probe.jl, and eager_priority_probe.jl against head and base using identical package resolutions. The integration probe showed one pass and one failure on each revision. The no-priority and callback-count probes passed at the base and failed at the head with the results above.
  • uv run --locked python --version printed Python 3.13.13 and warned that --locked had no effect outside a project. The checkout has no uv.lock and no locked Python interpreter was verified.

What I did not verify

The CI checks, other Julia versions, downstream groups, docs build, and runtime benchmark remain unverified. Baseline investigation established the six failures at the comparison base. A passing ancestor under the same dependencies and the first bad revision remain unverified.

AUTHOR_GRADE: {"task":"feature","score":2,"difficulty":3,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"Alias priority is disconnected from structural_simplify. Probes exposed propagation errors and an omitted-callback regression. The existing InterfaceI failures reproduced at the comparison base."}

Head link: babf18f


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a2195b-0e71-78e0-8873-460947187580 (no session URL)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants